LLPhant icon indicating copy to clipboard operation
LLPhant copied to clipboard

Tool calls in streamed responses

Open arnaudgoulpeau opened this issue 1 year ago • 1 comments

Hi !

I tried to use the OpenAIChat::createStreamedResponse with a function.

The finishReason is not function_call but tool_calls

It is not the only issue I faced.

Since it is a stream, when hitting the finishReason="tool_class", the array $toolsCalled is empty.

Here is the cinematic of $partialResponse->choices[0]->delta->toolCalls (note that $toolsCalled = []; for each piece of stream)

array:1 [
  0 => OpenAI\Responses\Chat\CreateStreamedResponseToolCall^ {#202
    +id: "call_lzS2i19jrpRSCKftKDLoRa2G"
    +type: "function"
    +function: OpenAI\Responses\Chat\CreateStreamedResponseToolCallFunction^ {#178
      +name: "sendMail"
      +arguments: ""
    }
  }
]
array:1 [
  0 => OpenAI\Responses\Chat\CreateStreamedResponseToolCall^ {#86
    +id: null
    +type: null
    +function: OpenAI\Responses\Chat\CreateStreamedResponseToolCallFunction^ {#400
      +name: null
      +arguments: "{\n"
    }
  }
]

...

array:1 [
  0 => OpenAI\Responses\Chat\CreateStreamedResponseToolCall^ {#414
    +id: null
    +type: null
    +function: OpenAI\Responses\Chat\CreateStreamedResponseToolCallFunction^ {#413
      +name: null
      +arguments: "}"
    }
  }
]
[]

Note the empty array

I honnestly don't know how to "merge" the buidling $toolsCalled for each piece of stream.

arnaudgoulpeau avatar Apr 02 '24 16:04 arnaudgoulpeau

Hey @arnaudgoulpeau, thanks for having spotted this. I'll have a look at it when I have a bit of time.

Can you write me the code you used to get this so I can use it as a test?

MaximeThoonsen avatar Apr 10 '24 09:04 MaximeThoonsen