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

openai的翻译验证可能过于严格导致出现:失败: 未能读取数据,因为它的格式不正确。 #757

Closed
5 of 6 tasks
Wszhdg opened this issue Dec 23, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Wszhdg
Copy link

Wszhdg commented Dec 23, 2024

请先确认以下事项:

  • 请务必查看 常见问题
  • 已仔细阅读了 README
  • issues 页面搜索过问题(包括已关闭的 issue),但未能找到解决方法
  • Easydict 已升级到 最新版本
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

问题描述

我正确的填写了api地址及秘钥,并且通过抓包也返回了正确的结果,在nextchat等流式传输中api也可用,但是在本app上,会出现失败: 未能读取数据,因为它的格式不正确。以下是返回的结果:
data: {"chatgpt_model":"gpt-4o-mini","choices":[{"delta":{"content":"The translation of ""},"finish_reason":null,"index":0,"logprobs":null}],"conversation_id":"6768d152-419c-8003-abfe-6668020ab470","created":"","id":"aa37f3bd-3b86-4740-b836-5ca20bfac855","object":"chat.completion.chunk","usage":null}

data: {"chatgpt_model":"gpt-4o-mini","choices":[{"delta":{"content":"支持手动设置 OpenAI"},"finish_reason":null,"index":0,"logprobs":null}],"conversation_id":"6768d152-419c-8003-abfe-6668020ab470","created":"","id":"aa37f3bd-3b86-4740-b836-5ca20bfac855","object":"chat.completion.chunk","usage":null}

该问题是否可以稳定重现?

可重现

重现步骤

点击openai翻译即可重现

截图

image

运行日志(zip 文件)

com.izual.Easydict 2024-12-23--01-54-46-505.log

期望结果

可以正确的识别api结果

解决方案(可选)

No response

设备型号 && 系统版本

macos13.7

是否愿意提交 PR 解决该问题?

  • 我愿意提交 PR 来解决该问题
@Wszhdg Wszhdg added the bug Something isn't working label Dec 23, 2024
Copy link

Hello Wszhdg, Thank you for your first issue contribution 🎉

@Wszhdg
Copy link
Author

Wszhdg commented Dec 23, 2024

目前能怀疑的就是回复的请求头不一致,目前回复的请求头为:Content-Type: text/event-stream; charset=utf-8

@tisfeng
Copy link
Owner

tisfeng commented Dec 23, 2024

Easydict 目前只保证符合 OpenAI 官方接口 数据格式的请求能成功,对于一些奇怪的第三方接口,验证失败是正常的。

你示例中数据格式,明显和官方不符,例如返回的模型字段名应该是 model,而不是 chatgpt_model,另外,created 字段应该是 integer 而不是 string 类型。

{
    "chatgpt_model": "gpt-4o-mini",
    "choices": [
        {
            "delta": {
                "content": "支持手动设置 OpenAI"
            },
            "finish_reason": null,
            "index": 0,
            "logprobs": null
        }
    ],
    "conversation_id": "6768d152-419c-8003-abfe-6668020ab470",
    "created": "",
    "id": "aa37f3bd-3b86-4740-b836-5ca20bfac855",
    "object": "chat.completion.chunk",
    "usage": null
}

@Wszhdg Wszhdg closed this as completed Dec 24, 2024
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

No branches or pull requests

2 participants