Skip to content

Commit 1c50176

Browse files
crmnetpaulshippy
authored andcommitted
fix: Rails integration with_context now works without global config
- Modified to_llm to accept optional context parameter - Updated with_context to pass context to to_llm - Added tests to verify custom contexts work without global configuration - Users can now use custom contexts even when global RubyLLM config is missing
1 parent 730a8c8 commit 1c50176

File tree

6 files changed

+556
-510
lines changed

6 files changed

+556
-510
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ Gemfile.lock
5656
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
5757
# .rubocop-https?--*
5858

59-
repomix-output.*
59+
CLAUDE.md
60+
.claude

docs/guides/available-models.md

Lines changed: 101 additions & 60 deletions
Large diffs are not rendered by default.

lib/ruby_llm/active_record/acts_as.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ module ChatMethods
8484
attr_reader :tool_call_class
8585
end
8686

87-
def to_llm
88-
@chat ||= RubyLLM.chat(model: model_id)
87+
def to_llm(context: nil)
88+
@chat ||= if context
89+
context.chat(model: model_id)
90+
else
91+
RubyLLM.chat(model: model_id)
92+
end
8993
@chat.reset_messages!
9094

9195
messages.each do |msg|
@@ -125,8 +129,8 @@ def with_temperature(...)
125129
self
126130
end
127131

128-
def with_context(...)
129-
to_llm.with_context(...)
132+
def with_context(context)
133+
to_llm(context: context)
130134
self
131135
end
132136

lib/ruby_llm/aliases.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,6 @@
174174
"openai": "o1-mini-2024-09-12",
175175
"openrouter": "openai/o1-mini-2024-09-12"
176176
},
177-
"o1-preview": {
178-
"openai": "o1-preview",
179-
"openrouter": "openai/o1-preview"
180-
},
181-
"o1-preview-2024-09-12": {
182-
"openai": "o1-preview-2024-09-12",
183-
"openrouter": "openai/o1-preview-2024-09-12"
184-
},
185177
"o1-pro": {
186178
"openai": "o1-pro",
187179
"openrouter": "openai/o1-pro"

0 commit comments

Comments
 (0)