Skip to content

Commit

Permalink
refactor: Remove usage of deprecated ChatMessage.to_openai_format (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shadeMe authored Aug 16, 2024
1 parent 13cdaab commit 55c65af
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from typing import Any, Dict, Iterator, Optional, Union

from haystack.components.generators.openai_utils import _convert_message_to_openai_format
from haystack.dataclasses import ChatMessage
from haystack.tracing import Span, Tracer, tracer
from haystack.tracing import utils as tracing_utils
Expand Down Expand Up @@ -51,14 +52,14 @@ def set_content_tag(self, key: str, value: Any) -> None:
return
if key.endswith(".input"):
if "messages" in value:
messages = [m.to_openai_format() for m in value["messages"]]
messages = [_convert_message_to_openai_format(m) for m in value["messages"]]
self._span.update(input=messages)
else:
self._span.update(input=value)
elif key.endswith(".output"):
if "replies" in value:
if all(isinstance(r, ChatMessage) for r in value["replies"]):
replies = [m.to_openai_format() for m in value["replies"]]
replies = [_convert_message_to_openai_format(m) for m in value["replies"]]
else:
replies = value["replies"]
self._span.update(output=replies)
Expand Down

0 comments on commit 55c65af

Please sign in to comment.