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.
636 637 638 639 640 641 642 643 644 |
# File 'lib/openai/helpers/streaming/chat_completion_stream.rb', line 636 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 @current_tool_call_index = nil end |
Instance Method Details
#get_done_events(choice_chunk:, choice_snapshot:, response_format:, tool_calls_by_index:) ⇒ Object
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
# File 'lib/openai/helpers/streaming/chat_completion_stream.rb', line 646 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)) if @current_tool_call_index && !@done_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 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 event = tool_done_event(tool_calls_by_index, @current_tool_call_index) events << event if event end end @current_tool_call_index = tool_call.index end events end |