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.67k stars 435 forks source link

[Feature]: 增加Azure OpenAI API支持和自定义Prompts #52

Closed kaiyo655 closed 1 year ago

kaiyo655 commented 1 year ago

需求描述

  1. OpenAI API支持Azure OpenAI API
  2. OpenAI 自定义支持修改system prompt and user prompt

应用场景

  1. Azure OpenAI API提供了简便和可用性较高的GPT 3.5/4的选择, 希望能够添加支持. 但是它的api和openai api有所区别, 详见官方文档Azure OpenAI Studio代码示例
  2. 不同的translation prompts会对模型的输出有影响, 因此也希望有自定义的选项

参考资料

No response

Pylogmon commented 1 year ago

感谢反馈!

  1. 我很早就想要支持了,但是我没有申请到Azure OpenaAI 的资格,所以没法测试。
  2. 很棒的建议,后续支持一下。
Pylogmon commented 1 year ago

已添加自定义Prompt选项: edee34bee25ae9596e59e2cb40a0e51340214864

Pylogmon commented 1 year ago

image

bigeqali commented 1 year ago

感谢作者的工具! 希望可以将整个url外放出来配置,这样可以提高自由度。现在只能配置domain https://${domain}/v1/chat/completions

Pylogmon commented 1 year ago

为什么要配置后面的路径呢,不同的接口请求内容不一样,如果后面也改的话接口也没法用了,配置那个没啥意义。

bigeqali commented 1 year ago

Azure的url形式并不是固定,我目前用Azure的url也是与OpenAI的url存在差异,比如我的url里没有"v1"。 目前我发现只有openai-translator是支持这种比较自由的配置形式,但openai-translator的易用性并不如pot。

以下是openai-translator的配置形式 image

Pylogmon commented 1 year ago

了解,后续加上

Pylogmon commented 1 year ago

已支持Azure,添加了两个设置项 image image

因为我没有Azure账号用来测试,所以这部分功能极有可能存在问题,后续使用如果遇到问题请及时向我反馈。

bigeqali commented 1 year ago

感谢作者

已支持Azure,添加了两个设置项 image image

因为我没有Azure账号用来测试,所以这部分功能极有可能存在问题,后续使用如果遇到问题请及时向我反馈。

感谢作者大大的快速支持。我发现一个问题,Azure与OpenAI的验证Header不一样,可能因为这个问题导致请求失败

        case 'ChatGPT':
            headers['Authorization'] = `Bearer ${apiKey}`
            break

        case 'Azure':
            headers['api-key'] = `${apiKey}`
            break

在错误返回上没有详细的错误信息 image

再次感谢作者大大,我会持续跟进测试的

Pylogmon commented 1 year ago

header我改了的,方便发我一下你的配置我来测试一下吗

Pylogmon commented 1 year ago

看起来我的header写错了,我写到Authorization里面了

bigeqali commented 1 year ago

抱歉,因为我不能随便刷新api-key,因此也不方便提供api-key。但我可以帮忙测试,windows构建包可以发我邮箱bigeqalinaewae0@outlook.com

现在的Header设置应该是有问题的

    const headers = service == 'openai' ? {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${apikey}`,
    } : {
        'Content-Type': 'application/json',
        Authorization: `api-key: ${apikey}`,
    }

根据Azure的文档,应该用"api-key"作为header

    const headers = service == 'openai' ? {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${apikey}`,
    } : {
        'Content-Type': 'application/json',
        'api-key': `${apikey}`,
    }
kaiyo655 commented 1 year ago

如果需要的话我可以提供密钥供测试

bigeqali @.***>于2023年5月18日 周四13:19写道:

抱歉,因为我不能随便刷新api-key,因此也不方便提供api-key。但我可以帮忙测试,windows构建包可以发我邮箱 @.***

现在的Header设置应该是有问题的

const headers = service == 'openai' ? {
    'Content-Type': 'application/json',
    Authorization: `Bearer ${apikey}`,
} : {
    'Content-Type': 'application/json',
    Authorization: `api-key: ${apikey}`,
}

根据Azure的文档 https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#example-request ,应该用"api-key"作为header

const headers = service == 'openai' ? {
    'Content-Type': 'application/json',
    Authorization: `Bearer ${apikey}`,
} : {
    'Content-Type': 'application/json',
    'api-key': `${apikey}`,
}

— Reply to this email directly, view it on GitHub https://github.com/pot-app/pot-desktop/issues/52#issuecomment-1552412589, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4WRVAGMQGD3EWHCFCSJFTXGWWPBANCNFSM6AAAAAAXQMQ4UA . You are receiving this because you authored the thread.Message ID: @.***>

Pylogmon commented 1 year ago

如果需要的话我可以提供密钥供测试

麻烦发我邮箱 pylogmon@outlook.com

感谢🫡

kaiyo655 commented 1 year ago

如果需要的话我可以提供密钥供测试

麻烦发我邮箱 pylogmon@outlook.com

感谢🫡

邮件已发

Pylogmon commented 1 year ago

邮件已发

不知道为什么stream输出是一大段一大段的,小段文本根本看不出来是stream输出,大段文本这么输出效果也不好。

kaiyo655 commented 1 year ago

邮件已发

不知道为什么stream输出是一大段一大段的,小段文本根本看不出来是stream输出,大段文本这么输出效果也不好。

Azure默认就是整段输出的, stream应该是要另外配置

Pylogmon commented 1 year ago

body里面写了stream,确实是按照stream的格式返回的,我的意思是他的stream每次返回太长了。

Pylogmon commented 1 year ago

是你在部署的时候需要设置吗

kaiyo655 commented 1 year ago

是你在部署的时候需要设置吗

这个应该是调用的时候吧, 我看到目前的实现譬如ChatGPTBox就是stream, 有的实现opencat是整段(好像)

Pylogmon commented 1 year ago

现在是stream没错,只是stream的单次返回长度有点怪,你待会可以试试。

Pylogmon commented 1 year ago

https://github.com/pot-app/pot-desktop/suites/12981306939/artifacts/702445034

bigeqali commented 1 year ago

https://github.com/pot-app/pot-desktop/suites/12981306939/artifacts/702445034

我点击翻译按钮之后,过一会儿,会白屏(软件界面全白)。感觉是响应时报错了。但我不知道在哪里收集错误日志(windows10)

Pylogmon commented 1 year ago

我发现azure有两个接口,你是不是用的旧版的接口

kaiyo655 commented 1 year ago

macOS什么时候有版本

现在是stream没错,只是stream的单次返回长度有点怪,你待会可以试试。

Pylogmon commented 1 year ago

actions有自动打包的

Pylogmon commented 1 year ago

https://github.com/pot-app/pot-desktop/actions/runs/5012031434

bigeqali commented 1 year ago

我发现azure有两个接口,你是不是用的旧版的接口

现在是翻译的功能是ok的。代码解析、润色、总结这几个功能还是会返回"http请求出错 {}"
十分感谢,终于用上了杀手锏级别的功能

Pylogmon commented 1 year ago

是的,那几个我还没改,我想确认没问题再去改,所以知道白屏是什么原因了吗?

bigeqali commented 1 year ago

我重新输入了我的配置(我怕我的配置有问题),然后用回车代替了点击"翻译"按钮,就可以了。也可能我之前的配置配错了😂。 希望可以增加日志文件输出,有日志定位问题应该会方便一点

bigeqali commented 1 year ago

@Pylogmon 作者大大,代码解析、润色、总结这几个功能的url拼接忘改了,还是用了这个https://${domain}/v1/chat/completions

Pylogmon commented 1 year ago

麻了,我还检查了几遍

keung67 commented 1 year ago

請問azure接口如何設置? 自訂域 aigpt3540.openai.azure.com 路徑 /openai/deployments/gpt35/completions?api-version=2023-03-15-preview 按照azure填好key 出現 Http请求错误 Http Status: 400 undefined 若路徑不填404錯誤 最後只能openai使用Cloudflare反向代理chatgptProxyAPI

Pylogmon commented 1 year ago

只支持了azure新版API, 像chat/completions这样的

keung67 commented 1 year ago

只支持了azure新版API, 像chat/completions这样的

謝謝,先Cloudflare先頂著用