haystack/test/components/generators/test_openai_utils.py
Stefano Fiorucci ea3602643a
feat!: new ChatMessage (#8640)
* draft

* del HF token in tests

* adaptations

* progress

* fix type

* import sorting

* more control on deserialization

* release note

* improvements

* support name field

* fix chatpromptbuilder test

* Update chat_message.py

---------

Co-authored-by: Daria Fokina <daria.fokina@deepset.ai>
2024-12-17 17:02:04 +01:00

17 lines
649 B
Python

# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
import pytest
from haystack.dataclasses import ChatMessage
from haystack.components.generators.openai_utils import _convert_message_to_openai_format
def test_convert_message_to_openai_format():
message = ChatMessage.from_system("You are good assistant")
assert _convert_message_to_openai_format(message) == {"role": "system", "content": "You are good assistant"}
message = ChatMessage.from_user("I have a question")
assert _convert_message_to_openai_format(message) == {"role": "user", "content": "I have a question"}