refactor: 重构项目结构和文件组织
- 将文档文件移动到docs目录下分类存放 - 将测试文件移动到tests目录 - 将工具脚本移动到tools目录 - 更新README中的文件路径说明 - 删除重复和过时的文件 - 优化项目目录结构,提升可维护性
This commit is contained in:
90
tests/test_vertex_ai_setup.py
Normal file
90
tests/test_vertex_ai_setup.py
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试 Vertex AI 配置和连接
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from config.doppler_config import get_google_genai_config
|
||||
|
||||
def test_doppler_config():
|
||||
"""测试 Doppler 配置"""
|
||||
print("🔍 测试 Doppler 配置...")
|
||||
try:
|
||||
config = get_google_genai_config()
|
||||
print("✅ 成功读取 Google GenAI 配置")
|
||||
print(f" - API Key: {'已配置' if config.get('api_key') else '未配置'}")
|
||||
print(f" - Use Vertex AI: {config.get('use_vertex_ai', '未设置')}")
|
||||
print(f" - Project ID: {config.get('project_id', '未设置')}")
|
||||
print(f" - Location: {config.get('location', '未设置')}")
|
||||
print(f" - Memory Bank Enabled: {config.get('memory_bank_enabled', '未设置')}")
|
||||
return config
|
||||
except Exception as e:
|
||||
print(f"❌ 读取 Google GenAI 配置失败: {e}")
|
||||
return None
|
||||
|
||||
def test_environment_variables():
|
||||
"""测试环境变量"""
|
||||
print("\n🔍 测试环境变量...")
|
||||
adc_path = os.path.expanduser("~/.config/gcloud/application_default_credentials.json")
|
||||
if os.path.exists(adc_path):
|
||||
print("✅ 找到 Application Default Credentials 文件")
|
||||
else:
|
||||
print("❌ 未找到 Application Default Credentials 文件")
|
||||
|
||||
google_env_vars = [var for var in os.environ if var.startswith('GOOGLE_')]
|
||||
if google_env_vars:
|
||||
print("✅ 找到以下 Google 环境变量:")
|
||||
for var in google_env_vars:
|
||||
# 不显示敏感信息
|
||||
if 'KEY' in var or 'SECRET' in var or 'TOKEN' in var:
|
||||
print(f" - {var}: {'已设置' if os.environ.get(var) else '未设置'}")
|
||||
else:
|
||||
print(f" - {var}: {os.environ.get(var, '未设置')}")
|
||||
else:
|
||||
print("⚠️ 未找到 Google 环境变量")
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
print("🧪 Vertex AI 配置测试\n")
|
||||
|
||||
# 测试 Doppler 配置
|
||||
config = test_doppler_config()
|
||||
|
||||
# 测试环境变量
|
||||
test_environment_variables()
|
||||
|
||||
# 检查是否满足基本要求
|
||||
print("\n📋 配置检查摘要:")
|
||||
if config:
|
||||
project_id = config.get('project_id')
|
||||
api_key = config.get('api_key')
|
||||
|
||||
if project_id:
|
||||
print("✅ Google Cloud Project ID 已配置")
|
||||
else:
|
||||
print("❌ 未配置 Google Cloud Project ID")
|
||||
|
||||
if api_key:
|
||||
print("✅ Google API Key 已配置")
|
||||
else:
|
||||
print("❌ 未配置 Google API Key")
|
||||
|
||||
# 检查是否启用 Vertex AI
|
||||
use_vertex = config.get('use_vertex_ai', '').upper()
|
||||
if use_vertex == 'TRUE':
|
||||
print("✅ Vertex AI 已启用")
|
||||
else:
|
||||
print("❌ Vertex AI 未启用 (请检查 GOOGLE_GENAI_USE_VERTEXAI 环境变量)")
|
||||
|
||||
# 检查是否启用 Memory Bank
|
||||
memory_bank_enabled = config.get('memory_bank_enabled', '').upper()
|
||||
if memory_bank_enabled == 'TRUE':
|
||||
print("✅ Memory Bank 已启用")
|
||||
else:
|
||||
print("❌ Memory Bank 未启用 (请检查 VERTEX_MEMORY_BANK_ENABLED 环境变量)")
|
||||
else:
|
||||
print("❌ 无法读取配置,请检查 Doppler 配置")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
72
tests/test_vertex_memory_bank_function.py
Normal file
72
tests/test_vertex_memory_bank_function.py
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试 Vertex AI Memory Bank 功能
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加项目根目录到Python路径
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '.')))
|
||||
|
||||
from src.jixia.memory.factory import get_memory_backend
|
||||
|
||||
async def test_vertex_memory_bank():
|
||||
"""测试 Vertex Memory Bank 功能"""
|
||||
print("🧪 Vertex AI Memory Bank 功能测试\n")
|
||||
|
||||
try:
|
||||
# 获取 Vertex Memory Bank 后端
|
||||
print("🔍 正在获取 Vertex Memory Bank 后端...")
|
||||
memory_bank = get_memory_backend(prefer='vertex')
|
||||
print("✅ 成功获取 Vertex Memory Bank 后端\n")
|
||||
|
||||
# 测试创建记忆银行
|
||||
print("🔍 正在为吕洞宾创建记忆银行...")
|
||||
bank_id = await memory_bank.create_memory_bank("lvdongbin", "吕洞宾的记忆银行")
|
||||
print(f"✅ 成功为吕洞宾创建记忆银行: {bank_id}\n")
|
||||
|
||||
# 测试添加记忆
|
||||
print("🔍 正在为吕洞宾添加记忆...")
|
||||
memory_id = await memory_bank.add_memory(
|
||||
agent_name="lvdongbin",
|
||||
content="在讨论NVIDIA股票时,我倾向于使用DCF模型评估其内在价值,并关注其在AI领域的竞争优势。",
|
||||
memory_type="preference",
|
||||
debate_topic="NVIDIA投资分析",
|
||||
metadata={"confidence": "high"}
|
||||
)
|
||||
print(f"✅ 成功为吕洞宾添加记忆: {memory_id}\n")
|
||||
|
||||
# 测试搜索记忆
|
||||
print("🔍 正在搜索吕洞宾关于NVIDIA的记忆...")
|
||||
results = await memory_bank.search_memories(
|
||||
agent_name="lvdongbin",
|
||||
query="NVIDIA",
|
||||
memory_type="preference"
|
||||
)
|
||||
print(f"✅ 搜索完成,找到 {len(results)} 条相关记忆\n")
|
||||
|
||||
if results:
|
||||
print("🔍 搜索结果:")
|
||||
for i, result in enumerate(results, 1):
|
||||
print(f" {i}. {result['content']}")
|
||||
print(f" 相关性评分: {result['relevance_score']:.4f}\n")
|
||||
|
||||
# 测试获取上下文
|
||||
print("🔍 正在获取吕洞宾关于NVIDIA投资分析的上下文...")
|
||||
context = await memory_bank.get_agent_context("lvdongbin", "NVIDIA投资分析")
|
||||
print("✅ 成功获取上下文\n")
|
||||
print("🔍 上下文内容:")
|
||||
print(context)
|
||||
print("\n")
|
||||
|
||||
print("🎉 Vertex AI Memory Bank 功能测试完成!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 测试过程中发生错误: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(test_vertex_memory_bank())
|
||||
Reference in New Issue
Block a user