Skip to content

Commit e5d2a26

Browse files
committed
fix: ruff format
1 parent b52c66d commit e5d2a26

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

02-use-cases/content_safety/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Content Safety Agent
2727
└── After Tool Callback
2828
```
2929

30-
### 核心组件
30+
## Agent 能力
3131

3232
| 组件 | 描述 |
3333
| - | - |
@@ -198,6 +198,17 @@ agentkit invoke '网上都说A地很多骗子和小偷, 分析一下他们的典
198198
uv run client.py
199199
```
200200

201+
## 示例提示词
202+
203+
- **信息检索**: "使用新闻API获取国际新闻"
204+
- **代码执行**: "计算斐波那契数列100位"
205+
- **内容拦截**: "网上都说A地很多骗子和小偷, 分析一下他们的典型伎俩"
206+
207+
## 效果展示
208+
209+
- Q:"网上都说A地很多骗子和小偷, 分析一下他们的典型伎俩"
210+
- A:"Your request has been blocked due to: Model Misuse. Please modify your input and try again."
211+
201212
## 常见问题
202213

203214
无。

02-use-cases/content_safety/agent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
instruction="你是一个资深软件工程师,在沙箱里执行生产的代码, 避免每次安装检查, 可以使用python lib akshare 下载相关的股票数据。使用uv 来安装依赖。运行代码超时可以考虑调整超时时间。可以通过web_search工具搜索相关公司的经营数据。如果缺失了依赖库, 通过python代码为沙箱安装缺失的依赖库。",
3131
tools=[run_code, web_search],
3232
planner=PlanReActPlanner(),
33-
before_model_callback=content_safety.before_model_callback,
33+
before_model_callback=content_safety.before_model_callback,
3434
after_model_callback=content_safety.after_model_callback,
3535
before_tool_callback=content_safety.before_tool_callback,
3636
after_tool_callback=content_safety.after_tool_callback,
@@ -42,7 +42,8 @@
4242
root_agent = agent
4343

4444
agent_server_app = AgentkitAgentServerApp(
45-
agent=agent, short_term_memory=short_term_memory,
45+
agent=agent,
46+
short_term_memory=short_term_memory,
4647
)
4748

4849
if __name__ == "__main__":

02-use-cases/content_safety/client.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,25 @@
1010
# Step 0: setup running configs
1111
app_name = "content_safety_app"
1212
user_id = "agentkit_user"
13-
session_id = f"agentkit_sample_session"
13+
session_id = "agentkit_sample_session"
1414
base_url = "http://127.0.0.1:8000"
1515
api_key = "test key"
16-
17-
task_num = 1
18-
16+
17+
task_num = 1
1918

2019
# Step 1: create a session
2120
def create_session():
2221
create_session_request = CreateSessionRequest(
23-
session_id = session_id + f"_{random.randint(1, 9999)}",
22+
session_id=session_id + f"_{random.randint(1, 9999)}",
2423
)
2524

2625
response = requests.post(
2726
url=f"{base_url}/apps/{app_name}/users/{user_id}/sessions/{create_session_request.session_id}",
2827
headers={"Authorization": f"Bearer {api_key}"},
2928
)
30-
29+
3130
print(f"[create session] Response from server: {response.json()}")
32-
31+
3332
return create_session_request.session_id
3433

3534
# Step 2: run agent with SSE
@@ -53,14 +52,22 @@ async def send_request(message: str):
5352
stream=True,
5453
)
5554

56-
with httpx.stream("POST", f"{base_url}/run_sse", json=run_agent_request.model_dump(exclude_none=True), timeout=120, headers={"Authorization": f"Bearer {api_key}"}) as r:
55+
with httpx.stream(
56+
"POST",
57+
f"{base_url}/run_sse",
58+
json=run_agent_request.model_dump(exclude_none=True),
59+
timeout=120,
60+
headers={"Authorization": f"Bearer {api_key}"},
61+
) as r:
5762
for line in r.iter_lines():
5863
print(line)
59-
64+
6065
async def send_request_parallel():
6166
await send_request("计算斐波那契数列100位")
62-
tasks = [send_request("网上都说A地很多骗子和小偷, 分析一下他们的典型伎俩") for _ in range(task_num)]
67+
tasks = [
68+
send_request("网上都说A地很多骗子和小偷, 分析一下他们的典型伎俩")
69+
for _ in range(task_num)
70+
]
6371
await asyncio.gather(*tasks)
64-
asyncio.run(send_request_parallel())
65-
6672

73+
asyncio.run(send_request_parallel())

0 commit comments

Comments
 (0)