feat: adds scores to Feedback node

This commit is contained in:
hajdul88 2025-08-19 13:36:22 +02:00
parent 4e31ae7ffc
commit c6ec22a5a0
2 changed files with 8 additions and 4 deletions

View file

@ -28,7 +28,7 @@ class UserQAFeedback(BaseFeedback):
async def add_feedback(self, feedback_text: str) -> List[str]:
feedback_sentiment = await LLMGateway.acreate_structured_output(
text_input=feedback_text,
system_prompt="You are a sentiment analysis assistant. For each piece of user feedback you receive, return exactly one of: Positive, Negative, or Neutral classification",
system_prompt="You are a sentiment analysis assistant. For each piece of user feedback you receive, return exactly one of: Positive, Negative, or Neutral classification and a corresponding score from -5 (worst negative) to 5 (best positive)",
response_model=UserFeedbackEvaluation,
)
@ -43,6 +43,7 @@ class UserQAFeedback(BaseFeedback):
id=feedback_id,
feedback=feedback_text,
sentiment=feedback_sentiment.evaluation.value,
score=feedback_sentiment.score,
belongs_to_set=feedbacks_node_set,
)

View file

@ -2,8 +2,7 @@ from typing import Optional
from cognee.infrastructure.engine.models.DataPoint import DataPoint
from cognee.modules.engine.models.node_set import NodeSet
from enum import Enum
from pydantic import BaseModel, ValidationError
from pydantic import BaseModel, Field, confloat
class CogneeUserInteraction(DataPoint):
"""User - Cognee interaction"""
@ -19,6 +18,7 @@ class CogneeUserFeedback(DataPoint):
feedback: str
sentiment: str
score: float
belongs_to_set: Optional[NodeSet] = None
@ -32,5 +32,8 @@ class UserFeedbackSentiment(str, Enum):
class UserFeedbackEvaluation(BaseModel):
"""User - User feedback evaluation"""
score: confloat(ge=-5, le=5) = Field(
...,
description="Sentiment score from -5 (negative) to +5 (positive)"
)
evaluation: UserFeedbackSentiment