Skip to content

Commit f7b2383

Browse files
committed
ensure the parameter is a class before checking subclass
1 parent 82c41d9 commit f7b2383

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Diff for: chatlab/registry.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,21 @@ class WhatTime(BaseModel):
4242
import asyncio
4343
import inspect
4444
import json
45-
from typing import Any, Callable, Dict, Iterable, List, Optional, Type, TypedDict, Union, get_args, get_origin, overload
45+
from typing import (
46+
Any,
47+
Callable,
48+
Dict,
49+
Iterable,
50+
List,
51+
Optional,
52+
Type,
53+
TypedDict,
54+
Union,
55+
cast,
56+
get_args,
57+
get_origin,
58+
overload,
59+
)
4660

4761
from openai.types import FunctionDefinition
4862
from openai.types.chat.completion_create_params import Function, FunctionCall
@@ -453,11 +467,10 @@ async def call(self, name: str, arguments: Optional[str] = None) -> Any:
453467
arg_value = parameters.get(param_name)
454468

455469
# Check if parameter type is a subclass of BaseModel and deserialize JSON into Pydantic model
456-
if issubclass(param_type, BaseModel):
470+
if inspect.isclass(param_type) and issubclass(param_type, BaseModel):
457471
prepared_arguments[param_name] = param_type.model_validate(arg_value)
458472
else:
459-
prepared_arguments[param_name] = arg_value
460-
473+
prepared_arguments[param_name] = cast(Any, arg_value)
461474

462475
if asyncio.iscoroutinefunction(function):
463476
result = await function(**prepared_arguments)

0 commit comments

Comments
 (0)