fix(langfuse.py): fix metadata logging for langfuse

This commit is contained in:
Krrish Dholakia 2023-11-30 13:45:26 -08:00
parent cc0df56bd6
commit a5c99d8594
2 changed files with 6 additions and 5 deletions

View File

@ -36,7 +36,7 @@ class LangFuseLogger:
print_verbose(
f"Langfuse Logging - Enters logging function for model {kwargs}"
)
metadata = kwargs.get("metadata", {})
metadata = kwargs["litellm_params"].get("metadata", {})
prompt = [kwargs.get('messages')]
optional_params = kwargs.get("optional_params", {})
@ -50,7 +50,6 @@ class LangFuseLogger:
pass
# end of processing langfuse ########################
self.Langfuse.generation(InitialGeneration(
name=metadata.get("generation_name", "litellm-completion"),
startTime=start_time,

View File

@ -22,7 +22,7 @@ def test_langfuse_logging_async():
messages=[{"role": "user", "content":"This is a test"}],
max_tokens=1000,
temperature=0.7,
timeout=5
timeout=5,
)
response = asyncio.run(_test_langfuse())
print(f"response: {response}")
@ -35,13 +35,15 @@ def test_langfuse_logging_async():
def test_langfuse_logging():
try:
# litellm.set_verbose = True
response = completion(model="claude-instant-1.2",
messages=[{
"role": "user",
"content": "Hi 👋 - i'm claude"
}],
max_tokens=10,
temperature=0.2
temperature=0.2,
metadata={"langfuse/key": "foo"}
)
print(response)
except litellm.Timeout as e:
@ -49,7 +51,7 @@ def test_langfuse_logging():
except Exception as e:
print(e)
# test_langfuse_logging()
test_langfuse_logging()
def test_langfuse_logging_stream():