import os
os.environ["OPENAI_API_KEY"] = "sk-9npZpELUzM0IxRU1B79bF5B9FfC04bDeA730F4090dF782A3"
os.environ["OPENAI_PROXY"] = "https://ai-yyds.com/v1"
import openai
import os
# 设置 API 基础地址和密钥
openai.api_base = os.getenv("OPENAI_PROXY")
openai.api_key = os.getenv("OPENAI_API_KEY")
# 创建聊天消息列表
messages = [
{"role": "user", "content": "介绍下你自己"}
]
# 使用新的接口调用
res = openai.ChatCompletion.create(
model="gpt-4-1106-preview",
messages=messages,
stream=False,
)
# 打印输出结果
print(res['choices'][0]['message']['content'])
C:\Users\Administrator>pip install openai==v0.28.1 -i https://pypi.org/simple
C:\Users\Administrator>pip install --upgrade langchain -i https://pypi.org/simple
包错误是这个
APIRemovedInV1 Traceback (most recent call last)
Cell In[18], line 14
9 messages = [
10 {"role": "user", "content": "介绍下你自己"}
11 ]
13 # 使用新的接口调用
---> 14 res = openai.ChatCompletion.create(
15 model="gpt-4-1106-preview",
16 messages=messages,
17 stream=False,
18 )
20 # 打印输出结果
21 print(res['choices'][0]['message']['content'])
File c:\Python312\Lib\site-packages\openai\lib\_old_api.py:39, in APIRemovedInV1Proxy.__call__(self, *_args, **_kwargs)
38 def __call__(self, *_args: Any, **_kwargs: Any) -> Any:
---> 39 raise APIRemovedInV1(symbol=self._symbol)
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: https://github.com/openai/openai-python/discussions/742