mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-09-17 10:06:18 +00:00
model.py imported its exceptions from the package __init__, which itself
imports model -- a cycle that only resolved because __init__ happens to
import exceptions first. Import them from the exceptions submodule
directly, matching service.py, so reordering __init__ can never break
collection.
Also update the two module docstrings that still pointed readers at the
deleted app/infra/ layout and the old deps.py wiring: adapters live in
app/adapters/{context}/ and wiring happens in the composition root,
app/composition.py::build_domain_services.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import uuid
|
|
from dataclasses import dataclass, field
|
|
from datetime import UTC, datetime
|
|
|
|
from deerflow.domain.feedback.exceptions import InvalidRatingError, InvalidTagError
|
|
|
|
VALID_RATINGS = (-1, 1)
|
|
|
|
# Language-neutral reason slugs for thumbs-down feedback. The UI translates
|
|
# them for display; storage and analytics only ever see the slug, so feedback
|
|
# submitted under different UI languages stays aggregatable.
|
|
VALID_FEEDBACK_TAGS = frozenset(
|
|
{
|
|
"incorrect",
|
|
"not_as_expected",
|
|
"slow",
|
|
"style_tone",
|
|
"safety_legal",
|
|
"other",
|
|
}
|
|
)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Feedback:
|
|
"""A user's rating of a single run: at most one per (thread, run, user).
|
|
|
|
Single-entity aggregate. ``tags`` carry optional thumbs-down reason
|
|
slugs from the feedback dialog.
|
|
"""
|
|
|
|
feedback_id: str
|
|
run_id: str
|
|
thread_id: str
|
|
rating: int
|
|
user_id: str | None = None
|
|
comment: str | None = None
|
|
tags: tuple[str, ...] = ()
|
|
created_at: datetime = field(default_factory=lambda: datetime.now(UTC))
|
|
|
|
def __post_init__(self):
|
|
if self.rating not in VALID_RATINGS:
|
|
raise InvalidRatingError(f"rating must be +1 or -1, got {self.rating}")
|
|
unknown = set(self.tags) - VALID_FEEDBACK_TAGS
|
|
if unknown:
|
|
raise InvalidTagError(f"unknown feedback tags: {sorted(unknown)}")
|
|
|
|
@classmethod
|
|
def create(
|
|
cls,
|
|
*,
|
|
run_id: str,
|
|
thread_id: str,
|
|
rating: int,
|
|
user_id: str | None = None,
|
|
comment: str | None = None,
|
|
tags: tuple[str, ...] | list[str] = (),
|
|
) -> Feedback:
|
|
"""Factory: generate identity and validate invariants."""
|
|
return cls(
|
|
feedback_id=str(uuid.uuid4()),
|
|
run_id=run_id,
|
|
thread_id=thread_id,
|
|
rating=rating,
|
|
user_id=user_id,
|
|
comment=comment,
|
|
tags=tuple(tags),
|
|
)
|