-
Notifications
You must be signed in to change notification settings - Fork 77
[Testing] LangfusePromptDataset and LangfuseTraceDataset #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c23ad1b
test draft based on the design suggestion
ravi-kumar-pilla 645caf5
version and label added
ravi-kumar-pilla d5b6127
address prompt dataset comments
ravi-kumar-pilla 5ca57df
minimal cred entry for openAI and langchain
ravi-kumar-pilla 78aa16c
local first works fine
ravi-kumar-pilla 253ab34
remote sync working fine
ravi-kumar-pilla ee0cf2c
update docstrings
ravi-kumar-pilla 2a5dcc4
update trace dataset usage
ravi-kumar-pilla 2f329ec
resolve PR comments
ravi-kumar-pilla a67b228
update doc strings
ravi-kumar-pilla ab1c35a
working draft of trace dataset
ravi-kumar-pilla 2fd5e37
address PR comments on trace ds
ravi-kumar-pilla 30e7515
made host optional for langfuse
ravi-kumar-pilla 7dd0451
added PR suggestions
ravi-kumar-pilla 6c1b7dd
removed message formatting
ravi-kumar-pilla 6406914
tested text
ravi-kumar-pilla 9b0f76d
Revert "removed message formatting"
ravi-kumar-pilla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
61 changes: 61 additions & 0 deletions
61
kedro-agentic-workflows/src/kedro_agentic_workflows/datasets/langfuse_trace_dataset.py
This file contains hidden or 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,61 @@ | ||
| from typing import Any, Literal | ||
|
|
||
| from kedro.io import AbstractDataset | ||
| from langfuse import Langfuse | ||
|
|
||
|
|
||
| class LangfuseTraceDataset(AbstractDataset): | ||
| """ | ||
| Kedro dataset for managing Langfuse tracing clients and callbacks. | ||
| Returns appropriate tracing objects based on mode configuration. | ||
| Modes: | ||
| - langchain: Returns CallbackHandler for LangChain integration | ||
| - openai: Returns wrapped OpenAI client with automatic tracing | ||
| - sdk: Returns raw Langfuse client for manual tracing | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| credentials: dict[str, Any], | ||
| mode: Literal["langchain", "openai", "sdk"] = "sdk", | ||
| **trace_kwargs | ||
| ): | ||
| """ | ||
| Args: | ||
| credentials: Dict with Langfuse credentials {public_key, secret_key, host}. | ||
| mode: Tracing mode - "langchain", "openai", or "sdk". | ||
| **trace_kwargs: Additional kwargs passed to the tracing client. | ||
| """ | ||
| self._credentials = credentials | ||
| self._mode = mode | ||
| self._trace_kwargs = trace_kwargs | ||
|
|
||
| def _describe(self): | ||
| return {"mode": self._mode, "credentials": "***"} | ||
|
|
||
| def load(self): | ||
| """ | ||
| Load appropriate tracing client based on mode. | ||
| Returns: | ||
| - langchain mode: CallbackHandler for LangChain callbacks | ||
| - openai mode: Wrapped OpenAI client with tracing | ||
| - sdk mode: Raw Langfuse client | ||
| """ | ||
| if self._mode == "langchain": | ||
ElenaKhaustova marked this conversation as resolved.
Show resolved
Hide resolved
ElenaKhaustova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from langfuse.langchain import CallbackHandler | ||
| return CallbackHandler() | ||
| elif self._mode == "openai": | ||
| from langfuse.openai import OpenAI | ||
| return OpenAI() | ||
| else: | ||
| return Langfuse( | ||
| public_key=self._credentials["public_key"], | ||
| secret_key=self._credentials["secret_key"], | ||
| host=self._credentials["host"] | ||
| ) | ||
|
|
||
| def save(self, data): | ||
| """Tracing datasets are read-only.""" | ||
| raise NotImplementedError("LangfuseTraceDataset is read-only - it provides tracing clients, not data storage") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.