langfuse-haystack 5.0.2__tar.gz → 5.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/CHANGELOG.md +7 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/PKG-INFO +1 -1
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/example/basic_rag.py +4 -2
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/example/chat.py +2 -1
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/src/haystack_integrations/components/connectors/langfuse/langfuse_connector.py +12 -6
- langfuse_haystack-5.1.0/tests/conftest.py +11 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/tests/test_langfuse_connector.py +37 -8
- langfuse_haystack-5.0.2/src/haystack_integrations/components/connectors/__init__.py +0 -3
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/.gitignore +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/LICENSE.txt +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/README.md +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/example/requirements.txt +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/pydoc/config_docusaurus.yml +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/pyproject.toml +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/src/haystack_integrations/components/connectors/langfuse/__init__.py +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/src/haystack_integrations/components/connectors/py.typed +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/src/haystack_integrations/tracing/langfuse/__init__.py +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/src/haystack_integrations/tracing/langfuse/tracer.py +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/src/haystack_integrations/tracing/py.typed +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/tests/__init__.py +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/tests/test_tracer.py +0 -0
- {langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/tests/test_tracing.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: langfuse-haystack
|
|
3
|
-
Version: 5.0
|
|
3
|
+
Version: 5.1.0
|
|
4
4
|
Summary: Langfuse integration for Haystack
|
|
5
5
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/langfuse#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
@@ -6,12 +6,15 @@ os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
|
|
|
6
6
|
from datasets import load_dataset
|
|
7
7
|
from haystack import Document, Pipeline
|
|
8
8
|
from haystack.components.builders import PromptBuilder
|
|
9
|
-
from haystack.components.embedders import SentenceTransformersDocumentEmbedder, SentenceTransformersTextEmbedder
|
|
10
9
|
from haystack.components.generators import OpenAIGenerator
|
|
11
10
|
from haystack.components.retrievers import InMemoryEmbeddingRetriever
|
|
12
11
|
from haystack.document_stores.in_memory import InMemoryDocumentStore
|
|
13
12
|
|
|
14
13
|
from haystack_integrations.components.connectors.langfuse import LangfuseConnector
|
|
14
|
+
from haystack_integrations.components.embedders.sentence_transformers import (
|
|
15
|
+
SentenceTransformersDocumentEmbedder,
|
|
16
|
+
SentenceTransformersTextEmbedder,
|
|
17
|
+
)
|
|
15
18
|
|
|
16
19
|
|
|
17
20
|
def get_pipeline(document_store: InMemoryDocumentStore):
|
|
@@ -54,7 +57,6 @@ if __name__ == "__main__":
|
|
|
54
57
|
document_store = InMemoryDocumentStore()
|
|
55
58
|
dataset = load_dataset("bilgeyucel/seven-wonders", split="train")
|
|
56
59
|
embedder = SentenceTransformersDocumentEmbedder("sentence-transformers/all-MiniLM-L6-v2")
|
|
57
|
-
embedder.warm_up()
|
|
58
60
|
docs_with_embeddings = embedder.run([Document(**ds) for ds in dataset]).get("documents") or [] # type: ignore
|
|
59
61
|
document_store.write_documents(docs_with_embeddings)
|
|
60
62
|
|
|
@@ -9,7 +9,7 @@ os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
|
|
|
9
9
|
|
|
10
10
|
from haystack import Pipeline
|
|
11
11
|
from haystack.components.builders import ChatPromptBuilder
|
|
12
|
-
from haystack.components.generators.chat import
|
|
12
|
+
from haystack.components.generators.chat import OpenAIChatGenerator
|
|
13
13
|
from haystack.dataclasses import ChatMessage
|
|
14
14
|
from haystack.utils.auth import Secret
|
|
15
15
|
from haystack.utils.hf import HFGenerationAPIType
|
|
@@ -17,6 +17,7 @@ from haystack.utils.hf import HFGenerationAPIType
|
|
|
17
17
|
from haystack_integrations.components.connectors.langfuse import LangfuseConnector
|
|
18
18
|
from haystack_integrations.components.generators.anthropic import AnthropicChatGenerator
|
|
19
19
|
from haystack_integrations.components.generators.cohere import CohereChatGenerator
|
|
20
|
+
from haystack_integrations.components.generators.huggingface_api import HuggingFaceAPIChatGenerator
|
|
20
21
|
|
|
21
22
|
os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
|
|
22
23
|
|
|
@@ -6,11 +6,11 @@ from typing import Any
|
|
|
6
6
|
|
|
7
7
|
import httpx
|
|
8
8
|
from haystack import component, default_from_dict, default_to_dict, logging, tracing
|
|
9
|
-
from haystack.
|
|
10
|
-
from haystack.utils
|
|
11
|
-
from langfuse import Langfuse
|
|
9
|
+
from haystack.core.serialization import component_to_dict
|
|
10
|
+
from haystack.utils import Secret, deserialize_chatgenerator_inplace, deserialize_secrets_inplace
|
|
12
11
|
|
|
13
12
|
from haystack_integrations.tracing.langfuse import LangfuseTracer, SpanHandler
|
|
13
|
+
from langfuse import Langfuse
|
|
14
14
|
|
|
15
15
|
logger = logging.getLogger(__name__)
|
|
16
16
|
|
|
@@ -198,7 +198,7 @@ class LangfuseConnector:
|
|
|
198
198
|
|
|
199
199
|
:returns: The serialized component as a dictionary.
|
|
200
200
|
"""
|
|
201
|
-
span_handler =
|
|
201
|
+
span_handler = component_to_dict(self.span_handler, "span_handler") if self.span_handler else None
|
|
202
202
|
if self.langfuse_client_kwargs:
|
|
203
203
|
# pop httpx_client and mask from self._langfuse_client_kwargs to prevent serialization issues
|
|
204
204
|
langfuse_client_kwargs = {
|
|
@@ -228,6 +228,12 @@ class LangfuseConnector:
|
|
|
228
228
|
"""
|
|
229
229
|
init_params = data["init_parameters"]
|
|
230
230
|
deserialize_secrets_inplace(init_params, keys=["secret_key", "public_key"])
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
span_handler_data = init_params.get("span_handler")
|
|
232
|
+
if span_handler_data is not None:
|
|
233
|
+
if "data" in span_handler_data:
|
|
234
|
+
# Pipelines serialized before this fix wrap the span handler as
|
|
235
|
+
# {"type": ..., "data": {"type": ..., "init_parameters": ...}}; unwrap it here so older
|
|
236
|
+
# serialized pipelines keep working.
|
|
237
|
+
init_params["span_handler"] = span_handler_data["data"]
|
|
238
|
+
deserialize_chatgenerator_inplace(init_params, key="span_handler")
|
|
233
239
|
return default_from_dict(cls, data)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@pytest.fixture(autouse=True)
|
|
5
|
+
def allow_deserialization_of_test_modules(monkeypatch):
|
|
6
|
+
"""
|
|
7
|
+
haystack-ai >= 3.0 refuses to deserialize classes and callables from modules outside its
|
|
8
|
+
trusted-module allowlist. Tools and callbacks defined in the test modules live outside that
|
|
9
|
+
allowlist, so trust them explicitly; haystack-ai 2.x ignores this environment variable.
|
|
10
|
+
"""
|
|
11
|
+
monkeypatch.setenv("HAYSTACK_DESERIALIZATION_ALLOWLIST", "tests,test_*")
|
|
@@ -104,10 +104,7 @@ class TestLangfuseConnector:
|
|
|
104
104
|
},
|
|
105
105
|
"span_handler": {
|
|
106
106
|
"type": "tests.test_langfuse_connector.CustomSpanHandler",
|
|
107
|
-
"
|
|
108
|
-
"type": "tests.test_langfuse_connector.CustomSpanHandler",
|
|
109
|
-
"init_parameters": {},
|
|
110
|
-
},
|
|
107
|
+
"init_parameters": {},
|
|
111
108
|
},
|
|
112
109
|
"host": "https://example.com",
|
|
113
110
|
"langfuse_client_kwargs": {"timeout": 30.0},
|
|
@@ -199,10 +196,7 @@ class TestLangfuseConnector:
|
|
|
199
196
|
},
|
|
200
197
|
"span_handler": {
|
|
201
198
|
"type": "tests.test_langfuse_connector.CustomSpanHandler",
|
|
202
|
-
"
|
|
203
|
-
"type": "tests.test_langfuse_connector.CustomSpanHandler",
|
|
204
|
-
"init_parameters": {},
|
|
205
|
-
},
|
|
199
|
+
"init_parameters": {},
|
|
206
200
|
},
|
|
207
201
|
"host": "https://example.com",
|
|
208
202
|
"langfuse_client_kwargs": {"timeout": 30.0},
|
|
@@ -218,6 +212,41 @@ class TestLangfuseConnector:
|
|
|
218
212
|
assert langfuse_connector.host == "https://example.com"
|
|
219
213
|
assert langfuse_connector.langfuse_client_kwargs == {"timeout": 30.0}
|
|
220
214
|
|
|
215
|
+
def test_from_dict_with_legacy_span_handler_format(self, monkeypatch):
|
|
216
|
+
# Pipelines serialized before this fix wrap span_handler as {"type": ..., "data": {...}}
|
|
217
|
+
monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
|
|
218
|
+
monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "public")
|
|
219
|
+
|
|
220
|
+
data = {
|
|
221
|
+
"type": "haystack_integrations.components.connectors.langfuse.langfuse_connector.LangfuseConnector",
|
|
222
|
+
"init_parameters": {
|
|
223
|
+
"name": "Chat example - OpenAI",
|
|
224
|
+
"public": True,
|
|
225
|
+
"secret_key": {
|
|
226
|
+
"type": "env_var",
|
|
227
|
+
"env_vars": ["LANGFUSE_SECRET_KEY"],
|
|
228
|
+
"strict": True,
|
|
229
|
+
},
|
|
230
|
+
"public_key": {
|
|
231
|
+
"type": "env_var",
|
|
232
|
+
"env_vars": ["LANGFUSE_PUBLIC_KEY"],
|
|
233
|
+
"strict": True,
|
|
234
|
+
},
|
|
235
|
+
"span_handler": {
|
|
236
|
+
"type": "tests.test_langfuse_connector.CustomSpanHandler",
|
|
237
|
+
"data": {
|
|
238
|
+
"type": "tests.test_langfuse_connector.CustomSpanHandler",
|
|
239
|
+
"init_parameters": {},
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
"host": "https://example.com",
|
|
243
|
+
"langfuse_client_kwargs": {"timeout": 30.0},
|
|
244
|
+
},
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
langfuse_connector = LangfuseConnector.from_dict(data)
|
|
248
|
+
assert isinstance(langfuse_connector.span_handler, CustomSpanHandler)
|
|
249
|
+
|
|
221
250
|
def test_pipeline_serialization(self, monkeypatch):
|
|
222
251
|
# Set test env vars
|
|
223
252
|
monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{langfuse_haystack-5.0.2 → langfuse_haystack-5.1.0}/src/haystack_integrations/tracing/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|