quivr/backend/modules/assistant/dto/inputs.py
Stan Girard 3e53ff0dce
fix(assistants): brain id is null (#2445)
This pull request fixes an issue where the brain activation and value
handling were not working correctly. The `BrainInput` model now allows
for optional activation and value fields, and an empty string is
converted to `None` using a root validator. This ensures that brain
activation and value can be properly handled in the application.

<!--
ELLIPSIS_HIDDEN
-->


----

| 🚀 This description was created by
[Ellipsis](https://www.ellipsis.dev) for commit
d63ed6e651 |
|--------|

### Summary:
This PR modifies the `BrainInput` class in
`/backend/modules/assistant/dto/inputs.py` to make `activated` and
`value` fields optional and adds a root validator to convert empty
strings to `None`.

**Key points**:
- Modified `BrainInput` class in
`/backend/modules/assistant/dto/inputs.py`
- Made `activated` and `value` fields optional with default values
- Added root validator `empty_string_to_none` to convert empty strings
to `None`


----
Generated with ❤️ by [ellipsis.dev](https://www.ellipsis.dev)



<!--
ELLIPSIS_HIDDEN
-->
2024-04-18 14:03:47 -07:00

83 lines
1.6 KiB
Python

import json
from typing import List, Optional
from uuid import UUID
from pydantic import BaseModel, model_validator, root_validator
class EmailInput(BaseModel):
activated: bool
class BrainInput(BaseModel):
activated: Optional[bool] = False
value: Optional[UUID] = None
@root_validator(pre=True)
def empty_string_to_none(cls, values):
for field, value in values.items():
if value == "":
values[field] = None
return values
class FileInput(BaseModel):
key: str
value: str
class UrlInput(BaseModel):
key: str
value: str
class TextInput(BaseModel):
key: str
value: str
class InputBoolean(BaseModel):
key: str
value: bool
class InputNumber(BaseModel):
key: str
value: int
class InputSelectText(BaseModel):
key: str
value: str
class InputSelectNumber(BaseModel):
key: str
value: int
class Inputs(BaseModel):
files: Optional[List[FileInput]] = None
urls: Optional[List[UrlInput]] = None
texts: Optional[List[TextInput]] = None
booleans: Optional[List[InputBoolean]] = None
numbers: Optional[List[InputNumber]] = None
select_texts: Optional[List[InputSelectText]] = None
select_numbers: Optional[List[InputSelectNumber]] = None
class Outputs(BaseModel):
email: Optional[EmailInput] = None
brain: Optional[BrainInput] = None
class InputAssistant(BaseModel):
name: str
inputs: Inputs
outputs: Outputs
@model_validator(mode="before")
@classmethod
def to_py_dict(cls, data):
return json.loads(data)