POST https://www.jiji.cc/v1/responses
基础调用
import os
from openai import OpenAI
client = OpenAI(
base_url="https://www.jiji.cc/v1",
api_key=os.environ["JIJI_API_KEY"],
)
resp = client.responses.create(
model="gpt-6.1-sol",
instructions="你是一个简洁的编程助手。",
input="用一句话解释什么是闭包。",
)
print(resp.output_text)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://www.jiji.cc/v1",
apiKey: process.env.JIJI_API_KEY,
});
const resp = await client.responses.create({
model: "gpt-6.1-sol",
instructions: "你是一个简洁的编程助手。",
input: "用一句话解释什么是闭包。",
});
console.log(resp.output_text);
curl https://www.jiji.cc/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $JIJI_API_KEY" \
-d '{
"model": "gpt-6.1-sol",
"instructions": "你是一个简洁的编程助手。",
"input": "用一句话解释什么是闭包。"
}'
控制思考强度
通过reasoning.effort 控制推理模型的思考深度。思考越深,效果越好,但耗时和 Token 消耗也越多:
Python
resp = client.responses.create(
model="gpt-6.1-sol",
reasoning={"effort": "high"},
input="设计一个支持撤销和重做的文本编辑器数据结构。",
)
print(resp.output_text)
| 取值 | 适合场景 |
|---|---|
low | 简单问答、格式转换 |
medium | 日常编程任务 |
high | 复杂设计、疑难 bug |
xhigh | 最难的任务,耗时最长 |
不同模型支持的取值不完全相同,以模型实际返回为准。
流式输出
Python
stream = client.responses.create(
model="gpt-6.1-sol",
input="写一首关于春天的短诗",
stream=True,
)
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
多轮对话
把历史消息放进input 列表:
Python
history = [{"role": "user", "content": "我叫小明"}]
resp = client.responses.create(model="gpt-6.1-sol", input=history)
history += resp.output
history.append({"role": "user", "content": "我叫什么名字?"})
resp = client.responses.create(model="gpt-6.1-sol", input=history)
print(resp.output_text)
建议在本地保存对话历史,每次请求完整传入,不要依赖
previous_response_id 让服务端保存上下文。工具调用
Python
import json
tools = [{
"type": "function",
"name": "get_weather",
"description": "查询城市的实时天气",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}]
history = [{"role": "user", "content": "北京今天天气怎么样?"}]
resp = client.responses.create(model="gpt-6.1-sol", input=history, tools=tools)
for item in resp.output:
if item.type == "function_call":
args = json.loads(item.arguments)
result = {"city": args["city"], "weather": "晴", "temp": 22} # 替换为真实查询
history += resp.output
history.append({
"type": "function_call_output",
"call_id": item.call_id,
"output": json.dumps(result, ensure_ascii=False),
})
resp = client.responses.create(model="gpt-6.1-sol", input=history, tools=tools)
print(resp.output_text)

