Class: LittleGhost::Providers::OpenAICompatible::ChatNormalizer
- Inherits:
-
Normalizer
- Object
- Normalizer
- LittleGhost::Providers::OpenAICompatible::ChatNormalizer
- Defined in:
- lib/little_ghost/providers/openai_compatible.rb
Overview
:nodoc:
Instance Method Summary collapse
- #consume(event) ⇒ Object
- #finish ⇒ Object
-
#initialize ⇒ ChatNormalizer
constructor
A new instance of ChatNormalizer.
Methods inherited from Normalizer
Constructor Details
#initialize ⇒ ChatNormalizer
Returns a new instance of ChatNormalizer.
628 629 630 631 |
# File 'lib/little_ghost/providers/openai_compatible.rb', line 628 def initialize(...) super @reasoning_details = [] end |
Instance Method Details
#consume(event) ⇒ Object
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 |
# File 'lib/little_ghost/providers/openai_compatible.rb', line 633 def consume(event) if event["error"] raise StreamError.from(event["error"], prefix: "Provider stream error") end events = [] events << start_event(event["id"], event["model"]) unless @message_id choice = event.fetch("choices", []).first if choice delta = choice["delta"] || {} events << text_delta(delta["content"]) if delta["content"] reasoning = delta["reasoning_content"] || delta["reasoning"] events << reasoning_delta(reasoning) if reasoning capture_reasoning_details(delta["reasoning_details"]) if delta.key?("reasoning_details") delta.fetch("tool_calls", []).each do |call| index = call.fetch("index") function = call["function"] || {} if call["id"] || function["name"] started = tool_start(index, call["id"], function["name"]) events << started if started end events << tool_delta(index, function["arguments"]) if function["arguments"] end if choice["finish_reason"] @stop_reason = stop_reason(choice["finish_reason"]) @terminal = true end end events << usage_event(chat_usage(event["usage"])) if event["usage"] events end |
#finish ⇒ Object
665 666 667 668 |
# File 'lib/little_ghost/providers/openai_compatible.rb', line 665 def finish events = @tool_calls.keys.sort.map { |index| tool_stop(index) } events.concat(super) end |