c56bef871b
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
from typing import Any
|
|
|
|
from haystack.core.errors import DeserializationError
|
|
from haystack.core.serialization import component_from_dict, import_class_by_name
|
|
|
|
|
|
def deserialize_chatgenerator_inplace(data: dict[str, Any], key: str = "chat_generator") -> None:
|
|
"""
|
|
Deserialize a ChatGenerator in a dictionary inplace.
|
|
|
|
:param data:
|
|
The dictionary with the serialized data.
|
|
:param key:
|
|
The key in the dictionary where the ChatGenerator is stored.
|
|
|
|
:raises DeserializationError:
|
|
If the key is missing in the serialized data, the value is not a dictionary,
|
|
the type key is missing, the class cannot be imported, or the class lacks a 'from_dict' method.
|
|
"""
|
|
deserialize_component_inplace(data, key=key)
|
|
|
|
|
|
def deserialize_component_inplace(data: dict[str, Any], key: str = "chat_generator") -> None:
|
|
"""
|
|
Deserialize a Component in a dictionary inplace.
|
|
|
|
:param data:
|
|
The dictionary with the serialized data.
|
|
:param key:
|
|
The key in the dictionary where the Component is stored. Default is "chat_generator".
|
|
|
|
:raises DeserializationError:
|
|
If the key is missing in the serialized data, the value is not a dictionary,
|
|
the type key is missing, the class cannot be imported, or the class lacks a 'from_dict' method.
|
|
"""
|
|
if key not in data:
|
|
raise DeserializationError(f"Missing '{key}' in serialization data")
|
|
|
|
serialized_component = data[key]
|
|
|
|
if not isinstance(serialized_component, dict):
|
|
raise DeserializationError(f"The value of '{key}' is not a dictionary")
|
|
|
|
if "type" not in serialized_component:
|
|
raise DeserializationError(f"Missing 'type' in {key} serialization data")
|
|
|
|
try:
|
|
component_class = import_class_by_name(serialized_component["type"])
|
|
except ImportError as e:
|
|
raise DeserializationError(f"Class '{serialized_component['type']}' not correctly imported") from e
|
|
|
|
data[key] = component_from_dict(cls=component_class, data=serialized_component, name=key)
|