quivr/backend/modules/assistant/dto/outputs.py
Stan Girard 1931848262
feat(assistants): Add user usage update and pricing calculation to ITO assistant (#2433)
This pull request adds functionality to update user usage and calculate
pricing in the ITO assistant. It includes a new method
`increase_usage_user()` that raises an error if the user has consumed
all of their credits, and a new method `calculate_pricing()` that
returns a fixed pricing value of 20.

<!--
ELLIPSIS_HIDDEN
-->
----

| <a href="https://ellipsis.dev" target="_blank"><img
src="https://avatars.githubusercontent.com/u/80834858?s=400&u=31e596315b0d8f7465b3ee670f25cea677299c96&v=4"
alt="Ellipsis" width="30px" height="30px"/></a> | 🚀 This PR
description was created by [Ellipsis](https://www.ellipsis.dev) for
commit ee5fdf70f6. |
|--------|--------|

### Summary:
This PR adds functionality to update user usage and calculate pricing in
the ITO assistant, with new methods in the `ITO` class and an update to
where the `increase_usage_user()` method is called.

**Key points**:
- Added `increase_usage_user()` and `calculate_pricing()` methods to
`ITO` class in `/backend/modules/assistant/ito/ito.py`
- `increase_usage_user()` updates user usage and raises an error if all
credits are consumed
- `calculate_pricing()` returns a fixed pricing value of 20
- `increase_usage_user()` is now called in the `ITO` class constructor


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

<!--
ELLIPSIS_HIDDEN
-->
2024-04-16 09:14:38 -07:00

100 lines
2.1 KiB
Python

from typing import List, Optional
from pydantic import BaseModel
class InputFile(BaseModel):
key: str
allowed_extensions: Optional[List[str]] = ["pdf"]
required: Optional[bool] = True
description: str
class InputUrl(BaseModel):
key: str
required: Optional[bool] = True
description: str
class InputText(BaseModel):
key: str
required: Optional[bool] = True
description: str
validation_regex: Optional[str] = None
class InputBoolean(BaseModel):
key: str
required: Optional[bool] = True
description: str
class InputNumber(BaseModel):
key: str
required: Optional[bool] = True
description: str
min: Optional[int] = None
max: Optional[int] = None
increment: Optional[int] = None
default: Optional[int] = None
class InputSelectText(BaseModel):
key: str
required: Optional[bool] = True
description: str
options: List[str]
default: Optional[str] = None
class InputSelectNumber(BaseModel):
key: str
required: Optional[bool] = True
description: str
options: List[int]
default: Optional[int] = None
class Inputs(BaseModel):
files: Optional[List[InputFile]] = None
urls: Optional[List[InputUrl]] = None
texts: Optional[List[InputText]] = None
booleans: Optional[List[InputBoolean]] = None
numbers: Optional[List[InputNumber]] = None
select_texts: Optional[List[InputSelectText]] = None
select_numbers: Optional[List[InputSelectNumber]] = None
class OutputEmail(BaseModel):
required: Optional[bool] = True
description: str
type: str
class OutputBrain(BaseModel):
required: Optional[bool] = True
description: str
type: str
class Outputs(BaseModel):
email: Optional[OutputEmail] = None
brain: Optional[OutputBrain] = None
class Pricing(BaseModel):
cost: int = 20
description: str = "Credits per use"
class AssistantOutput(BaseModel):
name: str
description: str
pricing: Optional[Pricing] = Pricing()
tags: Optional[List[str]] = []
input_description: str
output_description: str
inputs: Inputs
outputs: Outputs
icon_url: Optional[str] = None