Class: Ollama::Client::OpenAICompat::CompletionsAdapter
- Inherits:
-
Object
- Object
- Ollama::Client::OpenAICompat::CompletionsAdapter
- Defined in:
- lib/ollama/client/openai_compat.rb
Overview
Adapter for OpenAI-like text completions API.
Instance Method Summary collapse
-
#create(model:, prompt:, temperature: nil, top_p: nil) ⇒ Hash
Create text completion in OpenAI-compatible format.
-
#initialize(client) ⇒ CompletionsAdapter
constructor
A new instance of CompletionsAdapter.
Constructor Details
#initialize(client) ⇒ CompletionsAdapter
Returns a new instance of CompletionsAdapter.
162 163 164 |
# File 'lib/ollama/client/openai_compat.rb', line 162 def initialize(client) @client = client end |
Instance Method Details
#create(model:, prompt:, temperature: nil, top_p: nil) ⇒ Hash
Create text completion in OpenAI-compatible format.
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/ollama/client/openai_compat.rb', line 172 def create(model:, prompt:, temperature: nil, top_p: nil, **) text = @client.generate(model: model, prompt: prompt, options: { temperature: temperature, top_p: top_p }.compact) { "id" => "cmpl-#{SecureRandom.hex(12)}", "object" => "text_completion", "created" => Time.now.to_i, "model" => model, "choices" => [{ "index" => 0, "text" => text, "finish_reason" => "stop" }] } end |