mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 21:42:58 +00:00
Merge pull request #4970 from daniel-code/feat/support-literal-type-in-tools
feat: support Literal type in Tools
This commit is contained in:
commit
928326103c
@ -1,5 +1,7 @@
|
|||||||
|
from ast import literal_eval
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, create_model
|
from pydantic import BaseModel, Field, create_model
|
||||||
from typing import Any, Optional, Type
|
from typing import Any, Optional, Type, Literal
|
||||||
|
|
||||||
|
|
||||||
def json_schema_to_model(tool_dict: dict[str, Any]) -> Type[BaseModel]:
|
def json_schema_to_model(tool_dict: dict[str, Any]) -> Type[BaseModel]:
|
||||||
@ -100,5 +102,7 @@ def json_schema_to_pydantic_type(json_schema: dict[str, Any]) -> Any:
|
|||||||
return dict
|
return dict
|
||||||
elif type_ == "null":
|
elif type_ == "null":
|
||||||
return Optional[Any] # Use Optional[Any] for nullable fields
|
return Optional[Any] # Use Optional[Any] for nullable fields
|
||||||
|
elif type_ == "literal":
|
||||||
|
return Literal[literal_eval(json_schema.get("enum"))]
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unsupported JSON schema type: {type_}")
|
raise ValueError(f"Unsupported JSON schema type: {type_}")
|
||||||
|
Loading…
Reference in New Issue
Block a user