1. 接口描述
接口请求域名: cls.tencentcloudapi.com 。
调用接口,发起一次对话请求。
本接口支持智能生成检索分析语句等日志服务AI功能。
⚠️注意:通过SSE流式调用此接口时,请务必设置请求域名(Endpoint)为 cls.ai.tencentcloudapi.com。
默认接口请求频率限制:20次/秒。
2. 输入参数
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| Action | 是 | String | 公共参数,本接口取值:ChatCompletions。 |
| Version | 是 | String | 公共参数,本接口取值:2020-10-16。 |
| Region | 是 | String | 公共参数,详见产品支持的 地域列表。 |
| Model | 是 | String | 功能名称 枚举值:
示例值:text2sql |
| Messages.N | 是 | Array of Message | 聊天上下文信息。
|
| Stream | 否 | Boolean | 流式调用开关。
注意:
示例值:false |
| Metadata.N | 否 | Array of MetadataItem | 额外元数据信息。例如:[{"Key":"topic_id","Value":"xxxxxxxx-xxxx"},{"Key":"topic_region","Value":"ap-guangzhou"}] |
3. 输出参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| Created | Integer | Unix 时间戳,单位为秒。 示例值:1705634032 |
| Usage | ChatUsage | Token 统计信息。 |
| Id | String | 本次请求的 Id。 示例值:xxxxxxxx-xxxx |
| Choices | Array of Choice | 回复内容。 |
| Model | String | 功能名称 枚举值:
示例值:text2sql |
| RequestId | String | 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。本接口为流式响应接口,当请求成功时,RequestId 会被放在 HTTP 响应的 Header "X-TC-RequestId" 中。 |
4. 示例
示例1 智能生成检索语句-不开启深度思考-流式调用
此示例说明如何通过流式调用接口,以及如何传递历史上下文会话内容。注意:流式调用的请求域名需使用 cls.ai.tencentcloudapi.com。
输入示例
POST / HTTP/1.1
Host: cls.ai.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: ChatCompletions
<公共请求参数>
{
"Model": "text2sql",
"Messages": [
{
"Role": "user",
"Content": "状态码200, 统计日志条数"
},
{
"Role": "assistant",
"Content": "根据您的需求\"状态码200, 统计日志条数\",我分析出这是一个检索分析需求,需要检索状态码为200的日志,并统计日志条数。\n\n根据Nginx日志主题的字段配置,`status`字段是long类型且开启了统计状态。以下是生成的CQL语句:\n\n\\`\\`\\`sql\nstatus:200 | SELECT count(*) AS log_count\n\\`\\`\\`\n\n**解释说明:**\n1. **检索条件**:`status:200` - 检索状态码为200的日志\n2. **SQL语句**:`SELECT count(*) AS log_count` - 统计符合条件的日志条数\n3. **校验结果**:校验语句通过\n\n由于这是一个统计查询,需要使用管道符`|`将检索条件和SQL分析语句连接起来。语句使用了`status:200`作为检索条件,然后通过`count(*)`函数统计日志条数。"
},
{
"Content": "再统计5xx的",
"Role": "user"
}
],
"Stream": true,
"Metadata": [
{
"Key": "topic_id",
"Value": "xxxxxxxx-xxxx"
},
{
"Key": "topic_region",
"Value": "ap-guangzhou"
}
]
}
输出示例
id: 1
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"根据","Role":"assistant","ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103178,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 2
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"您的需求\"","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103178,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 3
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"再统计5","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103178,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 4
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"xx的\",","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103178,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 5
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"这是","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 6
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"要","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 7
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"统计HTTP","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 8
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"状态码为","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 9
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"5xx(","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 10
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"服务器错误)","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 11
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"的日志条","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 12
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"数。\n\n","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 13
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"根据日志主题","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 14
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"字段","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 15
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"列表,`","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 16
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"status`","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 17
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"字段是long","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 18
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"类型且开启了","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 19
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"统计状态。","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 20
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"以下是生成的","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 21
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"CQL语句","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 22
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":":\n\n\`\`\`sql","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 23
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"\nstatus","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 24
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":">=500 AND","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 25
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" status<=","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 26
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"599 |","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 27
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" SELECT count(*)","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 28
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" AS log","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 29
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"_count\n\`\`\`\n\n","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 30
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"**解释说明","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 31
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":":**\n1","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 32
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":". **检索","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 33
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"条件**:","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 34
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"`status>=","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 35
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"500 AND status","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 36
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"<=599`","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 37
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" - 检索","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 38
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"状态码在","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 39
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"500-","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 40
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"599之间的","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 41
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"日志(5","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 42
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"xx服务器","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 43
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"错误)\n2","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 44
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":". **","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 45
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"SQL语句**","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 46
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":":`SELECT","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 47
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" count(*) AS","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 48
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" log_count`","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 49
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" - 统计","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 50
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"符合条件的日志条","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 51
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"数\n3","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 52
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":". **校验","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 53
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"结果**:","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 54
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"校验语句","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 55
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"通过\n\n","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 56
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"该","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 57
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"语句使用了","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 58
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"数值","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 59
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"范围检索","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 60
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"条件","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 61
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"`status>=","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 62
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"500 AND status","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 63
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"<=599`","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 64
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"来匹配","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 65
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"所有","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 66
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"5xx状态","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 67
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"码,","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 68
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"然后统计","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 69
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"满足","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 70
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"条件的日志数量","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 71
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"。","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}
id: 72
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":null,"Role":null,"ReasoningContent":null},"Index":0,"FinishReason":"stop"}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{"PromptTokens":12482,"CompletionTokens":175,"TotalTokens":12657}}
示例2 智能生成检索语句-开启深度思考-非流式调用
此示例说明如何通过非流式调用接口。
输入示例
POST / HTTP/1.1
Host: cls.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: ChatCompletions
<公共请求参数>
{
"Messages": [
{
"Content": "状态码200, 统计日志条数",
"Role": "user"
}
],
"Model": "text2sql-reasoning",
"Metadata": [
{
"Key": "topic_region",
"Value": "ap-guangzhou"
},
{
"Key": "topic_id",
"Value": "xxxxxxxx-xxxx"
}
]
}
输出示例
{
"Response": {
"RequestId": "xxxxxxxx-xxxx",
"Id": "xxxxxxxx-xxxx",
"Created": 1775102996,
"Model": "text2sql-reasoning",
"Choices": [
{
"FinishReason": "stop",
"Message": {
"Role": "assistant",
"Content": "\n\`\`\`sql\nstatus:200 | SELECT count(*) AS \"日志条数\"\n\`\`\`\n\n### 解释说明:\n1. **检索条件**:`status:200`\n - 使用键值检索语法过滤状态码为200的日志\n - `status`字段在索引配置中已开启统计(状态为1),可直接使用\n\n2. **分析语句**:`SELECT count(*) AS \"日志条数\"`\n - 使用聚合函数`count(*)`统计符合条件的日志条数\n - 字段别名使用双引号包裹(包含中文)\n\n3. **注意事项**:\n - 该语句统计的是当前查询时间范围内的日志条数\n - 如需调整时间范围,请在控制台右侧时间选择器修改\n - `status`字段为long类型,支持精确数值检索\n\n### 校验结果:\n\`\`\`json\n{\n \"status\": \"success\",\n \"result\": {\n \"日志条数\": 15234\n }\n}\n\`\`\`",
"ReasoningContent": "\n我们已知日志主题索引配置字段列表,其中包含字段:status:long::1,表示status字段是long类型,开启统计。\n 需求是:状态码200, 统计日志条数。\n 根据规则,纯统计需求应使用检索分析格式:[检索条件] | [SQL语句]\n 检索条件:状态码200,即status:200\n SQL语句:统计日志条数,即SELECT count(*) AS log_count\n\n 注意:由于status字段在索引配置中已开启统计,可以直接使用。\n\n 输出CQL语句:`status:200 | SELECT count(*) AS log_count`\n\n 解释说明:检索条件为status:200,然后使用SQL统计日志条数。\n\n 另外,由于需求中指定了状态码200,我们不需要考虑时间范围,因为用户可以在界面选择时间范围。\n\n 校验:我们可以模拟校验,假设有status字段且值为200的日志,则统计其数量。如果日志中没有status字段或没有值为200的日志,则返回0。\n\n 由于我们使用了已开启统计的字段,所以不会出现字段未开启统计的问题。\n\n 因此,最终输出如下:",
"ToolCalls": []
},
"Index": 0
}
],
"Usage": {
"PromptTokens": 11262,
"CompletionTokens": 448,
"TotalTokens": 11710
}
}
}
5. 开发者资源
腾讯云 API 平台
腾讯云 API 平台 是综合 API 文档、错误码、API Explorer 及 SDK 等资源的统一查询平台,方便您从同一入口查询及使用腾讯云提供的所有 API 服务。
API Inspector
用户可通过 API Inspector 查看控制台每一步操作关联的 API 调用情况,并自动生成各语言版本的 API 代码,也可前往 API Explorer 进行在线调试。
SDK
云 API 3.0 提供了配套的开发工具集(SDK),支持多种编程语言,能更方便的调用 API。
- Tencent Cloud SDK 3.0 for Python: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for Java: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for PHP: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for Go: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for Node.js: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for .NET: CNB, GitHub, Gitee
命令行工具
6. 错误码
以下仅列出了接口业务逻辑相关的错误码,其他错误码详见 公共错误码。
| 错误码 | 描述 |
|---|---|
| FailedOperation.Timeout | 操作超时 |
| ResourceNotFound.TopicNotExist | 日志主题不存在。 |