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

Open AI 接口出错 #15

Open
Darling5 opened this issue Jan 12, 2024 · 8 comments
Open

Open AI 接口出错 #15

Darling5 opened this issue Jan 12, 2024 · 8 comments

Comments

@Darling5
Copy link

Open AI 的GPT翻译出错,百度没问题

@Darling5
Copy link
Author

#appid = [''] #secretKey = ['sk-bKP******************9Zr7558'] #此为Open AI 3.5 API 未成功
main的里面也改了

@Ding-Kyoma
Copy link
Owner

有报错信息么?

@Darling5
Copy link
Author

`TCU – Tension Compression Unit
TCU Datasheet.pdf: 0%| | 0/1 [00:15<?, ?it/s]
翻译过程出现异常......
Traceback (most recent call last):
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/tenacity/init.py", line 382, in call
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/EasyTrans-mac/translate_func.py", line 170, in translate
completion = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/openai/lib/_old_api.py", line 39, in call
raise APIRemovedInV1(symbol=self._symbol)
openai.lib._old_api.APIRemovedInV1:

You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.

You can run openai migrate to automatically upgrade your codebase to use the 1.0.0 interface.

Alternatively, you can pin your installation to the old version, e.g. pip install openai==0.28

A detailed migration guide is available here: openai/openai-python#742

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/genllson/EasyTrans-mac/main.py", line 235, in main
res = net_translate(trans_pragraph).replace(' ', '')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/EasyTrans-mac/translate_func.py", line 209, in gpt_translate
translation = translate(secretKey, "Chinese", content, api_base="https://aigptx.top/v1")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/tenacity/init.py", line 289, in wrapped_f
return self(f, *args, **kw)
^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/tenacity/init.py", line 379, in call
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/tenacity/init.py", line 326, in iter
raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x10b471a90 state=finished raised APIRemovedInV1>]
/Users/genllson/EasyTrans-mac/output_file/TCU Datasheet_translated.pdf`
之前用ChatGPT 解决这个问题 换过0.28版本 和有无chat:openai.ChatCompletion 与 openai.Completion的问题

@Darling5
Copy link
Author

`翻译过程出现异常......
Traceback (most recent call last):
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/openai/api_requestor.py", line 403, in handle_error_response
error_data = resp["error"]
~~~~^^^^^^^^^
KeyError: 'error'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/tenacity/init.py", line 382, in call
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/EasyTrans-mac/translate_func.py", line 170, in translate
completion = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/openai/api_resources/chat_completion.py", line 25, in create
return super().create(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
response, _, api_key = requestor.request(
^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/openai/api_requestor.py", line 298, in request
resp, got_stream = self._interpret_response(result, stream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/openai/api_requestor.py", line 700, in _interpret_response
self._interpret_response_line(
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/openai/api_requestor.py", line 765, in _interpret_response_line
raise self.handle_error_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/openai/api_requestor.py", line 405, in handle_error_response
raise error.APIError(
openai.error.APIError: Invalid response object from API: '{"statusCode":401,"message":"Incorrect API key provided. You can get your API key at https://www.ohmygpt.com/settings","data":null}' (HTTP response code was 401)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/genllson/EasyTrans-mac/main.py", line 235, in main
res = net_translate(trans_pragraph).replace(' ', '')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/EasyTrans-mac/translate_func.py", line 209, in gpt_translate
translation = translate(secretKey, "Chinese", content, api_base="https://aigptx.top/v1")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/tenacity/init.py", line 289, in wrapped_f
return self(f, *args, **kw)
^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/tenacity/init.py", line 379, in call
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/genllson/anaconda3/lib/python3.11/site-packages/tenacity/init.py", line 326, in iter
raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x1096ce710 state=finished raised APIError>]
/Users/genllson/EasyTrans-mac/output_file/TCU Datasheet_translated.pdf`
这是OpenAI 0.28版本的报错

@Darling5
Copy link
Author

(trans) ➜ EasyTrans-mac git:(main) ✗ python main.py
当前翻译的pdf名字 TCU Datasheet.pdf

==================================== 正在翻译第1页 ====================================
TCU – Tension Compression Unit
TCU Datasheet.pdf: 0%| | 0/1 [00:22<?, ?it/s]
翻译过程出现异常......
Traceback (most recent call last):
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/openai/api_requestor.py", line 403, in handle_error_response
error_data = resp["error"]
KeyError: 'error'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/tenacity/init.py", line 382, in call
result = fn(*args, **kwargs)
File "/Users/genllson/EasyTrans-mac/translate_func.py", line 170, in translate
completion = openai.ChatCompletion.create(
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/openai/api_resources/chat_completion.py", line 25, in create
return super().create(*args, **kwargs)
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
response, _, api_key = requestor.request(
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/openai/api_requestor.py", line 298, in request
resp, got_stream = self._interpret_response(result, stream)
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/openai/api_requestor.py", line 700, in _interpret_response
self._interpret_response_line(
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/openai/api_requestor.py", line 765, in _interpret_response_line
raise self.handle_error_response(
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/openai/api_requestor.py", line 405, in handle_error_response
raise error.APIError(
openai.error.APIError: Invalid response object from API: '{"statusCode":401,"message":"Incorrect API key provided. You can get your API key at https://www.ohmygpt.com/settings","data":null}' (HTTP response code was 401)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/genllson/EasyTrans-mac/main.py", line 235, in main
res = net_translate(trans_pragraph).replace(' ', '')
File "/Users/genllson/EasyTrans-mac/translate_func.py", line 209, in gpt_translate
translation = translate(secretKey, "Chinese", content, api_base="https://aigptx.top/v1")
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/tenacity/init.py", line 289, in wrapped_f
return self(f, *args, **kw)
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/tenacity/init.py", line 379, in call
do = self.iter(retry_state=retry_state)
File "/Users/genllson/anaconda3/envs/trans/lib/python3.10/site-packages/tenacity/init.py", line 326, in iter
raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x10538a9b0 state=finished raised APIError>]
/Users/genllson/EasyTrans-mac/output_file/TCU Datasheet_translated.pdf
Total translation time: 22.6581 sec

API昨天晚上才申请的

@Darling5
Copy link
Author

#appid = [''] #secretKey = ['sk-bKP******************9Zr7558'] #此为Open AI 3.5 API 未成功 主要的里面也改了

我不知道是不是这个API填法有什么问题

@Darling5
Copy link
Author

Darling5 commented Jan 13, 2024

image

有道翻译也没成功,百度翻译没问题

@Darling5
Copy link
Author

image

百度翻译 没问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants