Class: Ollama::Client::OpenAICompat::CompletionsAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama/client/openai_compat.rb

Overview

Adapter for OpenAI-like text completions API.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ CompletionsAdapter

Returns a new instance of CompletionsAdapter.

Parameters:



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.

Parameters:

  • model (String)
  • prompt (String)
  • temperature (Float, nil) (defaults to: nil)
  • top_p (Float, nil) (defaults to: nil)

Returns:

  • (Hash)

    OpenAI-style text completion response



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