Hey folks!
I use a Qwen2.5-7B-instruct model. For all my tool calls (see below), a (lazy?) ValidatorIterator is returned:
@tool
def end_conversation() → str:
“”“End the conversation with the user if the user explicitly wants to end the conversation. This does not end the conversation immediately, so you have a chance to say goodbye afterwards.”“”
return “Conversation ended”
or
@tool
def query_restaurants(
location: Optional[Literal[“north”, “south”, “east”, “west”, “centre”]] = None,
pricerange: Optional[Price] = None,
food: Optional[FoodType] = None,
) → dict | None:
“”“Query the restaurant database by various criteria.”“”
database = load_database(“multiwoz21”)
params = {
"area": location,
"pricerange": pricerange,
"food": food,
}
query_params = {k: v for k, v in params.items() if v is not None}
restaurants = database.query("restaurant", {"restaurant": query_params}, topk=1)
if restaurants:
print(restaurants)
restaurant = Restaurant(**restaurants[0])
print(restaurant)
return restaurant.model_dump()
return None
Notice that the restaurant return types do not contain literals:
class Restaurant(BaseModel):
id: str
name: str
address: str
area: Area
food: FoodType
introduction: Optional[str] = None
location: str
phone: Optional[str] = None
postcode: str
pricerange: Literal[“cheap”, “moderate”, “expensive”]
type: Literal[“restaurant”]
signature: Optional[str] = None
The returned ValidatorIterator looks like this:
{‘content’: ‘’,
‘role’: ‘assistant’,
‘tool_calls’: ValidatorIterator(index=0, schema=Some(TypedDict(TypedDictValidator { fields: [TypedDictField { name: “id”, lookup_key_collection: LookupKeyCollection { by_name: Simple(LookupPath { first_item: PathItemString { key: “id”, py_key: Py(0x7878441d4a20) }, rest: }), by_alias: None, by_alias_then_name: None }, name_py: Py(0xb41e88), required: true, validator: Str(StrValidator { strict: false, coerce_numbers_to_str: false }) }, TypedDictField { name: “function”, lookup_key_collection: LookupKeyCollection { by_name: Simple(LookupPath { first_item: PathItemString { key: “function”, py_key: Py(0x7878441d17f0) }, rest:}), by_alias: None, by_alias_then_name: None }, name_py: Py(0x787846821830), required: true, validator: TypedDict(TypedDictValidator { fields: [TypedDictField { name: “arguments”, lookup_key_collection: LookupKeyCollection { by_name: Simple(LookupPath { first_item: PathItemString { key: “arguments”, py_key: Py(0x7878441d39f0) }, rest:}), by_alias: None, by_alias_then_name: None }, name_py: Py(0xb3f9e8), required: true, validator: Str(StrValidator { strict: false, coerce_numbers_to_str: false }) }, TypedDictField { name: “name”, lookup_key_collection: LookupKeyCollection { by_name: Simple(LookupPath { first_item: PathItemString { key: “name”, py_key: Py(0x7878441d4630) }, rest:}), by_alias: None, by_alias_then_name: None }, name_py: Py(0xb43150), required: true, validator: Str(StrValidator { strict: false, coerce_numbers_to_str: false }) }], extra_behavior: Ignore, extras_validator: None, strict: false, loc_by_alias: true, validate_by_alias: None, validate_by_name: None, cls_name: Some(“Function”) }) }, TypedDictField { name: “type”, lookup_key_collection: LookupKeyCollection { by_name: Simple(LookupPath { first_item: PathItemString { key: “type”, py_key: Py(0x7878441d4a80) }, rest: }), by_alias: None, by_alias_then_name: None }, name_py: Py(0xb453c8), required: true, validator: Literal(LiteralValidator { lookup: LiteralLookup { expected_bool: None, expected_int: None, expected_str: Some({“function”: 0}), expected_py_dict: None, expected_py_values: None, expected_py_primitives: Some(Py(0x7878441d1580)), values: [Py(0x787846821830)] }, expected_repr: “‘function’”, name: “literal[‘function’]” }) }], extra_behavior: Ignore, extras_validator: None, strict: false, loc_by_alias: true, validate_by_alias: None, validate_by_name: None, cls_name: Some(“ChatCompletionMessageToolCallParam”) })))}
I already tried out all sorts of different types, returning json objects instead of strings etc. but it didn’t help. Is it likely that the issue occures because I’m calling a synchronous invoke instead of ainvoke?
Has anyone ever encountered such an error and can help me out? Thank you!