Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions plexe/internal/common/utils/pydantic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@ def map_to_basemodel(name: str, schema: dict | Type[BaseModel]) -> Type[BaseMode
# Handle both Dict[str, type] and Dict[str, str] formats
annotated_schema = {}

type_mapping = {
"int": int,
"float": float,
"str": str,
"bool": bool,
"List[int]": List[int],
"List[float]": List[float],
"List[str]": List[str],
"List[bool]": List[bool],
}

for k, v in schema.items():
# If v is a string like "int", convert it to the actual type
if isinstance(v, str):
type_mapping = {
"int": int,
"float": float,
"str": str,
"bool": bool,
"List[int]": List[int],
"List[float]": List[float],
"List[str]": List[str],
"List[bool]": List[bool],
}
if v in type_mapping:
annotated_schema[k] = (type_mapping[v], ...)
else:
Expand Down
18 changes: 10 additions & 8 deletions plexe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import uuid
import warnings
from datetime import datetime
from typing import Dict, List, Type, Any
from typing import Dict, List, Type, Any, Optional
from deprecated import deprecated

import pandas as pd
Expand Down Expand Up @@ -93,8 +93,8 @@ class Model:
def __init__(
self,
intent: str,
input_schema: Type[BaseModel] | Dict[str, type] = None,
output_schema: Type[BaseModel] | Dict[str, type] = None,
input_schema: Type[BaseModel] | Dict[str, type] = {},
output_schema: Type[BaseModel] | Dict[str, type] = {},
distributed: bool = False,
):
"""
Expand All @@ -110,8 +110,10 @@ def __init__(

# The model's identity is defined by these fields
self.intent: str = intent
self.input_schema: Type[BaseModel] = map_to_basemodel("in", input_schema) if input_schema else None
self.output_schema: Type[BaseModel] = map_to_basemodel("out", output_schema) if output_schema else None
self.input_schema: Optional[Type[BaseModel]] = map_to_basemodel("in", input_schema) if input_schema else None
self.output_schema: Optional[Type[BaseModel]] = (
map_to_basemodel("out", output_schema) if output_schema else None
)
self.training_data: Dict[str, Dataset] = dict()
self.distributed: bool = distributed

Expand Down Expand Up @@ -142,10 +144,10 @@ def build(
self,
datasets: List[pd.DataFrame | DatasetGenerator],
provider: str | ProviderConfig = "openai/gpt-4o-mini",
timeout: int = None,
max_iterations: int = None,
timeout: int | None = None,
max_iterations: int | None = None,
run_timeout: int = 1800,
callbacks: List[Callback] = None,
callbacks: List[Callback] | None = None,
verbose: bool = False,
# resume: bool = False,
enable_checkpointing: bool = False,
Expand Down