2023-12-01 00:29:28 +03:00
|
|
|
from typing import Optional
|
|
|
|
from uuid import UUID
|
|
|
|
|
|
|
|
from logger import get_logger
|
2023-12-06 10:40:18 +03:00
|
|
|
from modules.brain.entity.api_brain_definition_entity import (
|
|
|
|
ApiBrainAllowedMethods,
|
|
|
|
ApiBrainDefinitionEntity,
|
|
|
|
ApiBrainDefinitionSchema,
|
|
|
|
ApiBrainDefinitionSecret,
|
|
|
|
)
|
2023-12-01 00:29:28 +03:00
|
|
|
from modules.brain.entity.brain_entity import BrainType
|
|
|
|
from pydantic import BaseModel, Extra
|
|
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
|
|
|
2023-12-06 10:40:18 +03:00
|
|
|
class CreateApiBrainDefinition(BaseModel, extra=Extra.forbid):
|
|
|
|
method: ApiBrainAllowedMethods
|
|
|
|
url: str
|
|
|
|
params: Optional[ApiBrainDefinitionSchema] = ApiBrainDefinitionSchema()
|
|
|
|
search_params: ApiBrainDefinitionSchema = ApiBrainDefinitionSchema()
|
|
|
|
secrets: Optional[list[ApiBrainDefinitionSecret]] = []
|
|
|
|
|
|
|
|
|
2023-12-01 00:29:28 +03:00
|
|
|
class CreateBrainProperties(BaseModel, extra=Extra.forbid):
|
|
|
|
name: Optional[str] = "Default brain"
|
2024-01-20 07:34:30 +03:00
|
|
|
description: str = "This is a description"
|
|
|
|
status: Optional[str] = "public"
|
2023-12-01 00:29:28 +03:00
|
|
|
model: Optional[str]
|
|
|
|
temperature: Optional[float] = 0.0
|
|
|
|
max_tokens: Optional[int] = 256
|
|
|
|
prompt_id: Optional[UUID] = None
|
|
|
|
brain_type: Optional[BrainType] = BrainType.DOC
|
|
|
|
brain_definition: Optional[CreateApiBrainDefinition]
|
|
|
|
brain_secrets_values: dict = {}
|
2023-12-06 10:40:18 +03:00
|
|
|
connected_brains_ids: Optional[list[UUID]] = []
|
2023-12-01 00:29:28 +03:00
|
|
|
|
|
|
|
def dict(self, *args, **kwargs):
|
|
|
|
brain_dict = super().dict(*args, **kwargs)
|
|
|
|
if brain_dict.get("prompt_id"):
|
|
|
|
brain_dict["prompt_id"] = str(brain_dict.get("prompt_id"))
|
|
|
|
return brain_dict
|
|
|
|
|
|
|
|
|
|
|
|
class BrainUpdatableProperties(BaseModel):
|
|
|
|
name: Optional[str]
|
|
|
|
description: Optional[str]
|
|
|
|
temperature: Optional[float]
|
|
|
|
model: Optional[str]
|
|
|
|
max_tokens: Optional[int]
|
|
|
|
status: Optional[str]
|
|
|
|
prompt_id: Optional[UUID]
|
2023-12-06 10:40:18 +03:00
|
|
|
brain_definition: Optional[ApiBrainDefinitionEntity]
|
|
|
|
connected_brains_ids: Optional[list[UUID]] = []
|
2023-12-01 00:29:28 +03:00
|
|
|
|
|
|
|
def dict(self, *args, **kwargs):
|
|
|
|
brain_dict = super().dict(*args, **kwargs)
|
|
|
|
if brain_dict.get("prompt_id"):
|
|
|
|
brain_dict["prompt_id"] = str(brain_dict.get("prompt_id"))
|
|
|
|
return brain_dict
|
|
|
|
|
|
|
|
|
|
|
|
class BrainQuestionRequest(BaseModel):
|
|
|
|
question: str
|