mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-12-26 14:38:36 +00:00
fix: In State schema validation use != instead of is not for checking the type of messages (#9454)
* Use != instead of is not * Add reno * Use more == instead of is * Fix mypy
This commit is contained in:
parent
2616d4d55b
commit
25c8d7ef9a
@ -69,7 +69,7 @@ def _validate_schema(schema: Dict[str, Any]) -> None:
|
||||
raise ValueError(f"StateSchema: 'type' for key '{param}' must be a Python type, got {definition['type']}")
|
||||
if definition.get("handler") is not None and not callable(definition["handler"]):
|
||||
raise ValueError(f"StateSchema: 'handler' for key '{param}' must be callable or None")
|
||||
if param == "messages" and definition["type"] is not List[ChatMessage]:
|
||||
if param == "messages" and definition["type"] != List[ChatMessage]:
|
||||
raise ValueError(f"StateSchema: 'messages' must be of type List[ChatMessage], got {definition['type']}")
|
||||
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ def _is_valid_type(obj: Any) -> bool:
|
||||
False
|
||||
"""
|
||||
# Handle Union types (including Optional)
|
||||
if hasattr(obj, "__origin__") and obj.__origin__ is Union:
|
||||
if hasattr(obj, "__origin__") and obj.__origin__ == Union:
|
||||
return True
|
||||
|
||||
# Handle normal classes and generic types
|
||||
@ -45,7 +45,7 @@ def _is_list_type(type_hint: Any) -> bool:
|
||||
:param type_hint: The type hint to check
|
||||
:return: True if the type hint represents a list, False otherwise
|
||||
"""
|
||||
return type_hint is list or (hasattr(type_hint, "__origin__") and get_origin(type_hint) is list)
|
||||
return type_hint == list or (hasattr(type_hint, "__origin__") and get_origin(type_hint) == list)
|
||||
|
||||
|
||||
def merge_lists(current: Union[List[T], T, None], new: Union[List[T], T]) -> List[T]:
|
||||
|
||||
@ -422,7 +422,7 @@ class HuggingFaceLocalChatGenerator:
|
||||
replies = [o.get("generated_text", "") for o in output]
|
||||
|
||||
# Remove stop words from replies if present
|
||||
for stop_word in stop_words:
|
||||
for stop_word in stop_words or []:
|
||||
replies = [reply.replace(stop_word, "").rstrip() for reply in replies]
|
||||
|
||||
chat_messages = [
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fix type comparison in schema validation by replacing `is not` with `!=` when checking the type `List[ChatMessage]`.
|
||||
This prevents false mismatches due to Python's `is` operator comparing object identity instead of equality.
|
||||
Loading…
x
Reference in New Issue
Block a user