Skip to content

Commit 2336b4f

Browse files
optimized vikigndb case
1 parent cb8dc86 commit 2336b4f

File tree

3 files changed

+43
-33
lines changed

3 files changed

+43
-33
lines changed

02-use-cases/beginner/vikingdb/README.md

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ LLM 生成回答
4444

4545
```python
4646
# 准备知识源
47-
with open("/tmp/tech.txt", "w") as f:
48-
f.write("Python: programming language\nJavaScript: web development")
49-
with open("/tmp/products.txt", "w") as f:
50-
f.write("Laptop: $1200\nPhone: $800\nTablet: $600")
47+
with open("/tmp/product_info.txt", "w") as f:
48+
f.write("产品清单及价格:\n1. 高性能笔记本电脑 (Laptop Pro) - 价格:8999元...")
49+
with open("/tmp/service_policy.txt", "w") as f:
50+
f.write("售后服务政策:\n1. 质保期:所有电子产品提供1年免费质保...")
5151

5252
# 创建知识库
5353
kb = KnowledgeBase(backend="viking", app_name="test_app")
54-
kb.add_from_files(files=["/tmp/tech.txt", "/tmp/products.txt"])
54+
kb.add_from_files(files=["/tmp/product_info.txt", "/tmp/service_policy.txt"])
5555
```
5656

5757
**Agent 配置**[agent.py](https://github.com/volcengine/agentkit-samples/blob/main/02-use-cases/beginner/vikingdb/agent.py#L31-L36)):
@@ -138,8 +138,6 @@ export MODEL_AGENT_NAME=doubao-seed-1-6-251015
138138
# 火山引擎访问凭证(必需)
139139
export VOLCENGINE_ACCESS_KEY=<Your Access Key>
140140
export VOLCENGINE_SECRET_KEY=<Your Secret Key>
141-
# bucket需要用来上传本地文件,进而将文件从tos导入到知识库中
142-
export DATABASE_TOS_BUCKET=agentkit-platform-{{your_account_id}}
143141
```
144142

145143
### 调试方法
@@ -198,14 +196,18 @@ uv run agent.py
198196
```bash
199197
# 进入到vikingdb目录
200198

201-
# 配置部署参数
202-
agentkit config
199+
# 配置部署参数,DATABASE_TOS_BUCKET环境变量需要传入到Agent中,用来上传本地文件到TOS,进而将文件从TOS导入到知识库中
200+
agentkit config \
201+
--agent_name vikingdb_agnet \
202+
--entry_point 'agent.py' \
203+
--runtime_envs DATABASE_TOS_BUCKET=agentkit-platform-2107625663 \
204+
--launch_type cloud
203205

204206
# 启动云端服务
205207
agentkit launch
206208

207209
# 测试部署的 Agent
208-
agentkit invoke 'What is Python?'
210+
agentkit invoke '高性能笔记本电脑PRO的价钱是多少'
209211

210212
# 或使用 client.py 连接云端服务
211213
# 需要编辑 client.py,将其中的第 14 行和第 15 行的 base_url 和 api_key 修改为 agentkit.yaml 中生成的 runtime_endpoint 和 runtime_apikey 字段
@@ -215,46 +217,46 @@ uv run client.py
215217

216218
## 示例提示词
217219

218-
### 技术知识查询
220+
### 产品信息查询
219221

220-
**基于 tech.txt 的检索回答**
222+
**基于 product_info.txt 的检索回答**
221223

222224
```text
223-
用户:What is Python?
224-
Agent:Python is a programming language.
225+
用户:高性能笔记本Pro的价钱是多少?
226+
Agent:根据产品清单,高性能笔记本电脑 (Laptop Pro) 的价格是 8999 元。
225227
226-
用户:What is JavaScript used for?
227-
Agent:JavaScript is primarily used for web development.
228+
用户:这里最便宜的产品是什么?
229+
Agent:最便宜的产品是平板电脑 (Tablet Air),价格为 2999 元。
228230
```
229231

230-
### 产品价格查询
232+
### 售后服务查询
231233

232-
**基于 products.txt 的数据检索**
234+
**基于 service_policy.txt 的数据检索**
233235

234236
```text
235-
用户:Which is more expensive, Laptop or Phone?
236-
Agent:Laptop is more expensive. It costs $1200, while Phone costs $800.
237+
用户:你们的退换货政策是怎样的?
238+
Agent:根据售后服务政策,购买后 7 天内支持无理由退货,15 天内如有质量问题可以换货。
237239
238-
用户:What's the cheapest product?
239-
Agent:The cheapest product is Tablet at $600.
240+
用户:笔记本电脑保修多久?
241+
Agent:所有电子产品均提供 1 年免费质保。
240242
```
241243

242244
### 上下文关联查询
243245

244246
**复用前文上下文的连续问答:**
245247

246248
```text
247-
用户:What's the price difference with the cheapest one?
248-
Agent:The Laptop is $600 more expensive than the cheapest product (Tablet).
249+
用户:那 SmartPhone X 呢?
250+
Agent:SmartPhone X 的价格是 4999 元。
249251
```
250252

251253
### 复合查询
252254

253255
**跨文档的综合查询:**
254256

255257
```text
256-
用户:I want to learn Python, do you have any related products?
257-
Agent:Based on our documents, Python is a programming language. We have a Laptop ($1200) which would be suitable for programming.
258+
用户:我想买一台用来办公和娱乐的设备,有什么推荐并告诉我售后保障?
259+
Agent:推荐您使用平板电脑 (Tablet Air),它轻薄便携,适合办公娱乐,价格为 2999 元。售后方面,我们提供 1 年免费质保,且支持 7 天无理由退货。
258260
```
259261

260262
## 效果展示

02-use-cases/beginner/vikingdb/agent.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,30 @@
1717
from veadk import Agent, Runner
1818
from veadk.knowledgebase.knowledgebase import KnowledgeBase
1919
from veadk.memory.short_term_memory import ShortTermMemory
20+
import os
2021

2122
# 准备多个知识源
22-
with open("/tmp/tech.txt", "w") as f:
23-
f.write("Python: programming language\nJavaScript: web development")
24-
with open("/tmp/products.txt", "w") as f:
25-
f.write("Laptop: $1200\nPhone: $800\nTablet: $600")
23+
with open("/tmp/product_info.txt", "w") as f:
24+
f.write(
25+
"产品清单及价格:\n1. 高性能笔记本电脑 (Laptop Pro) - 价格:8999元\n - 适用于专业设计和游戏,配备最新显卡。\n2. 智能手机 (SmartPhone X) - 价格:4999元\n - 5G全网通,超长续航。\n3. 平板电脑 (Tablet Air) - 价格:2999元\n - 轻薄便携,适合办公娱乐。"
26+
)
27+
with open("/tmp/service_policy.txt", "w") as f:
28+
f.write(
29+
"售后服务政策:\n1. 质保期:所有电子产品提供1年免费质保。\n2. 退换货:购买后7天内无理由退货,15天内有质量问题换货。\n3. 客服支持:提供7x24小时在线客服咨询。"
30+
)
2631

2732
# 创建知识库
2833
kb = KnowledgeBase(backend="viking", app_name="test_app")
29-
kb.add_from_files(files=["/tmp/tech.txt", "/tmp/products.txt"])
34+
kb.add_from_files(
35+
files=["/tmp/product_info.txt", "/tmp/service_policy.txt"],
36+
tos_bucket_name=os.environ.get("DATABASE_TOS_BUCKET"),
37+
)
3038

3139
# 创建agent
3240
root_agent = Agent(
3341
name="test_agent",
3442
knowledgebase=kb,
35-
instruction="You are a helpful assistant. Be concise and friendly.",
43+
instruction="你是一个乐于助人的客服助手。你可以查阅知识库来回答关于产品类目、价格以及售后服务的问题。请根据知识库的内容准确回答。",
3644
)
3745

3846
# 运行

02-use-cases/beginner/vikingdb/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ async def send_request(message: str):
5353
print(line)
5454

5555
async def send_request_parallel():
56-
await send_request("What is Python?")
56+
await send_request("高性能笔记本Pro的价钱是多少")
5757

5858
asyncio.run(send_request_parallel())

0 commit comments

Comments
 (0)