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]] = []
|
2024-01-26 02:56:46 +03:00
|
|
|
raw: Optional[bool] = False
|
|
|
|
jq_instructions: Optional[str] = None
|
2023-12-06 10:40:18 +03:00
|
|
|
|
|
|
|
|
2024-02-06 08:02:46 +03:00
|
|
|
class CreateIntegrationBrain(BaseModel, extra=Extra.forbid):
|
|
|
|
integration_name: str
|
|
|
|
integration_logo_url: str
|
|
|
|
connection_settings: dict
|
|
|
|
|
|
|
|
|
|
|
|
class BrainIntegrationSettings(BaseModel, extra=Extra.forbid):
|
|
|
|
integration_id: str
|
|
|
|
settings: dict
|
|
|
|
|
|
|
|
|
|
|
|
class BrainIntegrationUpdateSettings(BaseModel, extra=Extra.forbid):
|
|
|
|
settings: dict
|
|
|
|
|
|
|
|
|
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"
|
2024-01-22 02:40:42 +03:00
|
|
|
status: Optional[str] = "private"
|
2024-02-15 01:01:35 +03:00
|
|
|
model: Optional[str] = None
|
2023-12-01 00:29:28 +03:00
|
|
|
temperature: Optional[float] = 0.0
|
2024-01-26 04:10:38 +03:00
|
|
|
max_tokens: Optional[int] = 2000
|
2023-12-01 00:29:28 +03:00
|
|
|
prompt_id: Optional[UUID] = None
|
|
|
|
brain_type: Optional[BrainType] = BrainType.DOC
|
2024-02-15 01:01:35 +03:00
|
|
|
brain_definition: Optional[CreateApiBrainDefinition] = None
|
2024-02-06 08:02:46 +03:00
|
|
|
brain_secrets_values: Optional[dict] = {}
|
2023-12-06 10:40:18 +03:00
|
|
|
connected_brains_ids: Optional[list[UUID]] = []
|
2024-02-06 08:02:46 +03:00
|
|
|
integration: Optional[BrainIntegrationSettings] = None
|
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):
|
2024-02-15 01:01:35 +03:00
|
|
|
name: Optional[str] = None
|
|
|
|
description: Optional[str] = None
|
|
|
|
temperature: Optional[float] = None
|
|
|
|
model: Optional[str] = None
|
|
|
|
max_tokens: Optional[int] = None
|
|
|
|
status: Optional[str] = None
|
|
|
|
prompt_id: Optional[UUID] = None
|
|
|
|
brain_definition: Optional[ApiBrainDefinitionEntity] = None
|
2023-12-06 10:40:18 +03:00
|
|
|
connected_brains_ids: Optional[list[UUID]] = []
|
2024-02-06 08:02:46 +03:00
|
|
|
integration: Optional[BrainIntegrationUpdateSettings] = None
|
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
|