Skip to content

Add provider specifying example to rails guide #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion docs/guides/rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,29 @@ class ToolCall < ApplicationRecord
end
```

### Setup RubyLLM.chat yourself

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:

```ruby
class Chat < ApplicationRecord
acts_as_chat

validates :model_id, presence: true
validates :provider, presence: true

after_initialize :set_chat

def set_chat
@chat = RubyLLM.chat(model: model_id, provider:)
end
end

# Then in your controller or background job:
Chat.new(model_id: 'alias', provider: 'provider_name')
```


## Basic Usage

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