Class: Genai::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/genai/model.rb

Constant Summary collapse

OPENAI_ROLES =
{
  "model" => "assistant",
  "assistant" => "assistant",
  "user" => "user",
  "system" => "system",
  "developer" => "developer",
  "tool" => "tool"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, model_id) ⇒ Model

Returns a new instance of Model.



18
19
20
21
# File 'lib/genai/model.rb', line 18

def initialize(client, model_id)
  @client = client
  @model_id = model_id
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/genai/model.rb', line 7

def client
  @client
end

#model_idObject (readonly)

Returns the value of attribute model_id.



7
8
9
# File 'lib/genai/model.rb', line 7

def model_id
  @model_id
end

Instance Method Details

#generate_content(contents:, tools: nil, config: nil, grounding: nil, **options) ⇒ Object

Raises:



23
24
25
26
27
28
29
# File 'lib/genai/model.rb', line 23

def generate_content(contents:, tools: nil, config: nil, grounding: nil, **options)
  raise Error, "grounding is not supported by OpenAI-compatible chat completions." if grounding

  request_body = build_request_body(contents: contents, tools: tools, config: config, **options)
  response = make_request(request_body)
  parse_response(response)
end