patterns-ai-core / langchainrb
git clone https://github.com/patterns-ai-core/langchainrb.git
0.19.5 · 1y ago
🔥 on GitHub Trending today
Build LLM-powered applications in Ruby
+2
stars, 24h · #508
—
stars, 7 days
—
stars, 30 days
2.0k
★ total
272
forks · 72 open issues
Star history starts 2026-10-20; the chart appears after the second daily snapshot.
LanguageRuby
LicenseMIT
Created2023-04-18 (3y ago)
Last push5d ago
Watchers38
OwnerOrganization
Seen on GitHub Trending
- 2026-10-20 — #13 daily in ruby · +2 ★
GitHub topics
Links
- GitHub: github.com/patterns-ai-core/langchainrb
- Homepage: https://rubydoc.info/gems/langchainrb
- Releases · Issues · Hacker News mentions
README excerpt
💎🔗 Langchain.rb --- ⚡ Building LLM-powered applications in Ruby ⚡ For deep Rails integration see: langchainrb_rails gem. Available for paid consulting engagements! Email me. ## Use Cases * Retrieval Augmented Generation (RAG) and vector search * Assistants (chat bots) ## Table of Contents - Installation - Usage - Unified Interface for LLMs - Prompt Management - Output Parsers - Building RAG - Assistants - Evaluations - Examples - Logging - Problems - Development - Discord ## Installation Install the gem and add to the application's Gemfile by executing: bundle add langchainrb If bundler is not being used to manage dependencies, install the gem by executing: gem install langchainrb Additional gems may be required. They're not included by default so you can include only what you need. ## Usage [code] # Unified Interface for LLMs The `Langchain::LLM` module provides a unified interface for interacting with various Large Language Model (LLM) providers. This abstraction allows you to easily switch between different LLM backends without changing your application code. ## Supported LLM Providers - Anthropic - AWS Bedrock - Azure OpenAI - Cohere - Google Gemini - Google Vertex AI - HuggingFace - Mistral AI - Ollama - OpenAI - Replicate ## Usage All LLM classes inherit from `Langchain::LLM::Base` and provide a consistent interface for common operations: 1. Generating embeddings 2. Generating prompt completions 3. Generating chat completions ### Initialization Most LLM classes can be initialized with an API key and optional default options: [code] ### Generating Embeddings Use the `embed` method to generate embeddings for given text: [code] #### Accepted parameters for `embed()` - `text`: (Required) The input text to embed. - `model`: (Optional) The model name to use or default embedding model will be used. ### Prompt completions Use the `complete` method to generate completions for a given prompt: [code] #### Accepted parameters for `complete()` - `prompt`: (Required) The input prompt for completion. - `max_tokens`: (Optional) The maximum number of tokens to generate. - `temperature`: (Optional) Controls randomness in generation. Higher values (e.g., 0.8) make output more random, while lower values (e.g., 0.2) make it more deterministic. - `top_p`: (Optional) An alternative to temperature, controls diversity of generated tokens. - `n`: (Optional) Number of completions to generate for each prompt. - `stop`: (Optional) Sequences where the API will stop generating further tokens. - `presence_penalty`: (Optional) Penalizes new tokens based on their presence in the text so far. - `frequency_penalty`: (Optional) Penalizes new tokens based on their frequency in the text so far. ### Generating Chat Completions Use the `chat` method to generate chat completions: [code] #### Accepted parameters for `chat()` - `messages`: (Required) An array of message objects representing the conversation history. - `model`: (Optional) The specific chat model to use. -