Anthropic SDK Ruby Examples
No description available
Ask AI about Anthropic SDK Ruby Examples
Powered by Claude · Grounded in docs
I know everything about Anthropic SDK Ruby Examples. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Anthropic SDK Ruby Examples
This repository contains examples from the course Claude with the Anthropic API converted to Ruby.
The examples demonstrate how to use the Anthropic SDK for Ruby to interact with Claude and build applications using the Anthropic API.
My hope is to make this a useful resource for learning and for reference.
Some of the conversion has been done by Claude (see the custom slash command) but manual edits were made, either out of neccessity, or to follow idiomatic Ruby.
Setup
Copy .env.example to .env and fill in your Anthropic API key.
(the VoyageAI API key is only needed for the Retrieval Augmentated Generation (RAG) section.)
Examples
Basic API Usage
- Making a Request - Basic example of making an API request to Claude
Tool Use
- Tool Functions - How to define and use tool functions with Claude
- Multiple Tool Turns - Implementing conversation flows with multiple tool interactions
- Using Multiple Tools - Working with multiple tools in a single conversation
- Tools for Structured Data - Using tools to extract and manipulate structured data from text
- Fine-Grained Tool Calling - Advanced tool calling with fine-grained control (failing due to anthropic-sdk-ruby#108)
- The Text Edit Tool - Implementation of a text editor tool for file manipulation with conversation loops
Retrieval Augmented Generation
- Text Chunking Strategies - Different strategies for chunking text including character-based, sentence-based, and section-based approaches
- Text Embeddings - Generate text embeddings using VoyageAI for RAG applications
- Implementing the RAG Flow - Implementation of vector database functionality and RAG flow components
- Note: This outputs different results than shown in the course video, but it matches what I see when running the Python Jupyter notebook.
- Multi-Index RAG Pipeline - A hybrid RAG system combining vector search and BM25 lexical search for improved retrieval accuracy
- Note: This outputs different results than shown in the course video. I need to investigate further.
- Reranking Results - Implementation of result reranking using Claude to improve the relevance of retrieved documents
Features of Claude
- Prompt Caching in Action - Demonstration of prompt caching techniques with large prompts and tool schemas
Model Context Protocol
I have adapted the example to use the official Ruby SDK for the Model Context Protocol.
- stdio_server.rb - MCP Server (using stdio transport)
When using the MCP inspector, set command to ruby and arguments to the absolute path of stdio_server.rb.
I have not implemented a client. I suggest using the Claude for desktop or Claude Code for trying it out. See below for a sample config for claude_desktop_config.json. You will likely need to explictly specify a Ruby version to avoid it falling to back the system Ruby version. The example shows it for mise.
{
"anthropic-ruby-mcp-example": {
"command": "/Users/andy/.local/share/mise/installs/ruby/3.4.4/bin/ruby",
"args": [
"/Users/andyw8/github.com/src/anthropic-sdk-ruby-examples/09_model_context_protocol/stdio_server.rb"
]
}
}
