tmc / langchaingo

LangChain for Go, the easiest way to write LLM-based programs in Go
https://tmc.github.io/langchaingo/
MIT License
4.39k stars 597 forks source link

Function calls are made in openai, and the function is called synchronously at the same time, and the result is assembled asynchronously. Not all assembly results were returned successfully. #842

Open androidsr opened 4 months ago

androidsr commented 4 months ago

image Figure: The first synchronous execution of the call function to generate sql. The local query data is thrown to ai analysis. The second return. Secondary return Sets the asynchronous callback. At this time. The data cannot be fully returned. But sometimes it all comes back. The synchronous http test ai interface is able to return all of them every time

androidsr commented 4 months ago

image The effect is normal

douglarek commented 4 months ago

It depends on how you handle the data returned by streamfunc. The correct approach is to use asynchronous processing for GenerateContent, with a channel in Go to receive chunks from streamFunc. Once GenerateContent finishes execution, close the channel. Your main thread can then use a for range loop to iterate over the channel. Also, your issue is quite messy, making it difficult for others to understand your intention.