使用 OpenAI 官方 Python 包
OpenAI()
实例 中添加 api_key
和 base_url
参数from openai import OpenAI
key = "sk-xxx"
url = "https://api.b3n.fun/v1"
client = OpenAI(api_key=key, base_url=url)
completion = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(completion)
修改于 2024-04-10 12:31:33