Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,11 @@ import json
|
|
| 3 |
import uuid
|
| 4 |
from langfuse import Langfuse
|
| 5 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
os.environ["LANGFUSE_PUBLIC_KEY"] = os.getenv('LANGFUSE_PUBLIC_KEY')
|
| 8 |
os.environ["LANGFUSE_SECRET_KEY"] = os.getenv('LANGFUSE_SECRET_KEY')
|
|
@@ -24,12 +29,6 @@ def set_new_session_id():
|
|
| 24 |
# Initialize
|
| 25 |
set_new_session_id()
|
| 26 |
|
| 27 |
-
# Langfuse decorator
|
| 28 |
-
from langfuse.decorators import observe, langfuse_context
|
| 29 |
-
# Optional: automated instrumentation via OpenAI SDK integration
|
| 30 |
-
# See note above regarding alternative implementations
|
| 31 |
-
from langfuse.openai import openai
|
| 32 |
-
|
| 33 |
# Global reference for the current trace_id which is used to later add user feedback
|
| 34 |
current_trace_id = None
|
| 35 |
|
|
@@ -60,9 +59,9 @@ async def create_response(
|
|
| 60 |
# Get completion via OpenAI SDK
|
| 61 |
# Auto-instrumented by Langfuse via the import, see alternative in note above
|
| 62 |
response = {"role": "assistant", "content": ""}
|
| 63 |
-
oai_response =
|
| 64 |
messages=history,
|
| 65 |
-
model="
|
| 66 |
)
|
| 67 |
response["content"] = oai_response.choices[0].message.content or ""
|
| 68 |
|
|
|
|
| 3 |
import uuid
|
| 4 |
from langfuse import Langfuse
|
| 5 |
import os
|
| 6 |
+
# Langfuse decorator
|
| 7 |
+
from langfuse.decorators import observe, langfuse_context
|
| 8 |
+
# Optional: automated instrumentation via OpenAI SDK integration
|
| 9 |
+
# See note above regarding alternative implementations
|
| 10 |
+
from langfuse.openai import openai, OpenAI
|
| 11 |
|
| 12 |
os.environ["LANGFUSE_PUBLIC_KEY"] = os.getenv('LANGFUSE_PUBLIC_KEY')
|
| 13 |
os.environ["LANGFUSE_SECRET_KEY"] = os.getenv('LANGFUSE_SECRET_KEY')
|
|
|
|
| 29 |
# Initialize
|
| 30 |
set_new_session_id()
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# Global reference for the current trace_id which is used to later add user feedback
|
| 33 |
current_trace_id = None
|
| 34 |
|
|
|
|
| 59 |
# Get completion via OpenAI SDK
|
| 60 |
# Auto-instrumented by Langfuse via the import, see alternative in note above
|
| 61 |
response = {"role": "assistant", "content": ""}
|
| 62 |
+
oai_response = client.chat.completions.create(
|
| 63 |
messages=history,
|
| 64 |
+
model="tgi",
|
| 65 |
)
|
| 66 |
response["content"] = oai_response.choices[0].message.content or ""
|
| 67 |
|