Class: Lluminary::Providers::Google
- Defined in:
- lib/lluminary/providers/google.rb
Constant Summary collapse
- NAME =
:google- DEFAULT_MODEL =
Models::Google::Gemini20Flash
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #call(prompt, _task) ⇒ Object
-
#initialize(**config_overrides) ⇒ Google
constructor
A new instance of Google.
- #model ⇒ Object
- #models ⇒ Object
Constructor Details
#initialize(**config_overrides) ⇒ Google
Returns a new instance of Google.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lluminary/providers/google.rb', line 19 def initialize(**config_overrides) super @config = { model: DEFAULT_MODEL }.merge(config) @client = ::OpenAI::Client.new( access_token: config[:api_key], api_version: "", uri_base: "https://generativelanguage.googleapis.com/v1beta/openai" ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
17 18 19 |
# File 'lib/lluminary/providers/google.rb', line 17 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
17 18 19 |
# File 'lib/lluminary/providers/google.rb', line 17 def config @config end |
Instance Method Details
#call(prompt, _task) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lluminary/providers/google.rb', line 30 def call(prompt, _task) response = client.chat( parameters: { model: model.class::NAME, messages: [{ role: "user", content: prompt }], response_format: { type: "json_object" } } ) content = response.dig("choices", 0, "message", "content") { raw: content, parsed: begin JSON.parse(content) if content rescue JSON::ParserError nil end } end |
#model ⇒ Object
55 56 57 |
# File 'lib/lluminary/providers/google.rb', line 55 def model @model ||= config[:model].new end |
#models ⇒ Object
59 60 61 62 |
# File 'lib/lluminary/providers/google.rb', line 59 def models response = @client.models.list response["data"].map { |model| model["id"].split("/").last } end |