chore: initial commit
This commit is contained in:
29
test_agent_response.py
Normal file
29
test_agent_response.py
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import os
|
||||
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
|
||||
|
||||
async def test_agent():
|
||||
# 设置环境
|
||||
os.environ['ANTHROPIC_API_KEY'] = os.environ.get('ANTHROPIC_AUTH_TOKEN', '')
|
||||
|
||||
# 配置选项
|
||||
options = ClaudeAgentOptions(
|
||||
system_prompt="你是一个友好的助手,请用中文回复。"
|
||||
)
|
||||
|
||||
# 测试对话
|
||||
async with ClaudeSDKClient(options=options) as client:
|
||||
print('发送查询...')
|
||||
await client.query('你好,1+1等于几?请简短回复。')
|
||||
|
||||
print('接收响应...')
|
||||
full_response = []
|
||||
async for message in client.receive_response():
|
||||
print(f'收到: {message}')
|
||||
full_response.append(str(message))
|
||||
|
||||
print(f'\n完整响应: {"".join(full_response)}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(test_agent())
|
||||
Reference in New Issue
Block a user