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

experimental_StreamData,If the string is too long, it will be truncated. #962

Open
zandko opened this issue Feb 7, 2024 · 1 comment
Labels
ai/ui bug Something isn't working

Comments

@zandko
Copy link

zandko commented Feb 7, 2024

Description

data.append({ 'sources': functionResponse.sources }); If the string is too long, it will be truncated.

Code example

  const data = new experimental_StreamData();

    const stream = OpenAIStream(response, {
      experimental_onToolCall: async (
        call: ToolCallPayload,
        appendToolCallMessage,
      ) => {

       // ...

        for (const toolCall of call.tools) {

          const functionName = toolCall.func.name;
          const functionToCall = availableFunctions[functionName];

          const functionArgs = JSON.parse(toolCall.func.arguments as unknown as string);
          const functionResponse = await functionToCall(parseNestedJSON(functionArgs));

          if (functionResponse.sources !== 'NONE') {
            data.append({ 'sources': functionResponse.sources });
          }

          const newMessages = appendToolCallMessage({
            tool_call_id: toolCall.id,
            function_name: functionName,
            tool_call_result: functionResponse.result,
          });

          return openai.chat.completions.create({
            ...defaultOptions,
            messages: [...messages, ...newMessages],
            model: LanguageModel.GPT3_5_16K,
            stream: true,
            tools,
            temperature: 0.2,
            tool_choice: 'auto',
          });
        }
      },
      onCompletion(completion) {
        console.log('completion', completion);
      },
      onFinal(completion) {
        data.close();
      },
      experimental_streamData: true,
    });

    return new StreamingTextResponse(stream, {
      headers: { ...ResponseHeaders }
    }, data);

Additional context

No response

@lgrammel lgrammel added bug Something isn't working ai/ui labels Sep 19, 2024
@lgrammel
Copy link
Collaborator

How long of a string are we talking about here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/ui bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants