Class: Ollama::Client::OpenAICompat::ChatAdapter
- Inherits:
-
Object
- Object
- Ollama::Client::OpenAICompat::ChatAdapter
- Defined in:
- lib/ollama/client/openai_compat.rb
Overview
Adapter for OpenAI-like chat/completions API.
Instance Method Summary collapse
- #completions ⇒ self
-
#create(model:, messages:, tools: nil, temperature: nil, top_p: nil) ⇒ Hash
Create chat completion in OpenAI-compatible format.
-
#initialize(client) ⇒ ChatAdapter
constructor
A new instance of ChatAdapter.
Constructor Details
#initialize(client) ⇒ ChatAdapter
Returns a new instance of ChatAdapter.
99 100 101 |
# File 'lib/ollama/client/openai_compat.rb', line 99 def initialize(client) @client = client end |
Instance Method Details
#completions ⇒ self
104 105 106 |
# File 'lib/ollama/client/openai_compat.rb', line 104 def completions self end |
#create(model:, messages:, tools: nil, temperature: nil, top_p: nil) ⇒ Hash
Create chat completion in OpenAI-compatible format.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ollama/client/openai_compat.rb', line 115 def create(model:, messages:, tools: nil, temperature: nil, top_p: nil, **) response = @client.chat( model: model, messages: , tools: tools, options: { temperature: temperature, top_p: top_p }.compact ) { "id" => "chatcmpl-#{SecureRandom.hex(12)}", "object" => "chat.completion", "created" => Time.now.to_i, "model" => model, "choices" => [ { "index" => 0, "message" => { "role" => "assistant", "content" => response..content, "tool_calls" => openai_tool_calls(response) }, "finish_reason" => response.done_reason || "stop" } ] } end |