Class: RailsAgents::Providers::Anthropic::Files
- Inherits:
-
Object
- Object
- RailsAgents::Providers::Anthropic::Files
- Defined in:
- lib/rails_agents/providers/anthropic/files.rb
Constant Summary collapse
- FILES_BETA =
"files-api-2025-04-14"- API_VERSION =
"2023-06-01"
Instance Method Summary collapse
- #download(file_id) ⇒ Object
-
#initialize(api_key: RailsAgents.config.anthropic_api_key) ⇒ Files
constructor
A new instance of Files.
- #retrieve(file_id) ⇒ Object
Constructor Details
#initialize(api_key: RailsAgents.config.anthropic_api_key) ⇒ Files
Returns a new instance of Files.
13 14 15 16 |
# File 'lib/rails_agents/providers/anthropic/files.rb', line 13 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
#download(file_id) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rails_agents/providers/anthropic/files.rb', line 18 def download(file_id) = retrieve(file_id) response = connection.get("files/#{file_id}/content") raise ProviderError, "Failed to download file #{file_id}: #{response.body}" unless response.success? GeneratedFile.new( file_id: file_id, filename: .fetch("filename"), content_type: .fetch("mime_type"), data: response.body, path: nil ) end |
#retrieve(file_id) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/rails_agents/providers/anthropic/files.rb', line 32 def retrieve(file_id) response = connection.get("files/#{file_id}") raise ProviderError, "Failed to retrieve file #{file_id}: #{response.body}" unless response.success? JSON.parse(response.body) end |