Class: Fastlane::Helper::Providers::GeminiProvider
- Inherits:
-
BaseProvider
- Object
- BaseProvider
- Fastlane::Helper::Providers::GeminiProvider
- Defined in:
- lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/gemini_provider.rb
Overview
Provider implementation for Google Gemini translation API using direct HTTP calls. Offers cost-effective translations suitable for high-volume use cases.
Constant Summary collapse
- DEFAULT_MODEL =
Default model for Gemini translations
'gemini-2.5-flash'.freeze
- DEFAULT_TEMPERATURE =
Default temperature for translation generation (0.5 = balanced creativity)
0.5- DEFAULT_TIMEOUT =
Default request timeout in seconds
60- API_BASE_URL =
Base URL for Gemini Generative Language API
'https://generativelanguage.googleapis.com'.freeze
Constants inherited from BaseProvider
BaseProvider::ANDROID_CHAR_LIMIT
Instance Attribute Summary
Attributes inherited from BaseProvider
Class Method Summary collapse
-
.display_name ⇒ String
Returns the human-readable display name for the provider.
-
.optional_params ⇒ Hash
Returns a hash of optional parameter definitions for this provider.
-
.provider_name ⇒ String
Returns the provider identifier string.
-
.required_credentials ⇒ Array<Symbol>
Returns the list of required credential symbols for this provider.
Instance Method Summary collapse
-
#initialize(params) ⇒ GeminiProvider
constructor
Initializes the Gemini provider with configuration parameters.
-
#translate(text, source_locale, target_locale, glossary_terms: {}) ⇒ String?
Translates text from source locale to target locale using Gemini’s API.
-
#validate_config! ⇒ void
Validates the provider configuration.
Methods inherited from BaseProvider
Constructor Details
#initialize(params) ⇒ GeminiProvider
Initializes the Gemini provider with configuration parameters.
58 59 60 61 62 63 64 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/gemini_provider.rb', line 58 def initialize(params) super @api_key = credential(:api_token) @model = @params[:model_name] || DEFAULT_MODEL @temperature = (@params[:temperature] || DEFAULT_TEMPERATURE).to_f @timeout = (@params[:request_timeout] || DEFAULT_TIMEOUT).to_i end |
Class Method Details
.display_name ⇒ String
Returns the human-readable display name for the provider.
33 34 35 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/gemini_provider.rb', line 33 def self.display_name 'Google Gemini' end |
.optional_params ⇒ Hash
Returns a hash of optional parameter definitions for this provider.
47 48 49 50 51 52 53 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/gemini_provider.rb', line 47 def self.optional_params { model_name: { default: DEFAULT_MODEL, description: 'Gemini model to use', env: 'GEMINI_MODEL_NAME' }, temperature: { default: DEFAULT_TEMPERATURE, description: 'Sampling temperature (0-1)', env: 'GEMINI_TEMPERATURE' }, request_timeout: { default: DEFAULT_TIMEOUT, description: 'Request timeout in seconds', env: 'GEMINI_REQUEST_TIMEOUT' } } end |
.provider_name ⇒ String
Returns the provider identifier string.
26 27 28 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/gemini_provider.rb', line 26 def self.provider_name 'gemini' end |
.required_credentials ⇒ Array<Symbol>
Returns the list of required credential symbols for this provider.
40 41 42 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/gemini_provider.rb', line 40 def self.required_credentials [:api_token] end |
Instance Method Details
#translate(text, source_locale, target_locale, glossary_terms: {}) ⇒ String?
Translates text from source locale to target locale using Gemini’s API.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/gemini_provider.rb', line 81 def translate(text, source_locale, target_locale, glossary_terms: {}) # Build prompt using inherited method (includes instructions, glossary, and text) prompt = build_prompt( text, source_locale, target_locale, glossary_terms: glossary_terms, platform: @params[:platform] ) # Make API call result = make_api_request(prompt) # Extract text from response enforce_android_limit(extract_text_from_response(result)) rescue StandardError => e UI.error "Gemini provider error: #{e.}" nil end |
#validate_config! ⇒ void
This method returns an undefined value.
Validates the provider configuration. Ensures that the required api_token credential is present.
70 71 72 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/gemini_provider.rb', line 70 def validate_config! require_credential(:api_token) end |