import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["LLM_SG_API_KEY"],
base_url="https://api.llm.sg/v1",
)
stream = client.chat.completions.create(
model=os.environ["LLM_SG_MODEL"],
messages=[{"role": "user", "content": "解释一下什么是模型聚合平台。"}],
stream=True,
)
try:
for chunk in stream:
if chunk.choices:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)
finally:
stream.close()
print()