Skip to content

Support options on completion calls #130

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions lib/ruby_llm/chat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(model: nil, provider: nil, assume_model_exists: false, context: n
@temperature = 0.7
@messages = []
@tools = {}
@options = {}
@on = {
new_message: nil,
end_message: nil
Expand Down Expand Up @@ -80,6 +81,11 @@ def with_temperature(temperature)
self
end

def with_options(**options)
@options = options
self
end

def on_new_message(&block)
@on[:new_message] = block
self
Expand All @@ -102,6 +108,7 @@ def complete(&) # rubocop:disable Metrics/MethodLength
temperature: @temperature,
model: @model.id,
connection: @connection,
options: @options,
&
)
@on[:end_message]&.call(response)
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_llm/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ module Provider
module Methods
extend Streaming

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

payload = render_payload(messages,
tools: tools,
temperature: normalized_temperature,
model: model,
stream: block_given?)
stream: block_given?).merge(options)

if block_given?
stream_response connection, payload, &
Expand Down