HN 日本語サマリー

← 一覧へ戻る
AI・機械学習

RubyLLM: すべての主要AIプロバイダーに対応する、唯一の美しいRubyフレームワーク

RubyLLM: A single, beautiful Ruby framework for all major AI providers (rubyllm.com)

101 pointsby doener15 コメント

要約

RubyLLMは、主要なAIプロバイダーすべてに対応するRubyフレームワークです。これにより、開発者は異なるAPIやレスポンス形式に悩むことなく、一貫したインターフェースでチャットボット、AIエージェント、RAGアプリケーションなどを簡単に構築できます。GPT、Claude、ローカルのOllamaなど、多様なモデルをシンプルに利用でき、わずかな依存関係でAIワークフローを効率的に実現します。

全文翻訳

ページをコピー お気に入りに登録 すべての主要AIプロバイダーに対応する、唯一の美しいRubyフレームワーク。チャットボット、AIエージェント、RAGアプリケーション、コンテンツ生成器、その他考えうるあらゆるAIワークフローを簡単に構築できます。GitHubで開始 バトルテスト済み - 完全にプライベートな作業AI 2分で動作するRuby AIチャットを構築 RubyLLMを使っていますか?あなたのストーリーを共有してください!5分で完了します。 なぜRubyLLMなのか?すべてのAIプロバイダーは、独自の肥大化したクライアントを提供しています。異なるAPI。異なるレスポンス形式。異なる規約。これでは疲弊してしまいます。RubyLLMは、それらすべてに対応する一つの美しいフレームワークを提供します。GPT、Claude、ローカルのOllamaを使用する場合でも、同じインターフェースです。依存関係はFaraday、Zeitwerk、Marcelのたった3つだけです。それだけです。 コードを見せてください# 質問するだけchat = RubyLLM.chat chat.ask "What's the best way to learn Ruby?" # あらゆるファイルタイプを分析chat.ask "What's in this image?", with: "ruby_conf.jpg" chat.ask "What's happening in this video?", with: "video.mp4" chat.ask "Describe this meeting", with: "meeting.wav" chat.ask "Summarize this document", with: "contract.pdf" chat.ask "Explain this code", with: "app.rb" # 複数ファイルを一度にchat.ask "Analyze these files", with: ["diagram.png", "report.pdf", "notes.txt"] # ストリーム応答chat.ask "Tell me a story about Ruby" do |chunk| print chunk.content end # 画像を生成RubyLLM.paint "a sunset over mountains in watercolor style" # エンベディングを作成RubyLLM.embed "Ruby is elegant and expressive" # 音声をテキストに変換RubyLLM.transcribe "meeting.wav" # 安全のためにコンテンツをモデレートRubyLLM.moderate "Check if this text is safe" # AIにコードを使わせるclass Weather < RubyLLM::Tool desc "Get current weather" def execute(latitude:, longitude:) url = "https://api.open-meteo.com/v1/forecast?latitude=#{latitude}&longitude=#{longitude}&current=temperature_2m,wind_speed_10m" JSON.parse(Faraday.get(url).body) end end chat.with_tool(Weather).ask "What's the weather in Berlin?" # 命令とツールを持つエージェントを定義class WeatherAssistant < RubyLLM::Agent model "gpt-5-nano" instructions "Be concise and always use tools for weather." tools Weather end WeatherAssistant.new.ask "What's the weather in Berlin?" # 構造化された出力を取得class ProductSchema < RubyLLM::Schema string :name number :price array :features do string end end response = chat.with_schema(ProductSchema).ask "Analyze this product", with: "product.txt" 機能 チャット: RubyLLM.chatによる会話型AI ビジョン: 画像と動画の分析 オーディオ: RubyLLM.transcribeによる音声の転写と理解 ドキュメント: PDF、CSV、JSON、あらゆるファイルタイプからの抽出 画像生成: RubyLLM.paintによる画像作成 エンベディング: RubyLLM.embedによるエンベディング生成 モデレーション: RubyLLM.moderateによるコンテンツの安全性 ツール: AIがRubyメソッドを呼び出す エージェント: RubyLLM::Agentによる再利用可能なアシスタント 構造化出力: 機能するJSONスキーマ ストリーミング: ブロックによるリアルタイム応答 Rails: acts_as_chatによるActiveRecord統合 非同期: Fiberベースの並行処理 モデルレジストリ: 機能検出と価格設定を備えた800以上のモデル 拡張思考: モデルの熟慮を制御、表示、永続化 プロバイダー: OpenAI、xAI、Anthropic、Gemini、VertexAI、Bedrock、DeepSeek、Mistral、Ollama、OpenRouter、Perplexity、GPUStack、およびあらゆるOpenAI互換API インストール Gemfileに追加: gem 'ruby_llm' その後、bundle installを実行します。APIキーを設定します: # config/initializers/ruby_llm.rb RubyLLM.configure do |config| config.openai_api_key = ENV['OPENAI_API_KEY'] end Rails # Rails統合をインストールbin/rails generate ruby_llm:install bin/rails db:migrate bin/rails ruby_llm:load_models # v1.13+ # チャットUIを追加 (任意)bin/rails generate ruby_llm:chat_ui class Chat < ApplicationRecord acts_as_chat end chat = Chat.create! model: "claude-sonnet-4" chat.ask "What's in this file?", with: "report.pdf" すぐに使えるチャットインターフェースは http://localhost:3000/chats を参照してください!