2024-06-27 13:51:01 +03:00
|
|
|
from datetime import datetime
|
2024-06-26 10:58:55 +03:00
|
|
|
from typing import Any
|
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-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]
|
|
|
|
|
|
|
|
|
|
|
|
class RAGResponseMetadata(BaseModel):
|
|
|
|
citations: list[int] | None = None
|
|
|
|
followup_questions: list[str] | None = None
|
|
|
|
sources: list[Any] | None = None
|
2024-08-06 15:51:27 +03:00
|
|
|
model_name: str | 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
|
|
|
|
brain_id: UUID
|
|
|
|
file_name: str | None = None
|
|
|
|
url: str | None = None
|
|
|
|
extension: str = "txt"
|
2024-07-16 18:18:05 +03:00
|
|
|
status: str = "PROCESSING"
|
2024-07-22 13:21:39 +03:00
|
|
|
integration: str | None = None
|
|
|
|
integration_link: str | None = 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
|