RubyLLM: すべての主要AIプロバイダーに対応する、唯一の美しいRubyフレームワーク
RubyLLM: A single, beautiful Ruby framework for all major AI providers (rubyllm.com)
要約
RubyLLMは、主要なAIプロバイダーすべてに対応するRubyフレームワークです。これにより、開発者は異なるAPIやレスポンス形式に悩むことなく、一貫したインターフェースでチャットボット、AIエージェント、RAGアプリケーションなどを簡単に構築できます。GPT、Claude、ローカルのOllamaなど、多様なモデルをシンプルに利用でき、わずかな依存関係でAIワークフローを効率的に実現します。
全文翻訳
bundle add ruby_llm --version 2.1.1
[画像: AIのためにPythonやJavaScriptは不要です。Rubyを使いましょう。]
[動画]
19のプロバイダー。1つのRuby API。
好きなモデルで構築しましょう。アプリケーションを書き直すことなく、ホスト型とローカルのプロバイダー間を移動したり、OpenAI互換のエンドポイントに接続したりできます。
chat = RubyLLM.chat(model: "claude-opus-5")
chat.ask "Hello!"
利用可能なモデルと価格を確認する · 利用状況とコストを追跡する
プロバイダーが見つからない場合
RubyLLMと同じインフラストラクチャ(設定、テスト、リリースセットアップ、実行時にRubyLLMにプラグインするモデルレジストリ)を備えたプロバイダーgemをスキャフォールドします。プロトコルコードを書かずに、サポートされているプロトコルを再利用できます。
gem install ruby_llm --pre
ruby_llm provider-gem Acme \
--api-base https://api.acme.example/v1
1行から始める。
ファイル、ツール、エージェントを追加する
ただ尋ねる
質問をして、もう一度質問します。チャットは会話履歴を保持するため、フォローアップごとにコンテキストがあります。
chat = RubyLLM.chat
chat.ask "What's the best way to learn Ruby?"
# 小さなもので、あなたが気にかけるものを構築し、良いRubyコードを読みましょう...
chat.ask "What should I build first?"
# 毎日行うことのためのコマンドラインツール...
応答をストリーミングする
ブロックを渡して、応答が到着したときにターミナルまたはRailsビューに表示します。
chat = RubyLLM.chat
chat.ask "Tell me a story about Ruby" do |chunk|
print chunk.content
end
ファイルを送信する
画像、録音、またはPDFについて質問します。ローカルパス、URL、または複数のファイルをwith:で一度に渡すと、RubyLLMがモデル用に準備します。
chat = RubyLLM.chat(model: "gemini-3.7-flash")
chat.ask "What's in this image?", with: "ruby_conf.jpg"
chat.ask "Summarize this", with: "https://example.com/q3.pdf"
chat.ask "Recap this call", with: ["call.wav", "notes.pdf"]
モデルにツールを与える
Rubyクラスでツールを記述し、executeを実装します。RubyLLMはツール呼び出しを実行し、結果をモデルに返します。
class Weather < RubyLLM::Tool
description "Get current weather"
def execute(latitude:, longitude:)
url = "https://api.open-meteo.com/v1/forecast?latitude=#{latitude}&longitude=#{longitude}¤t=temperature_2m,wind_speed_10m"
JSON.parse(Faraday.get(url).body)
end
end
chat.with_tools(Weather).ask "What's the weather in Berlin?"
MCPサーバーに接続する
Rubyクラスでモデルコンテキストプロトコル(MCP)サーバーを記述します。そのツールがモデルのツールとなり、どのツールを表示するかを選択できます。
class Linear < RubyLLM::MCP
url "https://mcp.linear.app/mcp"
inputs :user
bearer_token { user.linear_token }
only :list_issues, :get_issue
end
chat.with_mcp(Linear.new(user: current_user))
.ask "What's blocking the release?"
構造化された出力を取得する
Rubyスキーマで必要なフィールドを定義します。結果をresponse.parsedでハッシュとして読み取ります。
class ProductSchema < Schematist::Schema
string :name
number :price
array :features do
string
end
end
response = chat.with_schema(ProductSchema).ask "Analyze this product", with: "product.txt"
エージェントを定義する
Rubyクラスでエージェントのモデルと指示を与えます。必要に応じてインスタンスを作成します。
class SupportAgent < RubyLLM::Agent
model "gpt-5.6-luna"
instructions "Accept returns of unopened items within 30 days."
end
エージェントを評価する
質問と期待される回答のデータセットに対してエージェントを実行します。RubyLLMはデフォルトで正しさをチェックします。Ruby、RSpec、Minitest、またはRakeから同じ評価を使用できます。
class SupportEvaluation < RubyLLM::Evaluation
def perform(input)
SupportAgent.new.ask(input)
end
end
cases:
- name: within_return_window
inputs: Can I return an unopened item after 14 days?
expected_output: Yes, unopened items can be returned within 30 days.
Rubyのための完全なAIフレームワーク
エージェント、評価、ワークフロー、RAG、画像、音声、動画。組み込みで、利用状況追跡、OpenTelemetryトレーシング、Rails統合を備え、アプリケーションに組み込むことができます。
class IssueRefund < RubyLLM::Tool
description "Issues a refund for an order"
requires_approval
def execute(order_id:) = Refunds.issue!(order_id)
end
documents = [...] # ドキュメントの配列
chats = documents.map do |doc|
RubyLLM.chat(model: "claude-sonnet-5")
.with_instructions("Summarize in one paragraph.")
.ask_later(doc.text)
end
batch = RubyLLM.batch(chats)
chat = RubyLLM.chat(model: "claude-sonnet-5")
.with_caching
chat.with_instructions(File.read("review.md"))
.cache_until_here
chat.ask "Review this diff", with: "large_diff.patch"
response = RubyLLM.chat
.with_provider_tools(:web_search)
.ask "What's the latest stable Ruby? Cite sources."
response.citations
documents = ["Ruby is expressive", "Python uses indentation"]
embeddings = RubyLLM.embed(documents)
ranked = RubyLLM.rerank("Ruby language", documents, model: "rerank-v3.5")
class Urgency < RubyLLM::Judge
model "jev-latest"
probability :urgent, "Does this need action today?"
end
Urgency.judge("My account is locked!").urgent.probability
response = chat.ask "Explain embeddings"
response.tokens.output
response.cost.total
transcript = RubyLLM.transcribe "meeting.wav"
RubyLLM.speak(transcript.text).save "transcript.mp3"
document = RubyLLM.ocr "scanned-contract.pdf"
puts document.markdown
RubyLLM.paint "a sunset over mountains in watercolor style"
RubyLLM.animate "a paper boat sailing down a rainy gutter"
RubyLLM.moderate("Some user-generated content").flagged?
RubyLLM.chat(model: "gpt-5.6-luna")
.with_fallbacks("claude-sonnet-5")
.ask("Explain Ruby blocks")
Railsに馴染む
Active Recordで会話を保存し、Hotwireで応答をストリーミングします。ジェネレーターは動作するチャットUIを提供します。2分間のデモをご覧ください。
chat = Chat.create! model: "claude-opus-5"
chat.ask "What's in this file?", with: "report.pdf"
bin/rails generate ruby_llm:agent Support
bin/rails generate ruby_llm:tool Weather
bin/rails generate ruby_llm:schema Product
コーディングエージェントの準備完了
RubyLLM gemには、コーディングエージェント用のスキルが含まれています。アプリケーションに一致するAPI、例、およびRailsの規約を与えてください。
npx skills add "$(bundle show ruby_llm)" --skill rubyllm
RubyLLMをインストールした後、アプリケーションからこれを実行します。プロンプトが表示されたら、コーディングアシスタントを選択してください。スキルセットアップとアップデート
RubyLLMで構築されたもの
これらの製品の背後にあるチームによって本番環境で使用されています。
[画像: Chat with Work] [画像: Chat with Work]
[画像: Primevise]
[画像: Zipchat]
[画像: Chatwoot]
[画像: SerpApi]
[画像: Hunter]
[画像: Missive]
[画像: Bunny Inc]
[画像: Build Canada]
[画像: OpenRegulatory]
[画像: Corepilot]
[画像: Nodal Networks]
[画像: Intuition Education]
[画像: GrantHero]
[画像: Akira]
RubyLLMを使用していますか?紹介されるか、スポンサーになることができます。
彼らのサポートは、RubyLLMの開発資金を賄うのに役立ちます。RubyのためのAIへの投資に感謝します。
RubyistがRubyLLMを選ぶ理由
[画像: Jorge Manrubia]Jorge ManrubiaPrincipal Programmer, 37signals
OpenAI APIを、@paolinoによる素晴らしいRubyLLM gemを使用して利用しています。
[画像: Nick Warwick]Nick WarwickFounding Engineer, Nodal Networks
Langgraphエージェントが失敗していました。賭けに出てRubyLLMで再構築しました。はるかにシンプルになっただけでなく、パフォーマンスも向上しました。
[画像: Brendan Samek]Brendan SamekFounding Software Engineer, Build Canada
自然に感じます。10万人以上のエンドユーザーにサービスを提供するYumaでは、統合AIインターフェースに多くのゴミが蓄積していました。RubyLLMはそれらすべてよりもはるかに優れています。
[画像: Aaron Snyder]Aaron SnyderCTO / Co-founder, Corepilot
概念実証を1日で立ち上げ、最初のベータ版を約1週間でリリースしました。本当に印象的です。
[画像: Joe Leo]Joe LeoFounder/CEO, Def Method
ほとんどのツールはレイヤーを追加しますが、これは削除します。精神的負荷を低く抑えます。
[画像: Cole Robertson]Cole RobertsonCo-founder and CTO, dScribe AI
開発速度と、JavaScriptランドのAI SDKに最も近いものです。最も簡単なRails統合です。
[画像: Philippe Lehoux]Philippe LehouxCEO, Missive
マルチプロバイダーサポート。エージェントループサポート。スポンサーになれますか?
[画像: Hamid Siddiqui]Hamid SiddiquiFounder, ReelMoney
内部プロバイダー実装をRubyLLMに置き換えましたが、うまく機能しました。多くのコードを削除しました。
[画像: Marc Köhlbrugge]Marc KöhlbruggeFounder/CEO, Startup Jobs
Ruby風DSLと適切な抽象化レベル:構成可能で、アーキテクチャ上で柔軟、低レベルの実装では意見が分かれる。
RubyLLMを使用していますか?あなたのストーリーを共有する!5分で完了します。
試してみてください
RubyLLM.chat.ask "Hello, Ruby!"