langfuse-haystack 0.0.1__tar.gz → 0.0.3__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-0.0.1 → langfuse_haystack-0.0.3}/PKG-INFO +7 -6
- langfuse_haystack-0.0.3/README.md +22 -0
- {langfuse_haystack-0.0.1 → langfuse_haystack-0.0.3}/example/basic_rag.py +1 -1
- langfuse_haystack-0.0.3/example/chat.py +33 -0
- langfuse_haystack-0.0.3/example/requirements.txt +3 -0
- langfuse_haystack-0.0.3/src/haystack_integrations/components/others/langfuse/__about__.py +1 -0
- langfuse_haystack-0.0.3/src/haystack_integrations/components/others/langfuse/__init__.py +3 -0
- langfuse_haystack-0.0.1/src/haystack_integrations/components/others/langfuse/langfuse.py → langfuse_haystack-0.0.3/src/haystack_integrations/components/others/langfuse/component.py +0 -1
- {langfuse_haystack-0.0.1 → langfuse_haystack-0.0.3}/src/haystack_integrations/tracing/langfuse/tracer.py +29 -4
- langfuse_haystack-0.0.1/README.md +0 -21
- langfuse_haystack-0.0.1/example/requirements.txt +0 -2
- langfuse_haystack-0.0.1/src/haystack_integrations/components/others/langfuse/__about__.py +0 -1
- langfuse_haystack-0.0.1/src/haystack_integrations/components/others/langfuse/__init__.py +0 -3
- {langfuse_haystack-0.0.1 → langfuse_haystack-0.0.3}/.gitignore +0 -0
- {langfuse_haystack-0.0.1 → langfuse_haystack-0.0.3}/LICENSE.txt +0 -0
- {langfuse_haystack-0.0.1 → langfuse_haystack-0.0.3}/pyproject.toml +0 -0
- {langfuse_haystack-0.0.1 → langfuse_haystack-0.0.3}/src/haystack_integrations/tracing/langfuse/__init__.py +0 -0
- {langfuse_haystack-0.0.1 → langfuse_haystack-0.0.3}/tests/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: langfuse-haystack
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/langfuse#readme
|
|
5
5
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
6
6
|
Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/langfuse
|
|
@@ -23,20 +23,21 @@ Description-Content-Type: text/markdown
|
|
|
23
23
|
|
|
24
24
|
# langfuse
|
|
25
25
|
|
|
26
|
-
[](https://pypi.org/project/langfuse)
|
|
27
|
-
[](https://pypi.org/project/langfuse)
|
|
26
|
+
[](https://pypi.org/project/langfuse-haystack)
|
|
27
|
+
[](https://pypi.org/project/langfuse-haystack)
|
|
28
28
|
|
|
29
29
|
-----
|
|
30
30
|
|
|
31
31
|
**Table of Contents**
|
|
32
32
|
|
|
33
|
-
- [
|
|
34
|
-
- [
|
|
33
|
+
- [langfuse](#langfuse)
|
|
34
|
+
- [Installation](#installation)
|
|
35
|
+
- [License](#license)
|
|
35
36
|
|
|
36
37
|
## Installation
|
|
37
38
|
|
|
38
39
|
```console
|
|
39
|
-
pip install langfuse
|
|
40
|
+
pip install langfuse-haystack
|
|
40
41
|
```
|
|
41
42
|
|
|
42
43
|
## License
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# langfuse
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/langfuse-haystack)
|
|
4
|
+
[](https://pypi.org/project/langfuse-haystack)
|
|
5
|
+
|
|
6
|
+
-----
|
|
7
|
+
|
|
8
|
+
**Table of Contents**
|
|
9
|
+
|
|
10
|
+
- [langfuse](#langfuse)
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [License](#license)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```console
|
|
17
|
+
pip install langfuse-haystack
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
`langfuse` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.
|
|
@@ -41,7 +41,7 @@ def get_pipeline(document_store: InMemoryDocumentStore):
|
|
|
41
41
|
)
|
|
42
42
|
basic_rag_pipeline.add_component("retriever", retriever)
|
|
43
43
|
basic_rag_pipeline.add_component("prompt_builder", prompt_builder)
|
|
44
|
-
basic_rag_pipeline.add_component("llm", OpenAIGenerator(model="gpt-3.5-turbo"))
|
|
44
|
+
basic_rag_pipeline.add_component("llm", OpenAIGenerator(model="gpt-3.5-turbo", generation_kwargs={"n": 2}))
|
|
45
45
|
|
|
46
46
|
# Now, connect the components to each other
|
|
47
47
|
# NOTE: the tracer component doesn't need to be connected to anything in order to work
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
os.environ["LANGFUSE_HOST"] = "https://cloud.langfuse.com"
|
|
4
|
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
5
|
+
os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
|
|
6
|
+
|
|
7
|
+
from haystack.components.builders import DynamicChatPromptBuilder
|
|
8
|
+
from haystack.components.generators.chat import OpenAIChatGenerator
|
|
9
|
+
from haystack.dataclasses import ChatMessage
|
|
10
|
+
from haystack import Pipeline
|
|
11
|
+
from haystack.utils import Secret
|
|
12
|
+
|
|
13
|
+
from haystack_integrations.components.others.langfuse import LangfuseComponent
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
|
|
18
|
+
pipe = Pipeline()
|
|
19
|
+
pipe.add_component("tracer", LangfuseComponent("Chat example"))
|
|
20
|
+
pipe.add_component("prompt_builder", DynamicChatPromptBuilder())
|
|
21
|
+
pipe.add_component("llm", OpenAIChatGenerator(model="gpt-3.5-turbo"))
|
|
22
|
+
|
|
23
|
+
pipe.connect("prompt_builder.prompt", "llm.messages")
|
|
24
|
+
|
|
25
|
+
messages = [
|
|
26
|
+
ChatMessage.from_system("Always respond in German even if some input data is in other languages."),
|
|
27
|
+
ChatMessage.from_user("Tell me about {{location}}"),
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
response = pipe.run(
|
|
31
|
+
data={"prompt_builder": {"template_variables": {"location": "Berlin"}, "prompt_source": messages}}
|
|
32
|
+
)
|
|
33
|
+
print(response["llm"]["replies"][0])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.3"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import contextlib
|
|
2
2
|
from typing import Any, Dict, Iterator, Optional, Union
|
|
3
3
|
|
|
4
|
-
from haystack.lazy_imports import LazyImport
|
|
5
4
|
from haystack.tracing import Span, Tracer, tracer
|
|
6
5
|
from haystack.tracing import utils as tracing_utils
|
|
7
6
|
|
|
@@ -11,19 +10,32 @@ import langfuse
|
|
|
11
10
|
class LangfuseSpan(Span):
|
|
12
11
|
def __init__(self, span: "Union[langfuse.client.StatefulSpanClient, langfuse.client.StatefulTraceClient]") -> None:
|
|
13
12
|
self._span = span
|
|
13
|
+
# locally cache tags
|
|
14
|
+
self._data = {}
|
|
14
15
|
|
|
15
16
|
def set_tag(self, key: str, value: Any) -> None:
|
|
16
17
|
coerced_value = tracing_utils.coerce_tag_value(value)
|
|
17
18
|
self._span.update(metadata={key: coerced_value})
|
|
19
|
+
self._data[key] = value
|
|
18
20
|
|
|
19
21
|
def set_content_tag(self, key: str, value: Any) -> None:
|
|
20
22
|
if not tracer.is_content_tracing_enabled:
|
|
21
23
|
return
|
|
22
24
|
|
|
23
25
|
if key.endswith(".input"):
|
|
24
|
-
|
|
26
|
+
if "messages" in value:
|
|
27
|
+
messages = [m.to_openai_format() for m in value["messages"]]
|
|
28
|
+
self._span.update(input=messages)
|
|
29
|
+
else:
|
|
30
|
+
self._span.update(input=value)
|
|
25
31
|
elif key.endswith(".output"):
|
|
26
|
-
|
|
32
|
+
if "replies" in value:
|
|
33
|
+
replies = [m.to_openai_format() for m in value["replies"]]
|
|
34
|
+
self._span.update(output=replies)
|
|
35
|
+
else:
|
|
36
|
+
self._span.update(output=value)
|
|
37
|
+
|
|
38
|
+
self._data[key] = value
|
|
27
39
|
|
|
28
40
|
def raw_span(self) -> Any:
|
|
29
41
|
return self._span
|
|
@@ -43,7 +55,7 @@ class LangfuseTracer(Tracer):
|
|
|
43
55
|
tags = tags or {}
|
|
44
56
|
span_name = tags.get("haystack.component.name", operation_name)
|
|
45
57
|
|
|
46
|
-
if tags.get("haystack.component.type") in ["OpenAIGenerator"]:
|
|
58
|
+
if tags.get("haystack.component.type") in ["OpenAIGenerator", "OpenAIChatGenerator"]:
|
|
47
59
|
span = LangfuseSpan(self.current_span().raw_span().generation(name=span_name))
|
|
48
60
|
else:
|
|
49
61
|
span = LangfuseSpan(self.current_span().raw_span().span(name=span_name))
|
|
@@ -53,6 +65,19 @@ class LangfuseTracer(Tracer):
|
|
|
53
65
|
|
|
54
66
|
yield span
|
|
55
67
|
|
|
68
|
+
if tags.get("haystack.component.type") == "OpenAIGenerator":
|
|
69
|
+
meta = span._data.get("haystack.component.output", {}).get("meta")
|
|
70
|
+
if meta:
|
|
71
|
+
# Haystack returns one meta dict for each message, but the 'usage' value
|
|
72
|
+
# is always the same, let's just pick the first item
|
|
73
|
+
m = meta[0]
|
|
74
|
+
span._span.update(usage=m.get("usage"), model=m.get("model"))
|
|
75
|
+
elif tags.get("haystack.component.type") == "OpenAIChatGenerator":
|
|
76
|
+
replies = span._data.get("haystack.component.output", {}).get("replies")
|
|
77
|
+
if replies:
|
|
78
|
+
meta = replies[0].meta
|
|
79
|
+
span._span.update(usage=meta.get("usage"), model=meta.get("model"))
|
|
80
|
+
|
|
56
81
|
span.raw_span().end()
|
|
57
82
|
self._context.pop()
|
|
58
83
|
self._tracer.flush()
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# langfuse
|
|
2
|
-
|
|
3
|
-
[](https://pypi.org/project/langfuse)
|
|
4
|
-
[](https://pypi.org/project/langfuse)
|
|
5
|
-
|
|
6
|
-
-----
|
|
7
|
-
|
|
8
|
-
**Table of Contents**
|
|
9
|
-
|
|
10
|
-
- [Installation](#installation)
|
|
11
|
-
- [License](#license)
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```console
|
|
16
|
-
pip install langfuse
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## License
|
|
20
|
-
|
|
21
|
-
`langfuse` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|