Class: OpenAI::Helpers::Streaming::ChoiceEventState
- Inherits:
-
Object
- Object
- OpenAI::Helpers::Streaming::ChoiceEventState
- Defined in:
- lib/openai/helpers/streaming/chat_completion_stream.rb
Instance Method Summary collapse
- #get_done_events(choice_chunk:, choice_snapshot:, response_format:, tool_calls_by_index:) ⇒ Object
-
#initialize(input_tools:) ⇒ ChoiceEventState
constructor
A new instance of ChoiceEventState.
Constructor Details
#initialize(input_tools:) ⇒ ChoiceEventState
Returns a new instance of ChoiceEventState.
655 656 657 658 659 660 661 662 663 664 665 |
# File 'lib/openai/helpers/streaming/chat_completion_stream.rb', line 655 def initialize(input_tools:) @input_tools = Array(input_tools) @content_done = false @refusal_done = false @logprobs_content_done = false @logprobs_refusal_done = false @done_tool_calls = Set.new @pending_tool_calls = Set.new @deferred_tool_calls = Set.new @current_tool_call_index = nil end |
Instance Method Details
#get_done_events(choice_chunk:, choice_snapshot:, response_format:, tool_calls_by_index:) ⇒ Object
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
# File 'lib/openai/helpers/streaming/chat_completion_stream.rb', line 667 def get_done_events(choice_chunk:, choice_snapshot:, response_format:, tool_calls_by_index:) events = [] if choice_snapshot.finish_reason events.concat(content_done_events(choice_snapshot, response_format)) end Array(choice_chunk.delta.tool_calls).each do |tool_call| if @current_tool_call_index != tool_call.index events.concat(content_done_events(choice_snapshot, response_format)) if @current_tool_call_index if !@deferred_tool_calls.include?(@current_tool_call_index) && incomplete_strict_tool_call?(tool_calls_by_index, @current_tool_call_index) @deferred_tool_calls.add(@current_tool_call_index) end unless @deferred_tool_calls.include?(@current_tool_call_index) event = tool_done_event(tool_calls_by_index, @current_tool_call_index) events << event if event end end end @pending_tool_calls.add(tool_call.index) unless @done_tool_calls.include?(tool_call.index) @current_tool_call_index = tool_call.index end if choice_snapshot.finish_reason @pending_tool_calls.to_a.each do |tool_index| event = tool_done_event(tool_calls_by_index, tool_index) events << event if event end end events end |