Class: RailsAgents::Providers::Anthropic
- Defined in:
- lib/rails_agents/providers/anthropic.rb,
lib/rails_agents/providers/anthropic/files.rb
Defined Under Namespace
Classes: Files
Constant Summary collapse
- API_VERSION =
"2023-06-01"
Instance Method Summary collapse
- #chat(messages:, client_tools: [], skills: nil, model:, json: false, &block) ⇒ Object
- #files ⇒ Object
-
#initialize(api_key: RailsAgents.config.anthropic_api_key) ⇒ Anthropic
constructor
A new instance of Anthropic.
Constructor Details
#initialize(api_key: RailsAgents.config.anthropic_api_key) ⇒ Anthropic
Returns a new instance of Anthropic.
11 12 13 14 |
# File 'lib/rails_agents/providers/anthropic.rb', line 11 def initialize(api_key: RailsAgents.config.anthropic_api_key) raise ConfigurationError, "Set anthropic_api_key in config/initializers/rails_agents.rb" if api_key.to_s.empty? @api_key = api_key end |
Instance Method Details
#chat(messages:, client_tools: [], skills: nil, model:, json: false, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/rails_agents/providers/anthropic.rb', line 16 def chat(messages:, client_tools: [], skills: nil, model:, json: false, &block) anthropic_skills = skills&.anthropic_request || {} body = build_body(messages:, client_tools:, skills: anthropic_skills, model:) response = connection(anthropic_skills[:beta_headers]).post("messages", body.to_json) raise ProviderError, parse_error(response) unless response.success? parse_response(JSON.parse(response.body), json:) end |