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

Modify assistant notice: invalid character '<' looking for beginning of value #836

Closed
WangQuanTang opened this issue Aug 28, 2024 · 2 comments · Fixed by #856
Closed

Modify assistant notice: invalid character '<' looking for beginning of value #836

WangQuanTang opened this issue Aug 28, 2024 · 2 comments · Fixed by #856
Labels
bug Something isn't working

Comments

@WangQuanTang
Copy link

Your issue may already be reported!
Please search on the issue tracker before creating one.

Describe the bug
When I do an update to assistant it says: "error, status code: 403, message: invalid character '<' looking for beginning of value"

To Reproduce

// UpdateAssistant update assistant
func (service *RemoteAssistantService) UpdateAssistant(ctx context.Context, updateAssistantReq UpdatedAssistantReq) error {
	tools, err := formatAssistantTools(updateAssistantReq.Tools)
	if err != nil {
		return err
	}

	toolResources, err := formatAssistantToolResources(updateAssistantReq.ToolResources)
	if err != nil {
		return err
	}

	assistantRequest := openai.AssistantRequest{
		Model:         updateAssistantReq.Model,
		Instructions:  &updateAssistantReq.Instructions,
		Name:          &updateAssistantReq.Name,
		Tools:         tools,
		ToolResources: &toolResources,
	}
	if updateAssistantReq.Instructions != "" {
		assistantRequest.Instructions = &updateAssistantReq.Instructions
	}

	_, err = service.OpenAiClient.ModifyAssistant(ctx, updateAssistantReq.AssistantAppId, assistantRequest)
	if err != nil {
		return err
	}

	return nil
}

Expected behavior
I tried to google some solutions. Some said it was because of the proxy, and some said it was a situation that could only be reproduced by chance. My previous project also used go-openai, version v1.26.0, and the same update operation was successful in the previous project. By printing the context, client and request parameters, they are almost the same. Therefore, I judged that there was no problem with my code, and it might be other abnormalities.
When I upgraded to v1.29.0, the issue still exists.

Screenshots/Logs

error, status code: 403, message: invalid character '<' looking for beginning of value

Environment (please complete the following information):

  • go-openai version: go-openai v1.27.0
  • Go version: version go1.22.5
  • OpenAI API version: [e.g. v2]
  • OS: [e.g. Ubuntu 20.04]
@WangQuanTang WangQuanTang added the bug Something isn't working label Aug 28, 2024
@gspeicher
Copy link

I just sporadically got this same error after upgrading from v1.28.1 to v1.29.1 and calling CreateChatCompletion with a JSON schema for the new structured output feature, but the upgrade may just be a coincidence because I'm having a hard time reproducing with either version. I did some quick web searching, and it seems that the Go Stripe client had a similar issue which was resolved by this PR.

The long and the short of it is that with HTTP/2, it's not always safe to reuse an HTTP request from the Go http package. More details here and here. The Go Stripe issue was happening inside of a retry loop, and refreshing the request body on each iteration did the trick there.

For what it's worth, my error occurred within a retry loop in my application, but even so, I don't see any way that the code path could result in reusing the underlying request or the body at all.

@WangQuanTang are you reliably getting this error every time?

@gspeicher
Copy link

Oh, I just noticed error status code 403 in your log output. I see the problem now. That status code is http.StatusForbidden which means the response gets processed by handleErrorResp as called from sendRequest.

That function attempts to parse the response body under the assumption that it's in JSON format, but the OpenAI API must be responding with HTML which is causing the JSON decoder to fail with this error message about the invalid character when it encounters an HTML tag.

Your problem seems to be that your API key isn't working. My problem must have been a sporadic service issue with the API. Maybe the failure result processing can be improved to make it more obvious what the problem is when this happens in either scenario.

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

Successfully merging a pull request may close this issue.

2 participants