Class: Genai::Model

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, model_id) ⇒ Model

Returns a new instance of Model.



11
12
13
14
# File 'lib/genai/model.rb', line 11

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/genai/model.rb', line 9

def client
  @client
end

#model_idObject (readonly)

Returns the value of attribute model_id.



9
10
11
# File 'lib/genai/model.rb', line 9

def model_id
  @model_id
end

Class Method Details

.grounding_toolObject



34
35
36
# File 'lib/genai/model.rb', line 34

def self.grounding_tool
  { google_search: {} }
end

.grounding_with_dynamic_threshold(threshold) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/genai/model.rb', line 38

def self.grounding_with_dynamic_threshold(threshold)
  {
    google_search_retrieval: {
      dynamic_retrieval_config: {
        mode: "MODE_DYNAMIC",
        dynamic_threshold: threshold
      }
    }
  }
end

Instance Method Details

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/genai/model.rb', line 16

def generate_content(contents:, tools: nil, config: nil, grounding: nil, **options)
  tools = Array(tools).dup if tools
  if grounding
    if grounding.is_a?(Hash) && grounding[:dynamic_threshold]
      tools ||= []
      tools << self.class.grounding_with_dynamic_threshold(grounding[:dynamic_threshold])
    else
      tools ||= []
      tools << self.class.grounding_tool
    end
  end
  
  contents_with_urls = extract_and_add_urls(contents)
  request_body = build_request_body(contents: contents_with_urls, tools: tools, config: config, **options)
  response = make_request(request_body)
  parse_response(response)
end