Class: ActiveAgent::GenerationProvider::AnthropicProvider
- Includes:
- MessageFormatting, StreamProcessing, ToolManagement
- Defined in:
- lib/active_agent/generation_provider/anthropic_provider.rb
Instance Attribute Summary
Attributes inherited from Base
#access_token, #client, #config, #model_name, #prompt, #response
Instance Method Summary collapse
- #chat_prompt(parameters: prompt_parameters) ⇒ Object
- #generate(prompt) ⇒ Object
-
#initialize(config) ⇒ AnthropicProvider
constructor
A new instance of AnthropicProvider.
Methods included from ToolManagement
#format_tools, #handle_actions
Methods included from MessageFormatting
Methods included from StreamProcessing
Methods inherited from Base
Methods included from ParameterBuilder
Methods included from ErrorHandling
Constructor Details
#initialize(config) ⇒ AnthropicProvider
Returns a new instance of AnthropicProvider.
23 24 25 26 27 28 |
# File 'lib/active_agent/generation_provider/anthropic_provider.rb', line 23 def initialize(config) super @access_token ||= config["api_key"] || config["access_token"] || Anthropic.configuration.access_token || ENV["ANTHROPIC_ACCESS_TOKEN"] @extra_headers = config["extra_headers"] || {} @client = Anthropic::Client.new(access_token: @access_token, extra_headers: @extra_headers) end |
Instance Method Details
#chat_prompt(parameters: prompt_parameters) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/active_agent/generation_provider/anthropic_provider.rb', line 38 def chat_prompt(parameters: prompt_parameters) if prompt.[:stream] || config["stream"] parameters[:stream] = provider_stream @streaming_request_params = parameters end chat_response(@client.(parameters: parameters), parameters) end |
#generate(prompt) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/active_agent/generation_provider/anthropic_provider.rb', line 30 def generate(prompt) @prompt = prompt with_error_handling do chat_prompt(parameters: prompt_parameters) end end |