常见问题
常见问题
1. 报错:You can find your API key at https://platform.openai.com/account/api-keys.
Traceback (most recent call last):
File "/Users/yue/PycharmProjects/KuGPT-Python2/demo/test_openlingo_with_baidu_stream_api.py", line 59, in <module>
chat()
File "/Users/yue/PycharmProjects/KuGPT-Python2/demo/test_openlingo_with_baidu_stream_api.py", line 55, in chat
openai_chat(user_input)
File "/Users/yue/PycharmProjects/KuGPT-Python2/demo/test_openlingo_with_baidu_stream_api.py", line 16, in openai_chat
response = openai.ChatCompletion.create(
File "/Users/yue/anaconda3/envs/KuGPT-Python2/lib/python3.10/site-packages/openai/api_resources/chat_completion.py", line 25, in create
return super().create(*args, **kwargs)
File "/Users/yue/anaconda3/envs/KuGPT-Python2/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
response, _, api_key = requestor.request(
File "/Users/yue/anaconda3/envs/KuGPT-Python2/lib/python3.10/site-packages/openai/api_requestor.py", line 298, in request
resp, got_stream = self._interpret_response(result, stream)
File "/Users/yue/anaconda3/envs/KuGPT-Python2/lib/python3.10/site-packages/openai/api_requestor.py", line 700, in _interpret_response
self._interpret_response_line(
File "/Users/yue/anaconda3/envs/KuGPT-Python2/lib/python3.10/site-packages/openai/api_requestor.py", line 765, in _interpret_response_line
raise self.handle_error_response(
openai.error.AuthenticationError: Incorrect API key provided: sk-zk0EM*******************************************pzWs. You can find your API key at https://platform.openai.com/account/api-keys.
openai.api_key = ModelBrige后台应用的api_screct_key
openai.api_base = http://model-bridge.okeeper.com/v1
2. base_url地址到底是哪个?
下面单独来说一下这个问题,干货是:
base-url是灵活变化的,取决于你在哪里用,和使用的接口场景。
如果是chat场景,核心最终调用的完整url是:`http://model-bridge.okeeper.com/v1/chat/completions`,到底是域名即可,还是要加v1,还是完整地址取决于你在哪用,最终它肯定要将这个完整的地址补充完整,再发起http请求。
所以最终肯定是这3个当中的一个:
`http://model-bridge.okeeper.com`
`http://model-bridge.okeeper.com/v1`
`http://model-bridge.okeeper.com/v1/chat/completions`
其它场景依次类推。
比如你在python中使用,那得看人家python包中是怎么补全这个完整地址的,得按人家的规则来。openai的python包的基地址是:
http://model-bridge.okeeper.com/v1
比如你在其它工具或sdk中使用,也得看这个工具底层是怎么 补全完整地址的。如chatgpt-next-web这个软件配置的基地址是:
http://model-bridge.okeeper.com
,是没有v1的,说明底层他会自己补全。如果是speech的场景,则根据接口文档,完整的url是:
http://model-bridge.okeeper.com/v1/audio/speech
,也取决于你是怎么来用。1、其实只要看它默认情况下是openai的什么地址,就对应的加或不加v1,或是完整地址即可。
2、实在不行,你把3个可能的地址全试一遍就行了。
3. 响应code=105,msg="token invalid."
{
"code": "105",
"msg": "token invalid.",
"success": false
}
解决:请确认在请求头部设置了
Authorization: Bearer ModelBrige后台应用的api_screct_key
修改于 2024-12-10 07:49:54