pot-app / pot-desktop

🌈一个跨平台的划词翻译和OCR软件 | A cross-platform software for text translation and recognition.
https://pot-app.com
GNU General Public License v3.0
9.15k stars 418 forks source link

config openai translator #829

Closed xtyuns closed 3 weeks ago

xtyuns commented 3 weeks ago
  1. Fix openai not using options
  2. Add flexible argument configuration to openai
xtyuns commented 3 weeks ago

@Pylogmon PTAL

Pylogmon commented 3 weeks ago

一开始做这一步操作是为了兼容大部分人的写法,只写域名,自动补齐后面的 path,但是这样也会造成一定的局限性,我觉得可以加一个开关,是否自动补齐 path,默认打开,这样有更深入自定义 URL 的用户可以关闭开关后自定义 URL

xtyuns commented 3 weeks ago

这里删除掉 /v1 的原因是:随着 openai 服务多实例的支持,openai 服务可以添加一些 openai 风格的接口,但是它们的路径可能不是完全以 /v1/chat/completions 结尾,但是基本都会以 chat/completions 结尾,以智谱为例,它的请求地址是 https://open.bigmodel.cn/api/paas/v4/chat/completions

这个改动确定会影响原有用户的配置,因此我们能否把这块补全的逻辑修改为:

if (service === 'openai' && !requestPath.endsWith('/chat/completions')) {
    requestPath += '/v1/chat/completions';
}

这样既不会影响原有用户的配置,又可以支持上面举例中的场景

Pylogmon commented 3 weeks ago

可以