haystack icon indicating copy to clipboard operation
haystack copied to clipboard

TypeError: Object of type PromptTemplate is not JSON serializable

Open muazhari opened this issue 1 year ago • 1 comments

Describe the bug Error when using this:

logging.basicConfig(format="%(levelname)s - %(name)s -  %(message)s", level=logging.WARNING)
logging.getLogger("haystack").setLevel(logging.DEBUG)
def get_online_generator(self, generator_body: GeneratorBody) -> PromptNode:
        prompt_template = PromptTemplate(
            prompt=generator_body.prompt,
            output_parser=AnswerParser()
        )

        generator: PromptNode = PromptNode(
            model_name_or_path=generator_body.generator_model.model,
            default_prompt_template=prompt_template,
            max_length=generator_body.answer_max_length,
            api_key=generator_body.generator_model.api_key,
            use_gpu=True,
        )
        return generator

Error message

DEBUG - haystack.telemetry -  Telemetry couldn't make a POST request to PostHog.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/haystack/telemetry.py", line 98, in send_event
    json.dumps({**self.event_properties, **dynamic_specs, **event_properties}, sort_keys=True)
  File "/usr/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type PromptTemplate is not JSON serializable
DEBUG - haystack.utils.openai_utils -  Using tiktoken cl100k_base tokenizer

Expected behavior No error shown.

Additional context

  • None.

To Reproduce Use a logger and PromptTemplate like the above.

FAQ Check

System: OS: Windows 11 GPU/CPU: RTX4090/i9-13900K Haystack version (commit or version number): https://github.com/deepset-ai/haystack/commit/2a45e7cc06bc74526907c4da38d647163dca0dd2 DocumentStore: - Reader: - Retriever: - Ranker: -

muazhari avatar Oct 21 '23 18:10 muazhari

Can you try disabling the telemetry as described in https://docs.haystack.deepset.ai/docs/telemetry#how-can-i-opt-out ?

masci avatar Dec 19 '23 08:12 masci