Python示范代码(最新)

系统环境

MacOS

Python 3.9.6

OpenAI 1.46.0

演示代码

from openai import OpenAI

client = OpenAI(api_key="sk-xxxx", base_url="https://openkey.cloud/v1")

completion = client.chat.completions.create(
    model="gpt-3.5-turbo",
    stream=False,
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ]
)

print(completion.choices[0].message)python

输出结果

Last updated