Skip to content

Fixing Ollama Provider to match api endpoing and response structure a… #300

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

Closed
wants to merge 3 commits into from
Closed
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
23 changes: 23 additions & 0 deletions lib/ruby_llm/providers/ollama/chat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module Ollama
module Chat
module_function

def completion_url
'chat'
end

def format_messages(messages)
messages.map do |msg|
{
Expand All @@ -18,6 +22,25 @@ def format_messages(messages)
end
end

def parse_completion_response(response)
data = response.body
return if data.empty?

raise Error.new(response, data.dig('error', 'message')) if data.dig('error', 'message')

message_data = data['message']
return unless message_data

Message.new(
role: :assistant,
content: message_data['content'],
tool_calls: parse_tool_calls(message_data['tool_calls']),
input_tokens: data['prompt_eval_count'],
output_tokens: data['eval_count'],
model_id: data['model']
)
end

def format_role(role)
# Ollama doesn't use the new OpenAI convention for system prompts
role.to_s
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading