Class: Fastlane::Helper::Providers::AnthropicProvider
- Inherits:
-
BaseProvider
- Object
- BaseProvider
- Fastlane::Helper::Providers::AnthropicProvider
- Defined in:
- lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb
Overview
Provider implementation for Anthropic Claude translation API. Uses the Claude models for high-quality text translation with strong reasoning capabilities.
Constant Summary collapse
- DEFAULT_MODEL =
Default model for Anthropic translations
'claude-sonnet-4.5'.freeze
- DEFAULT_MAX_TOKENS =
Default maximum tokens for translation response
1024- DEFAULT_TEMPERATURE =
Default temperature for translation generation (0.5 = balanced creativity)
0.5- DEFAULT_TIMEOUT =
Default request timeout in seconds
60
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) ⇒ AnthropicProvider
constructor
Initializes the Anthropic provider with configuration parameters.
-
#translate(text, source_locale, target_locale, glossary_terms: {}) ⇒ String?
Translates text from source locale to target locale using Anthropic’s API.
-
#validate_config! ⇒ void
Validates the provider configuration.
Methods inherited from BaseProvider
Constructor Details
#initialize(params) ⇒ AnthropicProvider
Initializes the Anthropic provider with configuration parameters. Sets up the Anthropic::Client with appropriate credentials and timeout.
59 60 61 62 63 64 65 66 67 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 59 def initialize(params) super timeout = @params[:request_timeout] || DEFAULT_TIMEOUT @client = Anthropic::Client.new( api_key: credential(:api_token), timeout: timeout.to_i ) end |
Class Method Details
.display_name ⇒ String
Returns the human-readable display name for the provider.
32 33 34 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 32 def self.display_name 'Anthropic Claude' end |
.optional_params ⇒ Hash
Returns a hash of optional parameter definitions for this provider.
46 47 48 49 50 51 52 53 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 46 def self.optional_params { model_name: { default: DEFAULT_MODEL, description: 'Anthropic model to use', env: 'ANTHROPIC_MODEL_NAME' }, max_tokens: { default: DEFAULT_MAX_TOKENS, description: 'Maximum tokens in response', env: 'ANTHROPIC_MAX_TOKENS' }, temperature: { default: DEFAULT_TEMPERATURE, description: 'Sampling temperature (0-1)', env: 'ANTHROPIC_TEMPERATURE' }, request_timeout: { default: DEFAULT_TIMEOUT, description: 'Request timeout in seconds', env: 'ANTHROPIC_REQUEST_TIMEOUT' } } end |
.provider_name ⇒ String
Returns the provider identifier string.
25 26 27 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 25 def self.provider_name 'anthropic' end |
.required_credentials ⇒ Array<Symbol>
Returns the list of required credential symbols for this provider.
39 40 41 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 39 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 Anthropic’s API.
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 84 def translate(text, source_locale, target_locale, glossary_terms: {}) system_instruction = build_system_instruction( source_locale, target_locale, glossary_terms: glossary_terms, platform: @params[:platform] ) response = @client..create(build_create_params(system_instruction, text)) enforce_android_limit(extract_text_from_response(response)) rescue StandardError => e UI.error "Anthropic 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.
73 74 75 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 73 def validate_config! require_credential(:api_token) end |