웹 검색 (Tools)
실시간 웹 정보 검색을 지원하는 웹 검색 도구.
API 엔드포인트
POST
/chat/completions도구 포함 대화
요청 파라미터
| 파라미터 | 유형 | 필수 | 설명 |
|---|---|---|---|
model | string | 필수 | 도구 호출을 지원하는 모델 |
messages | array | 필수 | 대화 메시지 |
tools | array | 필수 | web_search를 포함한 도구 정의 목록 |
요청 예시
요청 예시
{
"model": "GLM-4-Air",
"messages": [
{
"role": "user",
"content": "请搜索一下今天的新闻"
}
],
"tools": [
{
"type": "web_search",
"web_search": {
"enable": true,
"search_query": "今天的新闻"
}
}
]
}응답 예시
응답 예시
{
"id": "chatcmpl-789",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "根据搜索结果,今天的主要新闻包括...",
"tool_calls": [
{
"id": "call_123",
"type": "web_search",
"web_search": {
"search_results": [...]
}
}
]
},
"finish_reason": "stop"
}
]
}코드 예시
Python
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://your-proxy-domain.com/v1"
)
response = client.chat.completions.create(
model="GLM-4-Air",
messages=[
{"role": "user", "content": "请搜索一下今天的新闻"}
],
tools=[
{
"type": "web_search",
"web_search": {
"enable": True,
"search_query": "今天的新闻"
}
}
]
)
print(response.choices[0].message.content)JavaScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'your-api-key',
baseURL: 'https://your-proxy-domain.com/v1'
});
async function searchWeb() {
const response = await client.chat.completions.create({
model: 'GLM-4-Air',
messages: [
{ role: 'user', content: '请搜索一下今天的新闻' }
],
tools: [
{
type: 'web_search',
web_search: {
enable: true,
search_query: '今天的新闻'
}
}
]
});
console.log(response.choices[0].message.content);
}
searchWeb();cURL
curl https://your-proxy-domain.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "GLM-4-Air",
"messages": [
{"role": "user", "content": "请搜索一下今天的新闻"}
],
"tools": [
{
"type": "web_search",
"web_search": {
"enable": true,
"search_query": "今天的新闻"
}
}
]
}'