Skip to content

Commit 91105f7

Browse files
tpaulshippycrmne
andauthored
Add provider specifying example to rails guide (#233)
## What this does Provide similar example that answered #226 ## Type of change - [ ] Bug fix - [ ] New feature - [ ] Breaking change - [X] Documentation - [ ] Performance improvement ## Scope check - [X] I read the [Contributing Guide](https://github.com/crmne/ruby_llm/blob/main/CONTRIBUTING.md) - [X] This aligns with RubyLLM's focus on **LLM communication** - [X] This isn't application-specific logic that belongs in user code - [X] This benefits most users, not just my specific use case ## Quality check - [X] I ran `overcommit --install` and all hooks pass - [X] I tested my changes thoroughly - [X] I updated documentation if needed - [X] I didn't modify auto-generated files manually (`models.json`, `aliases.json`) ## API changes - [ ] Breaking change - [ ] New public methods/classes - [ ] Changed method signatures - [X] No API changes ## Related issues <!-- Link issues: "Fixes #123" or "Related to #123" --> Related to #226 --------- Co-authored-by: Carmine Paolino <[email protected]>
1 parent 4ff492d commit 91105f7

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

docs/guides/rails.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,29 @@ class ToolCall < ApplicationRecord
193193
end
194194
```
195195

196+
### Setup RubyLLM.chat yourself
197+
198+
In some scenarios, you need to tap into the power and arguments of `RubyLLM.chat`. For example, if want to use model aliases with alternate providers. Here is a working example:
199+
200+
```ruby
201+
class Chat < ApplicationRecord
202+
acts_as_chat
203+
204+
validates :model_id, presence: true
205+
validates :provider, presence: true
206+
207+
after_initialize :set_chat
208+
209+
def set_chat
210+
@chat = RubyLLM.chat(model: model_id, provider:)
211+
end
212+
end
213+
214+
# Then in your controller or background job:
215+
Chat.new(model_id: 'alias', provider: 'provider_name')
216+
```
217+
218+
196219
## Basic Usage
197220

198221
Once your models are set up, the `acts_as_chat` helper delegates common `RubyLLM::Chat` methods to your `Chat` model:
@@ -510,4 +533,4 @@ end
510533
* [Using Tools]({% link guides/tools.md %})
511534
* [Streaming Responses]({% link guides/streaming.md %})
512535
* [Working with Models]({% link guides/models.md %})
513-
* [Error Handling]({% link guides/error-handling.md %})
536+
* [Error Handling]({% link guides/error-handling.md %})

0 commit comments

Comments
 (0)