|
| 1 | +import functools |
1 | 2 | import inspect |
2 | 3 | import json |
3 | 4 | from collections.abc import Awaitable, Callable, Sequence |
4 | 5 | from itertools import chain |
5 | 6 | from types import GenericAlias |
6 | 7 | from typing import Annotated, Any, cast, get_args, get_origin, get_type_hints |
7 | 8 |
|
| 9 | +import anyio |
| 10 | +import anyio.to_thread |
8 | 11 | import pydantic_core |
9 | | -from pydantic import ( |
10 | | - BaseModel, |
11 | | - ConfigDict, |
12 | | - Field, |
13 | | - RootModel, |
14 | | - WithJsonSchema, |
15 | | - create_model, |
16 | | -) |
| 12 | +from pydantic import BaseModel, ConfigDict, Field, RootModel, WithJsonSchema, create_model |
17 | 13 | from pydantic.fields import FieldInfo |
18 | 14 | from pydantic.json_schema import GenerateJsonSchema, JsonSchemaWarningKind |
19 | 15 | from typing_extensions import is_typeddict |
@@ -60,9 +56,7 @@ def model_dump_one_level(self) -> dict[str, Any]: |
60 | 56 | kwargs[output_name] = value |
61 | 57 | return kwargs |
62 | 58 |
|
63 | | - model_config = ConfigDict( |
64 | | - arbitrary_types_allowed=True, |
65 | | - ) |
| 59 | + model_config = ConfigDict(arbitrary_types_allowed=True) |
66 | 60 |
|
67 | 61 |
|
68 | 62 | class FuncMetadata(BaseModel): |
@@ -92,7 +86,7 @@ async def call_fn_with_arg_validation( |
92 | 86 | if fn_is_async: |
93 | 87 | return await fn(**arguments_parsed_dict) |
94 | 88 | else: |
95 | | - return fn(**arguments_parsed_dict) |
| 89 | + return await anyio.to_thread.run_sync(functools.partial(fn, **arguments_parsed_dict)) |
96 | 90 |
|
97 | 91 | def convert_result(self, result: Any) -> Any: |
98 | 92 | """Convert the result of a function call to the appropriate format for |
|
0 commit comments