Skip to content

Commit 7a73a65

Browse files
committed
support options on completion calls
1 parent a0f3704 commit 7a73a65

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/ruby_llm/chat.rb

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def initialize(model: nil, provider: nil, assume_model_exists: false, context: n
2525
@temperature = 0.7
2626
@messages = []
2727
@tools = {}
28+
@options = {}
2829
@on = {
2930
new_message: nil,
3031
end_message: nil
@@ -80,6 +81,11 @@ def with_temperature(temperature)
8081
self
8182
end
8283

84+
def with_options(**options)
85+
@options = options
86+
self
87+
end
88+
8389
def on_new_message(&block)
8490
@on[:new_message] = block
8591
self
@@ -102,6 +108,7 @@ def complete(&) # rubocop:disable Metrics/MethodLength
102108
temperature: @temperature,
103109
model: @model.id,
104110
connection: @connection,
111+
options: @options
105112
&
106113
)
107114
@on[:end_message]&.call(response)

lib/ruby_llm/provider.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ module Provider
1010
module Methods
1111
extend Streaming
1212

13-
def complete(messages, tools:, temperature:, model:, connection:, &) # rubocop:disable Metrics/MethodLength
13+
def complete(messages, tools:, temperature:, model:, connection:, options: {}, &) # rubocop:disable Metrics/MethodLength
1414
normalized_temperature = maybe_normalize_temperature(temperature, model)
1515

1616
payload = render_payload(messages,
1717
tools: tools,
1818
temperature: normalized_temperature,
1919
model: model,
20-
stream: block_given?)
20+
stream: block_given?).merge(options)
2121

2222
if block_given?
2323
stream_response connection, payload, &

0 commit comments

Comments
 (0)