Class: Get::Smart::Ai::Verifier::GeminiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/get/smart/ai/verifier.rb

Constant Summary collapse

BASE_URL =
"https://generativelanguage.googleapis.com/v1beta/models/"
DEFAULT_MODEL =
"gemini-2.0-flash"
TEMPERATURE =
1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model: DEFAULT_MODEL) ⇒ GeminiClient

Returns a new instance of GeminiClient.



15
16
17
# File 'lib/get/smart/ai/verifier.rb', line 15

def initialize(model: DEFAULT_MODEL)
  @model = model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



13
14
15
# File 'lib/get/smart/ai/verifier.rb', line 13

def model
  @model
end

Instance Method Details

#call(instructions:, prompt:, temperature: TEMPERATURE) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/get/smart/ai/verifier.rb', line 19

def call(instructions:, prompt:, temperature: TEMPERATURE)
  Faraday.post("#{BASE_URL}#{model}:generateContent?key=#{ENV.fetch("GEMINI_API_KEY")}") do |req|
    req.headers["Content-Type"] = "application/json"
    req.body = {
      "contents": [ {
        "parts": [ { "text": prompt } ]
      } ],
      "generationConfig": {
        "response_mime_type": "application/json",
        "temperature": temperature,
        "maxOutputTokens": 30000
      },
      "system_instruction": {
        "parts": [ {
          "text": instructions
        } ]
      }
    }.to_json
  end
end