跳到正文
TimRouter
文档/Python 代码示例/python 库流式传输输出
本页目录

python 库流式传输输出

from openai import OpenAI

client = OpenAI(
    base_url="https://api.timrouter.com/v1",
    api_key="YOUR_API_KEY"
)

stream = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Say this is a test"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

输入关键词,搜索全部文档。

搜索教程标题与正文 · Esc 关闭