recordPromptEvent 记录提示词事件
(span telemetry.Span, req *ModelRequest)
| 259 | |
| 260 | // recordPromptEvent 记录提示词事件 |
| 261 | func (m *TelemetryMiddleware) recordPromptEvent(span telemetry.Span, req *ModelRequest) { |
| 262 | attrs := []telemetry.Attribute{ |
| 263 | telemetry.Int("message_count", len(req.Messages)), |
| 264 | } |
| 265 | |
| 266 | // 添加系统提示词长度(不记录内容) |
| 267 | if req.SystemPrompt != "" { |
| 268 | attrs = append(attrs, telemetry.Int("system_prompt_length", len(req.SystemPrompt))) |
| 269 | } |
| 270 | |
| 271 | // 添加工具数量 |
| 272 | if len(req.Tools) > 0 { |
| 273 | attrs = append(attrs, telemetry.Int("tool_count", len(req.Tools))) |
| 274 | } |
| 275 | |
| 276 | span.AddEvent(genai.EventPrompt, attrs...) |
| 277 | } |
| 278 | |
| 279 | // recordCompletionEvent 记录完成事件 |
| 280 | func (m *TelemetryMiddleware) recordCompletionEvent(span telemetry.Span, resp *ModelResponse) { |
no test coverage detected