Skip to content

Commit

Permalink
Refactor langflow processing and langfuse callback initialization (#1413
Browse files Browse the repository at this point in the history
)

Update version to 0.6.7a2 in pyproject.toml

This pull request includes the following changes:

- Refactoring of langflow processing and langfuse callback initialization

- Updating the version to 0.6.7a2 in pyproject.toml
  • Loading branch information
ogabrielluiz authored Feb 9, 2024
2 parents 33d05a2 + 33dc1b9 commit fd55d50
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langflow"
version = "0.6.7a1"
version = "0.6.7a2"
description = "A Python package with a built-in web application"
authors = ["Logspace <[email protected]>"]
maintainers = [
Expand Down
8 changes: 5 additions & 3 deletions src/backend/langflow/processing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

from langchain.agents.agent import AgentExecutor
from langchain.callbacks.base import BaseCallbackHandler
from loguru import logger

from langflow.api.v1.callback import AsyncStreamingLLMCallbackHandler, StreamingLLMCallbackHandler
from langflow.processing.process import fix_memory_inputs, format_actions
from langflow.services.deps import get_plugins_service
from loguru import logger
from langflow.processing.process import fix_memory_inputs, format_actions
from langflow.services.deps import get_plugins_service

if TYPE_CHECKING:
from langfuse.callback import CallbackHandler # type: ignore
Expand All @@ -28,13 +31,12 @@ def setup_callbacks(sync, trace_id, **kwargs):

def get_langfuse_callback(trace_id):
from langflow.services.deps import get_plugins_service
from langfuse.callback import CreateTrace

logger.debug("Initializing langfuse callback")
if langfuse := get_plugins_service().get("langfuse"):
logger.debug("Langfuse credentials found")
try:
trace = langfuse.trace(CreateTrace(name="langflow-" + trace_id, id=trace_id))
trace = langfuse.trace(name="langflow-" + trace_id, id=trace_id)
return trace.getNewHandler()
except Exception as exc:
logger.error(f"Error initializing langfuse callback: {exc}")
Expand Down
3 changes: 1 addition & 2 deletions src/backend/langflow/services/plugins/langfuse_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ def get(self):
def get_callback(self, _id: Optional[str] = None):
if _id is None:
_id = "default"
from langfuse.callback import CreateTrace # type: ignore

logger.debug("Initializing langfuse callback")

try:
langfuse_instance = self.get()
if langfuse_instance is not None and hasattr(langfuse_instance, "trace"):
trace = langfuse_instance.trace(CreateTrace(name="langflow-" + _id, id=_id))
trace = langfuse_instance.trace(name="langflow-" + _id, id=_id)
if trace:
return trace.getNewHandler()

Expand Down

0 comments on commit fd55d50

Please sign in to comment.