Repository navigation
Expand file tree
/
Copy pathexample19.py
More file actions
57 lines (43 loc) · 1.39 KB
/
Copy pathexample19.py
File metadata and controls
57 lines (43 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Author: L. Saetta
Last modified: 2026-03-20
License: MIT
Description:
This example shows how-to integrate with Langfuse to track the request.
"""
import os
from langfuse.openai import openai as langfuse_openai
from langfuse import get_client
from common import (
get_inference_client,
print_example_summary,
print_runtime_config,
)
from config import MODEL_ID, LANGFUSE_BASE_URL
from config_private import LANGFUSE_SECRET_KEY, LANGFUSE_PUBLIC_KEY
# integration with langfuse
os.environ["LANGFUSE_SECRET_KEY"] = LANGFUSE_SECRET_KEY
os.environ["LANGFUSE_PUBLIC_KEY"] = LANGFUSE_PUBLIC_KEY
os.environ["LANGFUSE_HOST"] = LANGFUSE_BASE_URL
def main() -> None:
"""Simple LLM call with Langfuse integration."""
print_runtime_config()
print("")
print_example_summary("Simple non-streaming call with integration with Langfuse.")
print("")
# Use Langfuse OpenAI wrapper so requests are instrumented and traced.
client = get_inference_client(client_class=langfuse_openai.OpenAI)
request = "Tell me about G. Parisi and his work on Spin Glasses?"
response = client.responses.create(
model=MODEL_ID,
temperature=0.0,
input=request,
)
print("Request:", request)
print(response.output_text)
print("")
# Flush via global LangFuse client
langfuse = get_client()
langfuse.flush()
if __name__ == "__main__":
main()