Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aieng-agents/aieng/agents/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ class Configs(BaseSettings):
"""

model_config = SettingsConfigDict(
env_file=".env", env_file_encoding="utf-8", env_ignore_empty=True
env_file=".env",
env_file_encoding="utf-8",
env_ignore_empty=True,
extra="ignore",
)

openai_base_url: str = "https://generativelanguage.googleapis.com/v1beta/openai/"
Expand Down
19 changes: 18 additions & 1 deletion aieng-agents/aieng/agents/langfuse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
"""Utilities for Langfuse integration."""

from typing import TYPE_CHECKING

from aieng.agents.langfuse.oai_sdk_setup import setup_langfuse_tracer
from aieng.agents.langfuse.otlp_env_setup import set_up_langfuse_otlp_env_vars
from aieng.agents.langfuse.shared_client import flush_langfuse, langfuse_client
from aieng.agents.langfuse.shared_client import flush_langfuse
from langfuse import Langfuse


if TYPE_CHECKING:
from langfuse import Langfuse
Comment thread
fcogidi marked this conversation as resolved.
Outdated

langfuse_client: "Langfuse" # noqa: F822 -- lazily initialized via __getattr__


def __getattr__(name: str) -> "Langfuse":
if name == "langfuse_client":
from aieng.agents.langfuse.shared_client import _manager # noqa: PLC0415

return _manager.client
raise AttributeError(f"module has no attribute '{name}'")


__all__ = [
Expand Down
36 changes: 28 additions & 8 deletions aieng-agents/aieng/agents/langfuse/shared_client.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
"""Shared instance of langfuse client."""

from functools import cached_property

from aieng.agents.env_vars import Configs
from langfuse import Langfuse
from rich.progress import Progress, SpinnerColumn, TextColumn


__all__ = ["flush_langfuse", "langfuse_client"]
class _LangfuseClientManager:
@cached_property
def config(self) -> Configs:
return Configs()

@cached_property
def client(self) -> Langfuse:
return Langfuse(
public_key=self.config.langfuse_public_key,
secret_key=self.config.langfuse_secret_key,
)


_manager = _LangfuseClientManager()
langfuse_client: Langfuse # noqa: F822 -- lazily initialized via __getattr__

config = Configs()
langfuse_client = Langfuse(
public_key=config.langfuse_public_key, secret_key=config.langfuse_secret_key
)

def __getattr__(name: str) -> Langfuse:
"""Module-level lazy loading for backward compatibility."""
if name == "langfuse_client":
return _manager.client
raise AttributeError(f"module has no attribute '{name}'")

def flush_langfuse(client: "Langfuse | None" = None) -> None:

def flush_langfuse(client: Langfuse | None = None) -> None:
"""Flush shared LangFuse Client. Rich Progress included."""
if client is None:
client = langfuse_client
client = _manager.client

with Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
transient=True,
) as progress:
progress.add_task("Finalizing Langfuse annotations...", total=None)
langfuse_client.flush()
client.flush()


__all__ = ["flush_langfuse", "langfuse_client"]
2 changes: 1 addition & 1 deletion aieng-agents/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "aieng-agents"
version = "0.1.0"
version = "0.1.1"
description = "Helper modules for Vector Institute AI Engineering Agents Bootcamp implementations"
authors = [{name = "Vector AI Engineering", email = "ai_engineering@vectorinstitute.ai"}]
requires-python = ">=3.12"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [ {name = "Vector AI Engineering", email = "ai_engineering@vectorinsti
license = "MIT"
requires-python = ">=3.12"
dependencies = [
"aieng-agents>=0.1.0",
"aieng-agents>=0.1.1",
"numpy<2.3.0",
"plotly>=6.2.0",
"scikit-learn>=1.7.0",
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading