高级功能
本文说明 AnideaAI 在 https://anideaai.com/v1 上可直接使用的高级能力。
1. 工具调用(函数调用)
工具调用适合“让模型先决定要不要调用外部函数,再由你执行函数并回填结果”。
请求示例(/v1/chat/completions)
{
"model": "gpt-5.4",
"messages": [
{"role": "user", "content": "帮我查一下新加坡今天温度"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "根据城市查询天气",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string"}
},
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}
2. 结构化输出(JSON 模式)
当你需要稳定结构(如工单字段、评分结果),建议使用 response_format。
请求示例
{
"model": "gpt-5.4",
"messages": [{"role": "user", "content": "提取客户姓名和电话"}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "customer_info",
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"phone": {"type": "string"}
},
"required": ["name", "phone"]
}
}
}
}
3. 多模态输入(视觉)
在 messages[].content 中传入图片链接,可用于看图问答、商品图理解、海报审查等。
示例
{
"model": "gpt-5.4",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "这张图里最醒目的元素是什么?"},
{"type": "image_url", "image_url": {"url": "https://example.com/product.jpg"}}
]
}
]
}
4. 提示缓存(降低重复输入成本)
当模型或上游支持缓存时,返回中的 usage 会出现缓存相关字段:
- OpenAI 风格:
prompt_tokens_details.cached_tokens - Anthropic 风格:
cache_creation_input_tokens、cache_read_input_tokens
建议做法:
- 把稳定不变的系统提示尽量固定。
- 复用会话上下文,减少重复长文本输入。
- 监控
usage字段,评估缓存收益。
5. Realtime API(WebSocket)
- 连接地址:
wss://anideaai.com/v1/realtime?model=gpt-4o-realtime-preview - 认证方式:
Authorization: Bearer sk-xxxxx - 典型场景:低延迟语音对话、实时字幕、交互式助手。
JavaScript 连接示例
const ws = new WebSocket(
"wss://anideaai.com/v1/realtime?model=gpt-4o-realtime-preview",
{
headers: { Authorization: "Bearer sk-xxxxx" }
}
);
ws.onmessage = (event) => {
console.log("realtime event:", event.data);
};