Refactor langfuse plugin and add get_callback
method
This commit is contained in:
parent
f2389023ae
commit
26f84aa885
1 changed files with 23 additions and 4 deletions
|
|
@ -1,9 +1,8 @@
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from langflow.services.deps import get_settings_service
|
from langflow.services.deps import get_settings_service
|
||||||
from langflow.services.plugins.base import BasePlugin
|
from langflow.services.plugins.base import BasePlugin
|
||||||
from langflow.utils.logger import logger
|
from loguru import logger
|
||||||
|
|
||||||
### Temporary implementation
|
|
||||||
# This will be replaced by a plugin system once merged into 0.5.0
|
|
||||||
|
|
||||||
|
|
||||||
class LangfuseInstance:
|
class LangfuseInstance:
|
||||||
|
|
@ -61,3 +60,23 @@ class LangfusePlugin(BasePlugin):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return LangfuseInstance.get()
|
return LangfuseInstance.get()
|
||||||
|
|
||||||
|
def get_callback(self, _id: Optional[str] = None):
|
||||||
|
if _id is None:
|
||||||
|
_id = "default"
|
||||||
|
from langfuse.callback import CreateTrace
|
||||||
|
|
||||||
|
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))
|
||||||
|
if trace:
|
||||||
|
return trace.getNewHandler()
|
||||||
|
|
||||||
|
except Exception as exc:
|
||||||
|
logger.error(f"Error initializing langfuse callback: {exc}")
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue