mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
testing - use in memory langfuse client cache
This commit is contained in:
parent
b201402b0b
commit
c44e5a3d93
1 changed files with 17 additions and 5 deletions
|
@ -4,6 +4,7 @@ import json
|
|||
import logging
|
||||
import os
|
||||
import sys
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
@ -19,17 +20,28 @@ import time
|
|||
|
||||
import pytest
|
||||
|
||||
in_memory_langfuse_client: dict[str, Any] = {}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def langfuse_client():
|
||||
import langfuse
|
||||
|
||||
langfuse_client = langfuse.Langfuse(
|
||||
public_key=os.environ["LANGFUSE_PUBLIC_KEY"],
|
||||
secret_key=os.environ["LANGFUSE_SECRET_KEY"],
|
||||
host=None,
|
||||
_langfuse_cache_key = (
|
||||
f"{os.environ['LANGFUSE_PUBLIC_KEY']}-{os.environ['LANGFUSE_SECRET_KEY']}"
|
||||
)
|
||||
print("NEW LANGFUSE CLIENT")
|
||||
# use a in memory langfuse client for testing, RAM util on ci/cd gets too high when we init many langfuse clients
|
||||
if _langfuse_cache_key in in_memory_langfuse_clients:
|
||||
langfuse_client = in_memory_langfuse_clients[_langfuse_cache_key]
|
||||
else:
|
||||
langfuse_client = langfuse.Langfuse(
|
||||
public_key=os.environ["LANGFUSE_PUBLIC_KEY"],
|
||||
secret_key=os.environ["LANGFUSE_SECRET_KEY"],
|
||||
host=None,
|
||||
)
|
||||
in_memory_langfuse_clients[_langfuse_cache_key] = langfuse_client
|
||||
|
||||
print("NEW LANGFUSE CLIENT")
|
||||
|
||||
with patch(
|
||||
"langfuse.Langfuse", MagicMock(return_value=langfuse_client)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue