-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca9c92f
commit 0b888b5
Showing
9 changed files
with
80 additions
and
45 deletions.
There are no files selected for viewing
33 changes: 17 additions & 16 deletions
33
backend/chatsky_ui/schemas/front_graph_components/interface.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
from pydantic import model_validator, RootModel | ||
from pydantic import Field, model_validator | ||
from typing import Any | ||
|
||
from .base_component import BaseComponent | ||
from typing import Optional, Dict | ||
|
||
class Interface(BaseComponent): | ||
telegram: Optional[Dict[str, Any]] = Field(default=None) | ||
cli: Optional[Dict[str, Any]] = Field(default=None) | ||
|
||
class Interface(BaseComponent, RootModel): | ||
@model_validator(mode="before") | ||
def validate_interface(cls, v): | ||
if not isinstance(v, dict): | ||
raise ValueError('interface must be a dictionary') | ||
if "telegram" in v: | ||
if not isinstance(v['telegram'], dict): | ||
raise ValueError('telegram must be a dictionary') | ||
if 'token' not in v['telegram'] or not isinstance(v['telegram']['token'], str): | ||
raise ValueError('telegram dictionary must contain a string token') | ||
elif "cli" in v: | ||
pass | ||
else: | ||
raise ValueError('interface must contain either telegram or cli') | ||
return v | ||
@model_validator(mode='after') | ||
def check_one_not_none(cls, values): | ||
telegram, cli = values.telegram, values.cli | ||
if (telegram is None) == (cli is None): | ||
raise ValueError('Exactly one of "telegram" or "cli" must be provided.') | ||
return values | ||
|
||
@model_validator(mode='after') | ||
def check_telegram_token(cls, values): | ||
if values.telegram is not None and 'token' not in values.telegram: | ||
raise ValueError('Telegram token must be provided.') | ||
return values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters