Skip to content

Commit

Permalink
[Controller] Add Optional type hint to pydantic fields with None defa…
Browse files Browse the repository at this point in the history
…ult (#14)
  • Loading branch information
yonishelach authored Sep 4, 2024
1 parent e50f563 commit dad2e73
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 33 deletions.
16 changes: 8 additions & 8 deletions controller/src/schemas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from datetime import datetime
from enum import Enum
from http.client import HTTPException
from typing import Dict, Type, Union
from typing import Dict, Optional, Type, Union

import yaml
from pydantic import BaseModel
Expand Down Expand Up @@ -147,11 +147,11 @@ def __str__(self):

class BaseWithMetadata(Base):
name: str
uid: str = None
description: str = None
labels: Dict[str, Union[str, None]] = None
created: Union[str, datetime] = None
updated: Union[str, datetime] = None
uid: Optional[str] = None
description: Optional[str] = None
labels: Optional[Dict[str, Union[str, None]]] = None
created: Optional[Union[str, datetime]] = None
updated: Optional[Union[str, datetime]] = None


class BaseWithOwner(BaseWithMetadata):
Expand All @@ -164,8 +164,8 @@ class BaseWithVerMetadata(BaseWithOwner):

class APIResponse(BaseModel):
success: bool
data: Union[list, Type[BaseModel], dict] = None
error: str = None
data: Optional[Union[list, Type[BaseModel], dict]] = None
error: Optional[str] = None

def with_raise(self, format=None) -> "APIResponse":
if not self.success:
Expand Down
6 changes: 3 additions & 3 deletions controller/src/schemas/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List
from typing import List, Optional

from controller.src.schemas.base import BaseWithVerMetadata

Expand All @@ -23,5 +23,5 @@ class Dataset(BaseWithVerMetadata):
task: str
path: str
project_id: str
sources: List[str] = None
producer: str = None
sources: Optional[List[str]] = None
producer: Optional[str] = None
4 changes: 3 additions & 1 deletion controller/src/schemas/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional

from controller.src.schemas.base import BaseWithVerMetadata


class Document(BaseWithVerMetadata):
_top_level_fields = ["path", "origin"]
path: str
project_id: str
origin: str = None
origin: Optional[str] = None
9 changes: 5 additions & 4 deletions controller/src/schemas/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from enum import Enum
from typing import Optional

from controller.src.schemas.base import BaseWithVerMetadata

Expand All @@ -29,7 +30,7 @@ class Model(BaseWithVerMetadata):
model_type: ModelType
base_model: str
project_id: str
task: str = None
path: str = None
producer: str = None
deployment: str = None
task: Optional[str] = None
path: Optional[str] = None
producer: Optional[str] = None
deployment: Optional[str] = None
4 changes: 2 additions & 2 deletions controller/src/schemas/prompt_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List
from typing import List, Optional

from controller.src.schemas.base import BaseWithVerMetadata

Expand All @@ -23,4 +23,4 @@ class PromptTemplate(BaseWithVerMetadata):

text: str
project_id: str
arguments: List[str] = None
arguments: Optional[List[str]] = None
14 changes: 7 additions & 7 deletions controller/src/schemas/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from enum import Enum
from typing import List, Tuple
from typing import List, Optional, Tuple

from pydantic import BaseModel

Expand All @@ -22,9 +22,9 @@

class QueryItem(BaseModel):
question: str
session_id: str = None
filter: List[Tuple[str, str]] = None
data_source: str = None
session_id: Optional[str] = None
filter: Optional[List[Tuple[str, str]]] = None
data_source: Optional[str] = None


class ChatRole(str, Enum):
Expand All @@ -38,9 +38,9 @@ class ChatRole(str, Enum):
class Message(BaseModel):
role: ChatRole
content: str
extra_data: dict = None
sources: List[dict] = None
human_feedback: str = None
extra_data: Optional[dict] = None
sources: Optional[List[dict]] = None
human_feedback: Optional[str] = None


class ChatSession(BaseWithOwner):
Expand Down
8 changes: 5 additions & 3 deletions controller/src/schemas/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional

from controller.src.schemas.base import BaseWithMetadata


Expand All @@ -20,7 +22,7 @@ class User(BaseWithMetadata):
_top_level_fields = ["email", "full_name"]

email: str
full_name: str = None
features: dict[str, str] = None
policy: dict[str, str] = None
full_name: Optional[str] = None
features: Optional[dict[str, str]] = None
policy: Optional[dict[str, str]] = None
is_admin: bool = False
10 changes: 5 additions & 5 deletions controller/src/schemas/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import os
from enum import Enum
from typing import List
from typing import List, Optional

from controller.src.schemas.base import BaseWithVerMetadata

Expand All @@ -32,10 +32,10 @@ class Workflow(BaseWithVerMetadata):

workflow_type: WorkflowType
project_id: str
deployment: str = None
workflow_function: str = None
configuration: dict = None
graph: List[dict] = None
deployment: Optional[str] = None
workflow_function: Optional[str] = None
configuration: Optional[dict] = None
graph: Optional[List[dict]] = None

def get_infer_path(self):
if self.deployment is None:
Expand Down

0 comments on commit dad2e73

Please sign in to comment.