Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AmazonBedrockChatGenerator de/serialization issue #684

Closed
FloRul opened this issue Apr 24, 2024 · 2 comments · Fixed by #685
Closed

AmazonBedrockChatGenerator de/serialization issue #684

FloRul opened this issue Apr 24, 2024 · 2 comments · Fixed by #685
Labels
bug Something isn't working integration:amazon-bedrock

Comments

@FloRul
Copy link
Contributor

FloRul commented Apr 24, 2024

Describe the bug

The serialize_callable function in callable_serialization.py throws an AttributeError when the callable_handle argument is None.

Error message
AttributeError: 'NoneType' object has no attribute 'name'
  File "~\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code      
    exec(code, run_globals)
  File "~test.py", line 21, in <module>
    main()
  File "~/test.py", line 14, in main
    yyy = p.dumps()
          ^^^^^^^^^
  File "~\AppData\Local\Programs\Python\Python311\Lib\site-packages\haystack\core\pipeline\pipeline.py", line 196, in dumps
    return marshaller.marshal(self.to_dict())
                              ^^^^^^^^^^^^^^
  File "~\AppData\Local\Programs\Python\Python311\Lib\site-packages\haystack\core\pipeline\pipeline.py", line 118, in to_dict
    components[name] = component_to_dict(instance)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~\AppData\Local\Programs\Python\Python311\Lib\site-packages\haystack\core\serialization.py", line 24, in component_to_dict
    return obj.to_dict()
           ^^^^^^^^^^^^^
  File "~\AppData\Local\Programs\Python\Python311\Lib\site-packages\haystack_integrations\components\generators\amazon_bedrock\chat\chat_generator.py", line 223, in to_dict
    streaming_callback=serialize_callable(self.streaming_callback),
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~\AppData\Local\Programs\Python\Python311\Lib\site-packages\haystack\utils\callable_serialization.py", line 20, in serialize_callable
    full_path = callable_handle.__name__
                ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__name__'. Did you mean: '__ne__'?
Expected behavior
The function should handle the case where callable_handle is None and raise a more descriptive error message. For example, it could raise a ValueError with the message "callable_handle must be a callable, not None".

Additional context

This issue occurs when trying to serialize a None value as a callable, which is not a valid operation.

to reproduce the behavior:

from haystack_integrations.components.generators.amazon_bedrock import (
    AmazonBedrockChatGenerator,
)
from haystack import Pipeline


def main():
    p = Pipeline()
    p.add_component(
        "generator",
        # can be any chat supported model
        AmazonBedrockChatGenerator(model="anthropic.claude-3-sonnet-20240229-v1:0"),
    )
    print(p.dumps())

if __name__ == "__main__":
    main()

FAQ Check
Have you had a look at our new FAQ page?

Yes

System:
OS: Windows
GPU/CPU: I7
Haystack version (commit or version number): Version: 2.0.1
amazon-bedrock-haystack version : 0.7.0

This might be affecting all the generator that uses the streaming_callable (cohere chat generator, ...)

@FloRul FloRul added the bug Something isn't working label Apr 24, 2024
@anakin87
Copy link
Member

Hey! Thanks for reporting the issue.

This is probably an oversight.
In fact, I see that we generally do that:

callback_name = serialize_callable(self.streaming_callback) if self.streaming_callback else None

Would you like to check if this works and open a simple PR to fix the issue?

If you can't, we will take care of it...

@anakin87
Copy link
Member

released a new version: https://pypi.org/project/amazon-bedrock-haystack/0.7.1/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working integration:amazon-bedrock
Projects
None yet
2 participants