Skip to content
Draft
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
3 changes: 2 additions & 1 deletion adala/skills/collection/prompt_improvement.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
AfterValidator,
)
from adala.skills import Skill
from typing import Any, Dict, List, Optional, Union, Type
from typing import Any, Dict, List, Optional, Type, Union

from typing_extensions import Annotated
from adala.skills import AnalysisSkill
from adala.utils.parse import parse_template
Expand Down
15 changes: 13 additions & 2 deletions adala/utils/pydantic_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Type, Union, Tuple, Literal, Set
from typing import Any, Dict, List, Optional, Type, Union, Tuple, Literal, Set, get_origin, get_args
from enum import Enum
from datetime import datetime
from pydantic import BaseModel, Field, create_model
Expand Down Expand Up @@ -95,8 +95,12 @@ def json_schema_to_pydantic_field(json_schema: Dict[str, Any]) -> Tuple[Any, Fie
if constraint in json_schema:
field_params[constraint] = json_schema[constraint]

# Use None default for Optional types so they aren't required
is_optional = get_origin(type_) is Union and type(None) in get_args(type_)
default = None if is_optional else ...

# Create a Field object with the type and optional parameters.
return type_, Field(..., **field_params)
return type_, Field(default, **field_params)


def json_schema_to_pydantic_type(
Expand All @@ -115,6 +119,13 @@ def json_schema_to_pydantic_type(

type_ = json_schema.get("type")

# Handle union types: ["string", "null"] → Optional[str]
if isinstance(type_, list):
non_null = [t for t in type_ if t != 'null']
has_null = len(non_null) < len(type_)
inner = json_schema_to_pydantic_type({**json_schema, 'type': non_null[0]})
return Optional[inner] if has_null else inner

if type_ == "string":
if "format" in json_schema:
format_ = json_schema["format"]
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ dependencies = [
"pandarallel (>=1.6.5,<2.0.0)",
"instructor (>=1.14.5, <2.0.0)",
"async-lru (>=2.0.5,<3.0.0)",
"jinja2 (>=3.1.6,<4.0)"
"jinja2 (>=3.1.6,<4.0)",
"lxml>=6.0.2",
"appdirs>=1.4.4",
"xmljson>=0.2.1",
"jsf>=0.11.2",
"datamodel-code-generator>=0.54.1"
]

[project.urls]
Expand Down
Loading