openai-go icon indicating copy to clipboard operation
openai-go copied to clipboard

Stream with tool call and langchain fail

Open alejandrojnm opened this issue 6 months ago • 4 comments

I write a simple api to test the lib using Llama (vllm) as backend, everything work fine if I don't send a tool. I'm sure is not the model because I test with https://github.com/sashabaranov/go-openai and work fine.

I'm making the call using langchain

this Is the code that I have, can be something I have wrong ?


body, err := io.ReadAll(r.Body)
	if err != nil {
		utils.JSONError(w, http.StatusBadRequest, "Invalid request body")
		return
	}

	var chatRequest openai.ChatCompletionNewParams
	err = json.Unmarshal(body, &chatRequest)
	if err != nil {
		utils.JSONError(w, http.StatusBadRequest, "Invalid request body")
		return
	}

// Create the stream
		stream := client.Chat.Completions.NewStreaming(
			r.Context(),
			chatRequest,
		)

		acc := openai.ChatCompletionAccumulator{}
		for stream.Next() {
			chunk := stream.Current()
			acc.AddChunk(chunk)

			if len(chunk.Choices) > 0 {
				utils.SendEvent(w, utils.EventStream{
					Data: chunk,
				})
			}
		}

any idea why ?

alejandrojnm avatar May 27 '25 08:05 alejandrojnm

Thanks for this report, I'll look into this.

jacobzim-stl avatar May 27 '25 13:05 jacobzim-stl

I'm using net/http and mux, in case that help you to debug the problem

alejandrojnm avatar May 27 '25 13:05 alejandrojnm

I wasn't able to reproduce this bug, would you mind sharing a request.

You can a request with option.WithDebugLog(log.Default)

jacobzim-stl avatar Jul 21 '25 22:07 jacobzim-stl

I will try again with the last version of the lib and that option.

alejandrojnm avatar Jul 22 '25 06:07 alejandrojnm