Skip to content

Commit f8c4655

Browse files
authored
Merge branch 'main' into feature/video-file-support
2 parents 9604320 + 91105f7 commit f8c4655

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)