| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- """
- AI Trace监控模块
- 提供AI模型链路监控功能
- """
- from langfuse import Langfuse,observe
- from typing import Dict, List
- # 初始化Langfuse客户端
- lf = Langfuse(
- secret_key="sk-lf-034de024-bade-4d75-9911-319aa1e4ed30",
- public_key="pk-lf-d55b3b61-e183-42d2-9b8e-febb198dfe9d",
- base_url="http://127.0.0.1:3000/",
- )
- class TraceMonitor:
- """AI模型链路监控器"""
- def __init__(self):
- self.client = lf
- @observe
- def trace_inference(self, model_name: str, prompt: str, response: str):
- """
- 跟踪模型推理过程
- Args:
- model_name: 模型名称
- prompt: 输入提示
- response: 模型响应
- """
- pass
- def log_event(self, event_name: str, data: Dict):
- """
- 记录事件
- Args:
- event_name: 事件名称
- data: 事件数据
- """
- pass
- # 创建全局实例
- trace_monitor = TraceMonitor()
- # 导出Langfuse客户端以便兼容现有代码
- __all__ = ["TraceMonitor", "trace_monitor", "lf"]
|