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

html escape problem \u003c\u003e for json serialization in request gpt response results #23827

Closed
jokerhaos opened this issue Dec 4, 2024 · 4 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team OpenAI question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@jokerhaos
Copy link

  1. version 0.7.0+
  2. path [email protected]\models_serde.go
  3. request body
    "messages": [
        {
            "role": "user",
            "content": "用这几个符合“《》/<>”写一句话,10个字"
        }
    ],
  1. The error occurred on line 1799, json.Marshal(objectMap), which requires html escape problem escapeHTML: true
  2. At present, my fork warehouse is relatively simple, and I hope that the official can write a better performance scheme
// MarshalJSON implements the json.Marshaller interface for type ChatCompletions.
func (c ChatCompletions) MarshalJSON() ([]byte, error) {
	objectMap := make(map[string]any)
	populate(objectMap, "choices", c.Choices)
	populateTimeUnix(objectMap, "created", c.Created)
	populate(objectMap, "id", c.ID)
	populate(objectMap, "model", c.Model)
	populate(objectMap, "prompt_filter_results", c.PromptFilterResults)
	populate(objectMap, "system_fingerprint", c.SystemFingerprint)
	populate(objectMap, "usage", c.Usage)
	return JSONMarshal(objectMap)
}

func JSONMarshal(data any) ([]byte, error) {
	raw, err := json.Marshal(data)
	if err != nil {
		return nil, err
	}
	result := strings.ReplaceAll(string(raw), "\\u003c", "<")
	result = strings.ReplaceAll(result, "\\u003e", ">")
	result = strings.ReplaceAll(result, "\\u0026", "&")
	return []byte(result), nil
}
@jokerhaos jokerhaos changed the title 请求gpt响应结果中json序列化的html转义问题\u003c\u003e html escape problem \u003c\u003e for json serialization in request gpt response results Dec 4, 2024
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 4, 2024
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Dec 4, 2024
@richardpark-msft
Copy link
Member

Hey @jokerhaos,

I'm not sure if I understand what's broken. I'm able to send the content you have above to Azure OpenAI without any issue, so it must serialize properly, and there's no requirement that this data be directly usable as HTML.

Here's my sample program, which runs without error. Please let me know if I've misunderstood what you are trying to do:

client := newTestClient(t, azureOpenAI.ChatCompletions.Endpoint)

	resp, err := client.GetChatCompletions(context.Background(), azopenai.ChatCompletionsOptions{
		DeploymentName: &azureOpenAI.ChatCompletions.Model,
		Messages: []azopenai.ChatRequestMessageClassification{
			&azopenai.ChatRequestUserMessage{
				Content: azopenai.NewChatRequestUserMessageContent("用这几个符合“《》/<>”写一句话,10个字"),
			},
		},
	}, nil)
	require.NoError(t, err)

	t.Logf("%#v", resp)

	jsonResp, err := json.Marshal(resp)
	require.NoError(t, err)
	require.NotEmpty(t, jsonResp)

@richardpark-msft richardpark-msft added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Dec 4, 2024
Copy link

github-actions bot commented Dec 4, 2024

Hi @jokerhaos. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

@jokerhaos
Copy link
Author

@richardpark-msft Image
If you look at my screenshot, the response value has html tag <>, json serial number will be escaped

@github-actions github-actions bot added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-author-feedback Workflow: More information is needed from author to address the issue. labels Dec 6, 2024
@richardpark-msft
Copy link
Member

Ah, okay, I understand now. We don't have anything in the SDK that's attempting to convert these characters, so this appears to be more an issue in what the model is returning. That is out of the purview of the SDK, and will be something you'll need to address in your prompt, and may even change depending on the model you use.

There are features in OpenAI that can help with providing outputs that are more strictly specified, like Structured Outputs, but we don't provide anything like that directly in the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team OpenAI question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

3 participants