Module: OmniAI::Anthropic::Chat::ChoiceSerializer
- Defined in:
- lib/omniai/anthropic/chat/choice_serializer.rb
Overview
Overrides choice serialize / deserialize.
Constant Summary collapse
- FINISH_REASONS =
Maps Anthropic ‘stop_reason` values onto the normalized OmniAI::Chat::FinishReason symbols. `pause_turn` is intentionally absent (a continuation signal, neither a stop nor a filter) — it falls through to `:other`.
{ "end_turn" => OmniAI::Chat::FinishReason::STOP, "stop_sequence" => OmniAI::Chat::FinishReason::STOP, "max_tokens" => OmniAI::Chat::FinishReason::LENGTH, "tool_use" => OmniAI::Chat::FinishReason::TOOL_CALL, "refusal" => OmniAI::Chat::FinishReason::FILTER, }.freeze
Class Method Summary collapse
Class Method Details
.deserialize(data, context:) ⇒ OmniAI::Chat::Choice
28 29 30 31 32 |
# File 'lib/omniai/anthropic/chat/choice_serializer.rb', line 28 def self.deserialize(data, context:) = OmniAI::Chat::Message.deserialize(data, context:) finish_reason = OmniAI::Chat::FinishReason.deserialize(data["stop_reason"], table: FINISH_REASONS) OmniAI::Chat::Choice.new(message:, finish_reason:) end |
.serialize(choice, context:) ⇒ Hash
21 22 23 |
# File 'lib/omniai/anthropic/chat/choice_serializer.rb', line 21 def self.serialize(choice, context:) choice..serialize(context:) end |