Expand description
遥测与反馈模块:提供可选的、应用可控的用户反馈收集机制。
§Telemetry and Feedback Module
This module provides optional, application-controlled telemetry and feedback collection capabilities. Privacy is paramount - the runtime MUST NOT force telemetry collection.
§Overview
The feedback system enables:
- Collection of user preferences (thumbs up/down, ratings)
- Tracking of choice selections in multi-candidate responses
- Recording corrections and regeneration requests
- Custom feedback integration with external systems
§Design Principles
- Opt-in Only: No telemetry is collected unless explicitly configured
- Application-Controlled: The application decides what to collect and where to send
- Stable Linkage:
client_request_idprovides correlation across events - Pluggable Sinks: Implement
FeedbackSinkfor custom destinations
§Key Components
| Component | Description |
|---|---|
FeedbackEvent | Typed feedback event enum |
FeedbackSink | Trait for feedback destinations |
NoopFeedbackSink | Default no-op sink (no collection) |
InMemoryFeedbackSink | In-memory sink for testing |
ConsoleFeedbackSink | Console logging sink for debugging |
CompositeFeedbackSink | Multi-destination composite sink |
§Feedback Types
| Type | Description |
|---|---|
ThumbsFeedback | Simple positive/negative feedback |
RatingFeedback | Numeric rating (e.g., 1-5 stars) |
ChoiceSelectionFeedback | Multi-candidate selection tracking |
CorrectionFeedback | User corrections to model output |
RegenerateFeedback | Regeneration request tracking |
TextFeedback | Free-form text feedback |
§Example
use ai_lib_rust::telemetry::{FeedbackEvent, ThumbsFeedback, set_feedback_sink, InMemoryFeedbackSink};
use std::sync::Arc;
// Configure feedback collection (opt-in)
let sink = Arc::new(InMemoryFeedbackSink::new(100));
set_feedback_sink(sink.clone());
// Record feedback
let feedback = ThumbsFeedback::thumbs_up("req-123")
.with_reason("Helpful response");
// report_feedback(FeedbackEvent::Thumbs(feedback)).await?;Structs§
- Choice
Selection Feedback - Feedback for multi-candidate selection.
- Composite
Feedback Sink - Composite sink for multiple destinations.
- Console
Feedback Sink - Console sink for debugging.
- Correction
Feedback - Correction feedback.
- InMemory
Feedback Sink - In-memory sink for testing.
- Noop
Feedback Sink - No-op sink.
- Rating
Feedback - Rating feedback (e.g., 1-5 stars).
- Regenerate
Feedback - Regeneration feedback.
- Stop
Feedback - Stop generation feedback.
- Text
Feedback - Free-form text feedback.
- Thumbs
Feedback - Thumbs up/down feedback.
Enums§
- Feedback
Event - Typed feedback events (extensible).
Traits§
- Feedback
Sink - Feedback sink trait.