• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

deepset-ai / haystack / 12066860315

28 Nov 2024 10:16AM UTC coverage: 90.307% (-0.05%) from 90.359%
12066860315

push

github

web-flow
refactor: update components to access `ChatMessage.text` instead of `content` (#8589)

* introduce text property and deprecate content

* release note

* use chatmessage.text

* release note

* linting

8031 of 8893 relevant lines covered (90.31%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
haystack/components/generators/openai_utils.py
1
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
2
#
3
# SPDX-License-Identifier: Apache-2.0
4

5
from typing import Dict
1✔
6

7
from haystack.dataclasses import ChatMessage
1✔
8

9

10
def _convert_message_to_openai_format(message: ChatMessage) -> Dict[str, str]:
1✔
11
    """
12
    Convert a message to the format expected by OpenAI's Chat API.
13

14
    See the [API reference](https://platform.openai.com/docs/api-reference/chat/create) for details.
15

16
    :returns: A dictionary with the following key:
17
        - `role`
18
        - `content`
19
        - `name` (optional)
20
    """
21
    if message.text is None:
1✔
22
        raise ValueError(f"The provided ChatMessage has no text. ChatMessage: {message}")
×
23

24
    openai_msg = {"role": message.role.value, "content": message.text}
1✔
25
    if message.name:
1✔
26
        openai_msg["name"] = message.name
1✔
27

28
    return openai_msg
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc