Skip to content

快速开始 ​

出于兼容考虑,OpenDataSky 使用 OpenAI 的 API 格式调用模型,您可以使用 OpenAI SDK 或其他 OpenAI 兼容接口。

安装 OpenAI SDK ​

请确保您已经安装了 Python 环境,使用一下命令安装最新的 OpenAI SDK。

shell
pip install openai
shell
npm install openai

调用示例 ​

在调用 API 之前,需要您先注册 OpenDataSky 并创建 API Key ,同时您需要将 base_url 设置为 http://server.opendatasky.com/v1/api/open-ai/ds 。

以下为非流式调用输出示例,您可以将  stream 设置为 true 来使用流式输出。

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="http://server.opendatasky.com/v1/api/open-ai/ds"
)

completion = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ],
    top_p=0.7,
    temperature=0.9
 )

 print(completion.choices[0].message)