Class: OmniAI::Anthropic::Chat
- Inherits:
-
Chat
- Object
- Chat
- OmniAI::Anthropic::Chat
- Defined in:
- lib/omniai/anthropic/chat.rb,
lib/omniai/anthropic/chat/response/stream.rb,
lib/omniai/anthropic/chat/response/completion.rb
Overview
Defined Under Namespace
Constant Summary collapse
- DEFAULT_MODEL =
Model::CLAUDE_SONNET
- MEDIA_SERIALIZER =
lambda do |media, *| { type: media.kind, # i.e. 'image' / 'video' / 'audio' / ... source: { type: 'base64', media_type: media.type, # i.e. 'image/jpeg' / 'video/ogg' / 'audio/mpeg' / ... data: media.data, }, } end
- CONTEXT =
Context.build do |context| context.serializers[:file] = MEDIA_SERIALIZER context.serializers[:url] = MEDIA_SERIALIZER end
Instance Method Summary collapse
Instance Method Details
#messages ⇒ Array<Hash>
65 66 67 68 |
# File 'lib/omniai/anthropic/chat.rb', line 65 def = @prompt..filter(&:user?) .map { || .serialize(context: CONTEXT) } end |
#path ⇒ String
77 78 79 |
# File 'lib/omniai/anthropic/chat.rb', line 77 def path "/#{Client::VERSION}/messages" end |
#payload ⇒ Hash
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/omniai/anthropic/chat.rb', line 53 def payload OmniAI::Anthropic.config..merge({ model: @model, messages:, system:, stream: @stream.nil? ? nil : !@stream.nil?, temperature: @temperature, tools: tools_payload, }).compact end |
#system ⇒ String?
71 72 73 74 |
# File 'lib/omniai/anthropic/chat.rb', line 71 def system = @prompt..filter(&:system?) .map(&:content).join("\n\n") if .any? end |