- खूबसूरत और expressive Ruby-आधारित unified AI लाइब्रेरी
- हर AI provider के client library, response format और streaming handling का तरीका अलग होता है, और कई AI models इस्तेमाल करने के लिए incompatible APIs और complex dependencies संभालनी पड़ती हैं
- RubyLLM इन समस्याओं को हल करने के लिए एक unified API प्रदान करता है
मुख्य फीचर्स
- Conversation: OpenAI, Anthropic, Gemini, DeepSeek models का समर्थन
- Vision और Audio: image और audio understanding
- PDF analysis: document summary और analysis
- Image generation: DALL-E सहित कई models का समर्थन
- Embedding generation: vector search और semantic analysis
- Tool support: Ruby code को AI के साथ जोड़ा जा सकता है
- Rails integration: ActiveRecord के साथ chat history store की जा सकती है
- Streaming: real-time response processing का समर्थन
RubyLLM के फायदे
# सरल तरीके से सवाल पूछना
chat = RubyLLM.chat
chat.ask "루비를 배우기 가장 좋은 방법은?"
# image analysis
chat.ask "이 이미지에 무엇이 보이나요?", with: { image: "ruby_conf.jpg" }
# audio analysis
chat.ask "이 회의에서 무슨 이야기가 나왔나요?", with: { audio: "meeting.wav" }
# document summary
chat.ask "이 계약서를 요약해 주세요", with: { pdf: "contract.pdf" }
# image generation
RubyLLM.paint "산 위의 노을을 수채화 스타일로 그려줘"
# vector embedding generation
RubyLLM.embed "Ruby는 우아하고 표현력이 뛰어남"
# AI can use code
class Weather < RubyLLM::Tool
description "특정 위치의 현재 날씨 제공"
param :latitude, desc: "위도 (예: 52.5200)"
param :longitude, desc: "경도 (예: 13.4050)"
def execute(latitude:, longitude:)
url = "https://api.open-meteo.com/v1/forecast/…;
response = Faraday.get(url)
JSON.parse(response.body)
rescue => e
{ error: e.message }
end
end
chat.with_tool(Weather).ask "베를린의 날씨는 어때? (52.5200, 13.4050)"
इंस्टॉल करने का तरीका
# Gemfile में जोड़ें
gem 'ruby_llm'
# install
bundle install
# या सीधे install करें
gem install ruby_llm
API key सेट करना
RubyLLM.configure do |config|
config.openai_api_key = ENV['OPENAI_API_KEY']
config.anthropic_api_key = ENV['ANTHROPIC_API_KEY']
config.gemini_api_key = ENV['GEMINI_API_KEY']
config.deepseek_api_key = ENV['DEEPSEEK_API_KEY'] # optional
end
स्वाभाविक conversation handling
# default model (GPT-4o-mini) के साथ chat शुरू करें
chat = RubyLLM.chat
# दूसरा model इस्तेमाल करें
chat = RubyLLM.chat(model: 'claude-3-7-sonnet-20250219')
# simple question
chat.ask "attr_reader와 attr_accessor의 차이는?"
# multi-turn conversation handling
chat.ask "예제를 들어줄 수 있나요?"
# streaming response
chat.ask "루비 프로그래머에 관한 이야기 해줘" do |chunk|
print chunk.content
end
# अलग input types का समर्थन
chat.ask "이 두 다이어그램을 비교해줘", with: { image: ["diagram1.png", "diagram2.png"] }
chat.ask "이 문서를 요약해줘", with: { pdf: "contract.pdf" }
chat.ask "이 오디오에서 무슨 말이 나왔는지 알려줘", with: { audio: "meeting.wav" }
# conversation के दौरान model बदलना
chat.with_model('gemini-2.0-flash').ask "가장 좋아하는 알고리즘은?"
Rails integration support
# app/models/chat.rb
class Chat < ApplicationRecord
acts_as_chat
broadcasts_to ->(chat) { "chat_#{chat.id}" }
end
# app/models/message.rb
class Message < ApplicationRecord
acts_as_message
end
# app/models/tool_call.rb
class ToolCall < ApplicationRecord
acts_as_tool_call
end
# controller में इस्तेमाल का example
chat = Chat.create!(model_id: "gpt-4o-mini")
chat.ask("루비에서 가장 유용한 gem은 뭐야?") do |chunk|
Turbo::StreamsChannel.broadcast_append_to(
chat,
target: "response",
partial: "messages/chunk",
locals: { chunk: chunk }
)
end
# chat history अपने-आप save हो जाती है
tool लिखने का उदाहरण
class Search < RubyLLM::Tool
description "지식 베이스에서 검색 수행"
param :query, desc: "검색어"
param :limit, type: :integer, desc: "최대 결과 수", required: false
def execute(query:, limit: 5)
Document.search(query).limit(limit).map(&:title)
end
end
# AI में tool का उपयोग
chat.with_tool(Search).ask "루비 3.3의 새로운 기능에 대한 문서 찾아줘"
1 टिप्पणियां
Hacker News राय