Skip to content

feat: add cls sse example#275

Open
ianhu92 wants to merge 1 commit intoTencentCloud:masterfrom
ianhu92:feat/cls-sse-example
Open

feat: add cls sse example#275
ianhu92 wants to merge 1 commit intoTencentCloud:masterfrom
ianhu92:feat/cls-sse-example

Conversation

@ianhu92
Copy link
Copy Markdown

@ianhu92 ianhu92 commented Apr 3, 2026

测试脚本:

cat examples/cls/v20201016/run.sh
#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/../../.." && pwd)"
BUILD_DIR=/tmp/cls-build

DEPS=\
$HOME/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:\
$HOME/.m2/repository/com/squareup/okio/okio/1.15.0/okio-1.15.0.jar:\
$HOME/.m2/repository/com/squareup/okhttp3/okhttp/3.12.13/okhttp-3.12.13.jar:\
$HOME/.m2/repository/com/squareup/okhttp3/logging-interceptor/3.12.13/logging-interceptor-3.12.13.jar:\
$HOME/.m2/repository/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar:\
$HOME/.m2/repository/org/ini4j/ini4j/0.5.4/ini4j-0.5.4.jar

echo "==> 编译 SDK..."
mkdir -p "$BUILD_DIR"
find "$PROJECT_DIR/src/main/java" -name "*.java" > /tmp/sdk-sources.txt
javac -nowarn -source 8 -target 8 -cp "$DEPS" -d "$BUILD_DIR" @/tmp/sdk-sources.txt 2>/dev/null

echo "==> 编译示例..."
javac -nowarn -source 8 -target 8 \
  -cp "$DEPS:$BUILD_DIR" \
  -d "$BUILD_DIR" \
  "$SCRIPT_DIR/ChatCompletions.java" 2>/dev/null

echo "==> 运行示例..."
java -cp "$DEPS:$BUILD_DIR" cls.v20201016.ChatCompletions

exit 0

正常响应:

./examples/cls/v20201016/run.sh
==> 编译 SDK...
==> 编译示例...
==> 运行示例...
\```sql
status:200 | SELECT count(*) AS log_count
\```

**Verification Result:** The query syntax check passed successfully.

**Brief Explanation:** This CQL statement retrieves logs with HTTP status code 200 from the Nginx access logs and counts the total number of these successful request logs. The `status:200` filter in the search condition selects only logs where the status field equals 200, and the SQL `count(*)` function calculates the total number of matching log entries.
[流式] 完成,开始非流式调用...
思考过程:
[非流式] 回复内容:
\```sql
status:200 | SELECT count(*) AS log_count
\```

**Verification Result:** The query syntax is valid.

**Explanation:** 
1. **Search Condition:** `status:200` retrieves all logs where the status field equals 200.
2. **Analytics:** `SELECT count(*) AS log_count` counts the number of logs that match the search condition and labels the result as "log_count".
3. The field "status" is in the log topic's index configuration with long data type and statistics enabled.

This CQL statement meets your requirement to count logs with status code 200.

错误处理:

./examples/cls/v20201016/run.sh
==> 编译 SDK...
==> 编译示例...
==> 运行示例...

[流式] error {"Code":"ResourceNotFound.TopicNotExist","Message":"topic_id \"xxxxxxxx-xxxx\" does not exist."}

[流式] 完成,开始非流式调用...
[TencentCloudSDKException]code: ResourceNotFound.TopicNotExist message:topic_id "xxxxxxxx-xxxx" does not exist. requestId:dd6e7172-12fe-4416-ba36-8d3567031d04
        at com.tencentcloudapi.common.AbstractClient.processResponseJson(AbstractClient.java:638)
        at com.tencentcloudapi.common.AbstractClient.internalRequest(AbstractClient.java:559)
        at com.tencentcloudapi.cls.v20201016.ClsClient.ChatCompletions(ClsClient.java:84)
        at cls.v20201016.ChatCompletions.main(ChatCompletions.java:104)

@ianhu92 ianhu92 force-pushed the feat/cls-sse-example branch from cbbf0bd to 8e0b851 Compare April 3, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant