zyddnys / manga-image-translator

Translate manga/image 一键翻译各类图片内文字 https://cotrans.touhou.ai/
https://cotrans.touhou.ai/
GNU General Public License v3.0
5.18k stars 535 forks source link

gpt使用不了 #542

Open tgchara opened 10 months ago

tgchara commented 10 months ago

报错APIConnectionError: Error communicating with OpenAI 使用的第三方站 后缀v1加不加都试过了 api

zyddnys commented 9 months ago

什么第三方站,要翻墙吗

SuperMaxine commented 7 months ago

我也遇到了同样的问题,之前是可以正常使用的,今天pull之后突然用不了gpt了,我在gpt4里插了个桩,能看到地址和key都是对的 image

image

这个第三方api我在其他的gpt客户端都可以不翻墙正常使用,但是在这边翻译图片时现在会报错

image

linhue commented 6 months ago

将 manga_translator/translators/chatgpt.py 文件中的请求方式换为 requests 包去请求,下面代码供参考。

def requestOpenAi(data, headers, token_count, token_count_last): print("----------requestOpenAi") try: response = requests.post('https://api.openai.com/v1/chat/completions', json=data, headers=headers, proxies={ "http":"http://%s" % LOCAL_PEOXY, "https":"http://%s" % LOCAL_PEOXY, }) except requests.exceptions.RequestException as e: print(f"请求错误: {e}")

result = response.json()
token_count += result['usage']['total_tokens']
token_count_last = result['usage']['total_tokens']
for choice in result['choices']:
    if 'text' in choice:
        return choice['text']

# If no response with text is found, return the first response's content (which may be empty)
return result['choices'][0]['message']['content'], token_count, token_count_last