mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-24 21:36:06 +00:00
feat(wecom): add user feedback support for WeChat Work AI Bot
This commit implements user feedback functionality (like/dislike) for WeChat Work AI Bot conversations, including: Backend changes: - Add feedback_id and stream_id fields to WecomBotEvent - Implement feedback event handling in WecomBotClient (api.py) - Add StreamSessionManager._feedback_index for feedback_id lookup - Add on_feedback decorator for custom feedback handlers - Create MonitoringFeedback entity for database persistence - Add dbm025 migration for monitoring_feedback table - Implement FeedbackMonitor helper class - Update all platform adapters with ap parameter support - Update botmgr to pass bot_info for monitoring context Frontend changes: - Add FeedbackCard and FeedbackList components - Add useFeedbackData hook for feedback data fetching - Add feedback tab to monitoring page - Add feedback types and interfaces - Add i18n translations (zh-Hans, en-US) Other changes: - Update Dockerfile with Chinese mirror for faster builds - Update docker-compose.yaml with network configuration - Update .gitignore for docker data and backup files Note: Known issues that need future improvement: - feedback_type=3 (cancel) is recorded but not properly handled - Duplicate feedback records are not deduplicated
This commit is contained in:
@@ -353,3 +353,62 @@ class LLMCallMonitor:
|
||||
)
|
||||
|
||||
return False # Don't suppress exceptions
|
||||
|
||||
|
||||
class FeedbackMonitor:
|
||||
"""Helper for recording user feedback from AI Bot conversations"""
|
||||
|
||||
@staticmethod
|
||||
async def record_feedback(
|
||||
ap: app.Application,
|
||||
feedback_id: str,
|
||||
feedback_type: int,
|
||||
feedback_content: str | None = None,
|
||||
inaccurate_reasons: list[str] | None = None,
|
||||
bot_id: str | None = None,
|
||||
bot_name: str | None = None,
|
||||
pipeline_id: str | None = None,
|
||||
pipeline_name: str | None = None,
|
||||
session_id: str | None = None,
|
||||
message_id: str | None = None,
|
||||
stream_id: str | None = None,
|
||||
user_id: str | None = None,
|
||||
platform: str = 'wecom',
|
||||
):
|
||||
"""Record user feedback (like/dislike) from AI Bot conversation.
|
||||
|
||||
Args:
|
||||
ap: Application instance
|
||||
feedback_id: Unique feedback identifier from platform
|
||||
feedback_type: 1 = like, 2 = dislike
|
||||
feedback_content: Optional user feedback text
|
||||
inaccurate_reasons: List of reasons for inaccurate response
|
||||
bot_id: Bot UUID
|
||||
bot_name: Bot name
|
||||
pipeline_id: Pipeline UUID
|
||||
pipeline_name: Pipeline name
|
||||
session_id: Session ID
|
||||
message_id: Message ID
|
||||
stream_id: Stream ID
|
||||
user_id: User ID
|
||||
platform: Platform name (default: wecom)
|
||||
"""
|
||||
try:
|
||||
await ap.monitoring_service.record_feedback(
|
||||
feedback_id=feedback_id,
|
||||
feedback_type=feedback_type,
|
||||
feedback_content=feedback_content,
|
||||
inaccurate_reasons=inaccurate_reasons,
|
||||
bot_id=bot_id,
|
||||
bot_name=bot_name,
|
||||
pipeline_id=pipeline_id,
|
||||
pipeline_name=pipeline_name,
|
||||
session_id=session_id,
|
||||
message_id=message_id,
|
||||
stream_id=stream_id,
|
||||
user_id=user_id,
|
||||
platform=platform,
|
||||
)
|
||||
ap.logger.info(f'Recorded feedback: feedback_id={feedback_id}, type={feedback_type}')
|
||||
except Exception as e:
|
||||
ap.logger.error(f'Failed to record feedback: {e}')
|
||||
|
||||
Reference in New Issue
Block a user