curl -X POST http://localhost:18000/api/chat \\
-H "Content-Type: application/json" \\
-d '{
"model_type": "[$MODEL_TYPE$]", // 当前选择的模型类型
"model": "[$MODEL$]", // 当前选择的模型
"api_key": "[$API_KEY$]", // 当前输入的 API Key
"prompt": "Your message here",
"enable_streaming": [$STREAMING$] // 是否启用流式输出
}'
from ai_palette import AIChat
# 初始化聊天实例
chat = AIChat(
provider="[$MODEL_TYPE$]", # 当前选择的模型类型
model="[$MODEL$]", # 当前选择的模型
api_key="[$API_KEY$]", # 当前输入的 API Key
enable_streaming=True if '[$STREAMING$]' == 'true' else False # 是否启用流式输出
)
# 发送消息
response = chat.ask("Your message here")
print(response)
# 流式输出
for chunk in chat.ask("Your message here"):
print(chunk["content"], end="", flush=True)