mirror of
https://github.com/langgenius/dify.git
synced 2026-11-13 06:41:07 +08:00
refactor(api): establish dataset application boundaries (#41729)
Co-authored-by: Jyong <jyong@dify.ai>
This commit is contained in:
1 parent
c005932db9
commit
a67cd87eb0
417 files changed
+30522
-23751
No files matched your search
@@ -1,10 +1,6 @@
|
||||
from collections.abc import Iterable, Mapping
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import field_serializer
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from fields.base import ResponseModel
|
||||
from libs.helper import to_timestamp
|
||||
@@ -72,40 +68,6 @@ class SegmentResponse(ResponseModel):
|
||||
return to_timestamp(value)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SegmentWithSummary:
|
||||
"""Expose session-backed segment relations during response validation."""
|
||||
|
||||
segment: Any
|
||||
summary: str | None
|
||||
session: Session
|
||||
|
||||
@property
|
||||
def child_chunks(self) -> Any:
|
||||
return self.segment.get_child_chunks(session=self.session, include_full_doc=False)
|
||||
|
||||
@property
|
||||
def attachments(self) -> Any:
|
||||
return self.segment.get_attachments(session=self.session)
|
||||
|
||||
def __getattr__(self, name: str) -> Any:
|
||||
return getattr(self.segment, name)
|
||||
|
||||
|
||||
def segment_response_with_summary(segment: Any, summary: str | None, *, session: Session) -> SegmentResponse:
|
||||
response_source = SegmentWithSummary(segment=segment, summary=summary, session=session)
|
||||
return SegmentResponse.model_validate(response_source, from_attributes=True)
|
||||
|
||||
|
||||
def segment_responses_with_summaries(
|
||||
segments: Iterable[Any],
|
||||
summaries: Mapping[str, str | None],
|
||||
*,
|
||||
session: Session,
|
||||
) -> list[SegmentResponse]:
|
||||
return [segment_response_with_summary(segment, summaries.get(segment.id), session=session) for segment in segments]
|
||||
|
||||
|
||||
class SegmentDetailResponse(ResponseModel):
|
||||
data: SegmentResponse
|
||||
doc_form: str
|
||||
|
||||
Reference in new issue
Block a user