准备环境变量
macOS / Linux 终端示例:安装
完整示例
保存为example.py,执行 python example.py。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
从安装依赖到运行完整的文本对话示例。
export API_KEY='YOUR_API_KEY'
export MODEL='YOUR_MODEL_ID'
python -m pip install openai
example.py,执行 python example.py。
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["API_KEY"],
base_url="https://token.poryf.com/v1",
)
response = client.chat.completions.create(
model=os.environ["MODEL"],
messages=[{"role": "user", "content": "你好,请用一句话介绍自己。"}],
)
print(response.choices[0].message.content)