-
Notifications
You must be signed in to change notification settings - Fork 0
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
37b76d0
commit e267a9d
Showing
7 changed files
with
154 additions
and
107 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pydantic import BaseModel | ||
|
||
def determine_pydantic_version_from_base_model(model: BaseModel): | ||
"""Determine if a BaseModel is from Pydantic v1 or v2.""" | ||
if hasattr(model, 'model_fields'): | ||
return 2 | ||
elif hasattr(model, '__fields__'): | ||
return 1 | ||
else: | ||
raise ValueError("Unknown Pydantic version or incompatible BaseModel class.") | ||
|
||
|
||
def get_field_infos(model: BaseModel): | ||
"""Get all FieldInfo instances from a Pydantic model, compatible with v1 and v2.""" | ||
version = determine_pydantic_version_from_base_model(model) | ||
|
||
field_infos = [] | ||
|
||
# Handle Pydantic v2 | ||
if version == 2: | ||
for field_name, field in model.model_fields.items(): | ||
field_infos.append(field) | ||
|
||
# Handle Pydantic v1 | ||
elif version == 1: | ||
for field_name, field in model.__fields__.items(): | ||
field_infos.append(field) | ||
|
||
return field_infos |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from pydantic import BaseModel | ||
|
||
class AutoflexBaseModel(BaseModel): | ||
""" | ||
A base class that can be used for any model within the system. | ||
It inherits from Pydantic's BaseModel to leverage data validation | ||
and parsing features. | ||
""" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from autoflex.types.core import AutoflexBaseModel | ||
from autoflex.types.descriptors import AutoflexParameterTypes | ||
|
||
|
||
class ParameterTable(AutoflexBaseModel): | ||
name: str | ||
types: str | ||
description: str | ||
special_parameters: AutoflexParameterTypes |
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,36 +1,5 @@ | ||
from pydantic.fields import FieldInfo | ||
from pydantic import BaseModel | ||
|
||
def check_json_schema_extra(field: FieldInfo) -> bool: | ||
"""Check if the FieldInfo contains a 'json_schema_extra' parameter.""" | ||
return hasattr(field, 'json_schema_extra') and field.json_schema_extra is not None | ||
|
||
|
||
|
||
def determine_pydantic_version_from_base_model(model: BaseModel): | ||
"""Determine if a BaseModel is from Pydantic v1 or v2.""" | ||
if hasattr(model, 'model_fields'): | ||
return 2 | ||
elif hasattr(model, '__fields__'): | ||
return 1 | ||
else: | ||
raise ValueError("Unknown Pydantic version or incompatible BaseModel class.") | ||
|
||
|
||
def get_field_infos(model: BaseModel): | ||
"""Get all FieldInfo instances from a Pydantic model, compatible with v1 and v2.""" | ||
version = determine_pydantic_version_from_base_model(model) | ||
|
||
field_infos = [] | ||
|
||
# Handle Pydantic v2 | ||
if version == 2: | ||
for field_name, field in model.model_fields.items(): | ||
field_infos.append(field) | ||
|
||
# Handle Pydantic v1 | ||
elif version == 1: | ||
for field_name, field in model.__fields__.items(): | ||
field_infos.append(field) | ||
|
||
return field_infos |
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