-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OPIK-770] Fix haystack integration (#1070)
* Put error details closer to the beginning of error messages to simplify sentry logs review * Fix haystack bug * Remove version restriction in integration test for haystack * Fix lint errors
- Loading branch information
1 parent
e835dfd
commit 79501b1
Showing
5 changed files
with
42 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import functools | ||
import importlib.metadata | ||
from typing import Any, Dict | ||
|
||
import haystack.dataclasses | ||
import haystack.version | ||
|
||
from opik import semantic_version | ||
|
||
|
||
def convert_message_to_openai_format( | ||
message: haystack.dataclasses.ChatMessage, | ||
) -> Dict[str, Any]: | ||
if _haystack_version_less_than_2_9_0(): | ||
# 2.8.1 and less use _convert_message_to_openai_format function | ||
from haystack.components.generators.openai import ( | ||
_convert_message_to_openai_format, | ||
) | ||
|
||
return _convert_message_to_openai_format(message=message) | ||
else: | ||
# 2.9.0 introduced to_openai_dict_format | ||
return message.to_openai_dict_format() | ||
|
||
|
||
@functools.lru_cache | ||
def _haystack_version_less_than_2_9_0() -> bool: | ||
haystack_version = importlib.metadata.version("haystack-ai") | ||
result = semantic_version.SemanticVersion.parse(haystack_version) < "2.9.0" # type: ignore | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sdks/python/tests/library_integration/haystack/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
haystack-ai<2.9.0 # 2.9.0 broke our imports, we need to fix it! https://github.com/comet-ml/opik/issues/1047 | ||
haystack-ai |