Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streaming - get run_id from toolCallDone event #1260

Open
1 task done
carmen0208 opened this issue Jan 13, 2025 · 0 comments
Open
1 task done

streaming - get run_id from toolCallDone event #1260

carmen0208 opened this issue Jan 13, 2025 · 0 comments

Comments

@carmen0208
Copy link

Confirm this is a feature request for the Node library and not the underlying OpenAI API.

  • This is a feature request for the Node library

Describe the feature or improvement you're requesting

Current Behavior

When handling tool outputs using submitToolOutputsStream(), we currently need to track the run_id through the runStepCreated event; it would be better if the run_id is available in the toolCallDone event's payload.

Current pattern:

 const stream: AssistantStream = await openaiClient.beta.threads.runs.stream(
      thread.id,
      {
        assistant_id: assistant.id,
      }
    );

    let runId: string | undefined;
    stream
      .on("runStepCreated", (runStep) => {
        runId = runStep.run_id;
      })
      .on("toolCallDone", async (toolCall) => {
        console.log("toolCallDone", toolCall);
        if (toolCall.type == "function") {
          // call function...
          if (runId) {
              await openaiClient.beta.threads.runs.submitToolOutputsStream(
                thread.id,
                runId,
                {
                  tool_outputs: [
                    ...
                  ],
                }
              );
          }
        }
      })

Proposed Enhancement

The toolCallDone event handler should receive the run_id directly in its payload, eliminating the need for the separate runStepCreated event handler. This would simplify the code and remove potential race conditions.

Suggested pattern:

outputStream
  .on("toolCallDone", async (toolCall: ToolCall, runId: string) => {
     // call function...
    await openaiClient.beta.threads.runs.submitToolOutputsStream(
        thread.id,
        runId,
        {
          tool_outputs: [...],
        }
      );
}

Benefits

  1. Simpler, more straightforward code
  2. Eliminates potential race conditions between events
  3. Reduces unnecessary state management
  4. More intuitive API design

Additional Context

This enhancement would be particularly useful when chaining multiple tool calls, as it would remove the need to maintain run ID state between event handlers.

Environment

  • OpenAI Node.js Library Version: [4.77.3]

Additional context

No response

@carmen0208 carmen0208 changed the title [streaming]get run_id from toolCallDone event streaming - get run_id from toolCallDone event Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant