2024-06-27 13:51:01 +03:00
|
|
|
from datetime import datetime
|
2024-09-02 11:20:53 +03:00
|
|
|
from enum import Enum
|
|
|
|
from typing import Any, Dict, Optional
|
2024-06-27 13:51:01 +03:00
|
|
|
from uuid import UUID
|
2024-06-26 10:58:55 +03:00
|
|
|
|
2024-07-09 18:55:14 +03:00
|
|
|
from langchain_core.documents import Document
|
2024-07-10 16:22:59 +03:00
|
|
|
from langchain_core.messages import AIMessage, HumanMessage
|
2024-06-26 10:58:55 +03:00
|
|
|
from langchain_core.pydantic_v1 import BaseModel as BaseModelV1
|
|
|
|
from langchain_core.pydantic_v1 import Field as FieldV1
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from typing_extensions import TypedDict
|
|
|
|
|
|
|
|
|
|
|
|
class cited_answer(BaseModelV1):
|
|
|
|
"""Answer the user question based only on the given sources, and cite the sources used."""
|
|
|
|
|
|
|
|
answer: str = FieldV1(
|
|
|
|
...,
|
|
|
|
description="The answer to the user question, which is based only on the given sources.",
|
|
|
|
)
|
|
|
|
citations: list[int] = FieldV1(
|
|
|
|
...,
|
|
|
|
description="The integer IDs of the SPECIFIC sources which justify the answer.",
|
|
|
|
)
|
|
|
|
|
|
|
|
followup_questions: list[str] = FieldV1(
|
|
|
|
...,
|
|
|
|
description="Generate up to 3 follow-up questions that could be asked based on the answer given or context provided.",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-07-10 16:22:59 +03:00
|
|
|
class ChatMessage(BaseModelV1):
|
2024-06-27 13:51:01 +03:00
|
|
|
chat_id: UUID
|
|
|
|
message_id: UUID
|
2024-08-06 15:51:27 +03:00
|
|
|
brain_id: UUID | None
|
2024-07-10 16:22:59 +03:00
|
|
|
msg: AIMessage | HumanMessage
|
2024-06-27 13:51:01 +03:00
|
|
|
message_time: datetime
|
2024-07-10 16:22:59 +03:00
|
|
|
metadata: dict[str, Any]
|
2024-06-27 13:51:01 +03:00
|
|
|
|
|
|
|
|
2024-09-02 11:20:53 +03:00
|
|
|
class KnowledgeStatus(str, Enum):
|
|
|
|
PROCESSING = "PROCESSING"
|
|
|
|
UPLOADED = "UPLOADED"
|
|
|
|
ERROR = "ERROR"
|
2024-09-16 14:31:09 +03:00
|
|
|
RESERVED = "RESERVED"
|
2024-09-02 11:20:53 +03:00
|
|
|
|
|
|
|
|
2024-06-26 10:58:55 +03:00
|
|
|
class Source(BaseModel):
|
|
|
|
name: str
|
|
|
|
source_url: str
|
|
|
|
type: str
|
|
|
|
original_file_name: str
|
|
|
|
citation: str
|
|
|
|
|
|
|
|
|
|
|
|
class RawRAGChunkResponse(TypedDict):
|
|
|
|
answer: dict[str, Any]
|
|
|
|
docs: dict[str, Any]
|
|
|
|
|
|
|
|
|
|
|
|
class RawRAGResponse(TypedDict):
|
|
|
|
answer: dict[str, Any]
|
|
|
|
docs: dict[str, Any]
|
|
|
|
|
|
|
|
|
2024-08-06 18:44:12 +03:00
|
|
|
class ChatLLMMetadata(BaseModel):
|
|
|
|
name: str
|
|
|
|
display_name: str | None = None
|
|
|
|
description: str | None = None
|
|
|
|
image_url: str | None = None
|
2024-08-07 21:47:33 +03:00
|
|
|
brain_id: str | None = None
|
|
|
|
brain_name: str | None = None
|
2024-08-06 18:44:12 +03:00
|
|
|
|
|
|
|
|
2024-06-26 10:58:55 +03:00
|
|
|
class RAGResponseMetadata(BaseModel):
|
|
|
|
citations: list[int] | None = None
|
|
|
|
followup_questions: list[str] | None = None
|
|
|
|
sources: list[Any] | None = None
|
2024-08-06 18:44:12 +03:00
|
|
|
metadata_model: ChatLLMMetadata | None = None
|
2024-06-26 10:58:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
class ParsedRAGResponse(BaseModel):
|
|
|
|
answer: str
|
|
|
|
metadata: RAGResponseMetadata | None = None
|
|
|
|
|
|
|
|
|
|
|
|
class ParsedRAGChunkResponse(BaseModel):
|
|
|
|
answer: str
|
|
|
|
metadata: RAGResponseMetadata
|
|
|
|
last_chunk: bool = False
|
2024-06-27 13:51:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
class QuivrKnowledge(BaseModel):
|
|
|
|
id: UUID
|
2024-09-23 19:11:06 +03:00
|
|
|
file_name: str
|
|
|
|
brain_ids: list[UUID] | None = None
|
2024-09-02 11:20:53 +03:00
|
|
|
url: Optional[str] = None
|
2024-09-23 19:11:06 +03:00
|
|
|
extension: str = ".txt"
|
2024-09-02 11:20:53 +03:00
|
|
|
mime_type: str = "txt"
|
|
|
|
status: KnowledgeStatus = KnowledgeStatus.PROCESSING
|
|
|
|
source: Optional[str] = None
|
|
|
|
source_link: str | None = None
|
|
|
|
file_size: int | None = None # FIXME: Should not be optional @chloedia
|
|
|
|
file_sha1: Optional[str] = None # FIXME: Should not be optional @chloedia
|
|
|
|
updated_at: Optional[datetime] = None
|
|
|
|
created_at: Optional[datetime] = None
|
|
|
|
metadata: Optional[Dict[str, str]] = None
|
2024-07-09 18:55:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
# NOTE: for compatibility issues with langchain <-> PydanticV1
|
|
|
|
class SearchResult(BaseModelV1):
|
|
|
|
chunk: Document
|
2024-07-12 16:07:39 +03:00
|
|
|
distance: float
|