Files
docker-configs/discord_bot/test_claude_code.py
Will Song 568dcc45e4 Fix router failover and add Discord bot
- Remove duplicate claude_api provider to fix automatic failover
- Enhance error detection with HTTP status codes and more indicators
- Add comprehensive README documentation with manual switching
- Implement Discord bot with Claude Code CLI integration
- Support /terminal and /claude commands with AI-powered responses

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-16 21:35:52 -05:00

51 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Claude Code CLI 测试脚本
"""
import asyncio
import sys
from pathlib import Path
# 添加项目路径
sys.path.append(str(Path(__file__).parent))
from utils.claude_code_client import ClaudeCodeClient
import logging
# 配置日志
logging.basicConfig(level=logging.INFO)
async def test_claude_code_cli():
"""测试Claude Code CLI集成"""
print("🧪 测试Claude Code CLI集成...")
try:
# 初始化Claude Code CLI客户端
claude_code_client = ClaudeCodeClient("/home/will/docker")
# 测试基础对话
print("\n🔧 测试Claude Code CLI对话...")
response = await claude_code_client.ask_claude("你好,请简单介绍一下你的功能")
print(f"对话测试结果:\n{response}\n")
# 测试命令解释
print("🔧 测试命令解释功能...")
test_commands = [
"ls", # 直接shell命令
"docker ps", # Docker命令
"查看当前目录文件", # 自然语言
"查看Docker容器状态", # 自然语言
"启动nginx容器", # 复杂自然语言
]
for cmd in test_commands:
print(f"\n 测试命令: {cmd}")
result = await claude_code_client.run_claude_command(cmd)
print(f" 执行结果: {result[:200]}...")
except Exception as e:
print(f"❌ 测试失败: {e}")
if __name__ == "__main__":
asyncio.run(test_claude_code_cli())