https://github.com/crmne/ruby_llm
Stop juggling AI SDKs! RubyLLM offers one delightful Ruby interface for OpenAI, Anthropic, Gemini, Bedrock, OpenRouter, DeepSeek, Ollama & compatible APIs. Chat, Vision, Audio, PDF, Images, Embeddings, Tools, Streaming & Rails integration.
https://github.com/crmne/ruby_llm
ai anthropic chatgpt claude dall-e deepseek embeddings gemini image-generation llm openai rails ruby
Last synced: 13 days ago
JSON representation
Stop juggling AI SDKs! RubyLLM offers one delightful Ruby interface for OpenAI, Anthropic, Gemini, Bedrock, OpenRouter, DeepSeek, Ollama & compatible APIs. Chat, Vision, Audio, PDF, Images, Embeddings, Tools, Streaming & Rails integration.
- Host: GitHub
- URL: https://github.com/crmne/ruby_llm
- Owner: crmne
- License: mit
- Created: 2025-01-30T08:58:19.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-04-25T15:40:44.000Z (17 days ago)
- Last Synced: 2025-04-25T15:42:41.957Z (17 days ago)
- Topics: ai, anthropic, chatgpt, claude, dall-e, deepseek, embeddings, gemini, image-generation, llm, openai, rails, ruby
- Language: Ruby
- Homepage: https://rubyllm.com/
- Size: 29.2 MB
- Stars: 2,106
- Watchers: 18
- Forks: 101
- Open Issues: 45
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-ChatGPT-repositories - ruby_llm - A delightful Ruby way to work with AI. No configuration madness, no complex callbacks, no handler hell – just beautiful, expressive Ruby code. (NLP)
- awesome-chatgpt - crmne/ruby_llm - RubyLLM is a Ruby library that provides a unified, expressive, and easy-to-use interface for working with multiple AI providers, supporting chat, vision, audio, document analysis, image generation, embeddings, and integration with Ruby on Rails. (SDK, Libraries, Frameworks / Other sdk/libraries)
README
**A delightful Ruby way to work with AI.** RubyLLM provides **one** beautiful, Ruby-like interface to interact with modern AI models. Chat, generate images, create embeddings, and use tools – all with clean, expressive code that feels like Ruby, not like patching together multiple services.
🤺 Battle tested at [💬 Chat with Work](https://chatwithwork.com)
## The problem with AI libraries
Every AI provider comes with its own client library, its own response format, its own conventions for streaming, and its own way of handling errors. Want to use multiple providers? Prepare to juggle incompatible APIs and bloated dependencies.
RubyLLM fixes all that. One beautiful API for everything. One consistent format. Minimal dependencies — just Faraday and Zeitwerk. Because working with AI should be a joy, not a chore.
## What makes it great
```ruby
# Just ask questions
chat = RubyLLM.chat
chat.ask "What's the best way to learn Ruby?"# Analyze images
chat.ask "What's in this image?", with: { image: "ruby_conf.jpg" }# Analyze audio recordings
chat.ask "Describe this meeting", with: { audio: "meeting.wav" }# Analyze documents
chat.ask "Summarize this document", with: { pdf: "contract.pdf" }# Stream responses in real-time
chat.ask "Tell me a story about a Ruby programmer" do |chunk|
print chunk.content
end# Generate images
RubyLLM.paint "a sunset over mountains in watercolor style"# Create vector embeddings
RubyLLM.embed "Ruby is elegant and expressive"# Let AI use your code
class Weather < RubyLLM::Tool
description "Gets current weather for a location"
param :latitude, desc: "Latitude (e.g., 52.5200)"
param :longitude, desc: "Longitude (e.g., 13.4050)"def execute(latitude:, longitude:)
url = "https://api.open-meteo.com/v1/forecast?latitude=#{latitude}&longitude=#{longitude}¤t=temperature_2m,wind_speed_10m"response = Faraday.get(url)
data = JSON.parse(response.body)
rescue => e
{ error: e.message }
end
endchat.with_tool(Weather).ask "What's the weather in Berlin? (52.5200, 13.4050)"
```## Core Capabilities
* 💬 **Unified Chat:** Converse with models from OpenAI, Anthropic, Gemini, Bedrock, OpenRouter, DeepSeek, Ollama, or any OpenAI-compatible API using `RubyLLM.chat`.
* 👁️ **Vision:** Analyze images within chats.
* 🔊 **Audio:** Transcribe and understand audio content.
* 📄 **PDF Analysis:** Extract information and summarize PDF documents.
* 🖼️ **Image Generation:** Create images with `RubyLLM.paint`.
* 📊 **Embeddings:** Generate text embeddings for vector search with `RubyLLM.embed`.
* 🔧 **Tools (Function Calling):** Let AI models call your Ruby code using `RubyLLM::Tool`.
* 🚂 **Rails Integration:** Easily persist chats, messages, and tool calls using `acts_as_chat` and `acts_as_message`.
* 🌊 **Streaming:** Process responses in real-time with idiomatic Ruby blocks.## Installation
Add to your Gemfile:
```ruby
gem 'ruby_llm'
```
Then `bundle install`.Configure your API keys (using environment variables is recommended):
```ruby
# config/initializers/ruby_llm.rb or similar
RubyLLM.configure do |config|
config.openai_api_key = ENV.fetch('OPENAI_API_KEY', nil)
# Add keys ONLY for providers you intend to use
# config.anthropic_api_key = ENV.fetch('ANTHROPIC_API_KEY', nil)
# ... see Configuration guide for all options ...
end
```
See the [Installation Guide](https://rubyllm.com/installation) for full details.## Rails Integration
Add persistence to your chat models effortlessly:
```ruby
# app/models/chat.rb
class Chat < ApplicationRecord
acts_as_chat # Automatically saves messages & tool calls
# ... your other model logic ...
end# app/models/message.rb
class Message < ApplicationRecord
acts_as_message
# ...
end# app/models/tool_call.rb (if using tools)
class ToolCall < ApplicationRecord
acts_as_tool_call
# ...
end# Now interacting with a Chat record persists the conversation:
chat_record = Chat.create!(model_id: "gpt-4.1-nano")
chat_record.ask("Explain Active Record callbacks.") # User & Assistant messages saved
```
Check the [Rails Integration Guide](https://rubyllm.com/guides/rails) for more.## Learn More
Dive deeper with the official documentation:
- [Installation](https://rubyllm.com/installation)
- [Configuration](https://rubyllm.com/configuration)
- **Guides:**
- [Getting Started](https://rubyllm.com/guides/getting-started)
- [Chatting with AI Models](https://rubyllm.com/guides/chat)
- [Using Tools](https://rubyllm.com/guides/tools)
- [Streaming Responses](https://rubyllm.com/guides/streaming)
- [Rails Integration](https://rubyllm.com/guides/rails)
- [Image Generation](https://rubyllm.com/guides/image-generation)
- [Embeddings](https://rubyllm.com/guides/embeddings)
- [Working with Models](https://rubyllm.com/guides/models)
- [Error Handling](https://rubyllm.com/guides/error-handling)
- [Available Models](https://rubyllm.com/guides/available-models)## Contributing
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on setup, testing, and contribution guidelines.
## License
Released under the MIT License.