Class: ActiveGenie::Providers::GoogleProvider
- Inherits:
-
BaseProvider
- Object
- BaseProvider
- ActiveGenie::Providers::GoogleProvider
- Defined in:
- lib/active_genie/providers/google_provider.rb
Overview
Provider for interacting with the Google Generative Language API.
Constant Summary collapse
- API_VERSION_PATH =
'v1beta/models'- ROLE_TO_GOOGLE_ROLE =
{ user: 'user', assistant: 'model' }.freeze
Constants inherited from BaseProvider
BaseProvider::DEFAULT_HEADERS, BaseProvider::DEFAULT_MAX_RETRIES, BaseProvider::DEFAULT_OPEN_TIMEOUT, BaseProvider::DEFAULT_RETRY_DELAY, BaseProvider::DEFAULT_TIMEOUT
Instance Method Summary collapse
-
#function_calling(messages, function) ⇒ Hash?
Requests structured JSON output from the Google Generative Language model based on a schema.
Methods inherited from BaseProvider
#delete, #get, #initialize, #post, #put
Constructor Details
This class inherits a constructor from ActiveGenie::Providers::BaseProvider
Instance Method Details
#function_calling(messages, function) ⇒ Hash?
Requests structured JSON output from the Google Generative Language model based on a schema.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/active_genie/providers/google_provider.rb', line 19 def function_calling(, function) contents = (, function) contents << output_as_json_schema(function) payload = { contents:, generationConfig: { response_mime_type: 'application/json', temperature: 0.1 } } params = { key: provider_config.api_key } response = retry_with_backoff do request(payload, params) end json_string = response&.dig('candidates', 0, 'content', 'parts', 0, 'text') return nil if json_string.nil? || json_string.empty? ActiveGenie.logger.call( { code: :function_calling, fine_tune: true, payload:, parsed_response: json_string }, config: @config ) normalize_response(json_string) end |