hanshan1988 commited on
Commit
2d72111
·
1 Parent(s): ae79440

fixed langfuse flush function

Browse files
Files changed (1) hide show
  1. agent.py +4 -4
agent.py CHANGED
@@ -3,6 +3,8 @@ from typing import TypedDict, List, Dict, Any, Optional, Annotated
3
  from functools import partial
4
  import os
5
  import re
 
 
6
 
7
  # from langchain_openai import ChatOpenAI
8
  # from langchain_huggingface.llms import HuggingFaceEndpoint
@@ -197,8 +199,6 @@ class BasicAgent:
197
  print(f"Agent received question (first 100 chars): {question[:100]}...")
198
 
199
  # Create a new Langfuse handler for this specific question to ensure separate traces
200
- import time
201
- import uuid
202
  handler = CallbackHandler()
203
 
204
  # Generate unique identifiers for this trace
@@ -229,8 +229,8 @@ class BasicAgent:
229
  response_text = response['messages'][-1].content
230
  answer = extract_answer(response_text)
231
 
232
- # Flush the handler to ensure the trace is sent to Langfuse
233
- handler.flush()
234
 
235
  print(f"Trace logged for task_id: {task_id}")
236
 
 
3
  from functools import partial
4
  import os
5
  import re
6
+ import time
7
+ import uuid
8
 
9
  # from langchain_openai import ChatOpenAI
10
  # from langchain_huggingface.llms import HuggingFaceEndpoint
 
199
  print(f"Agent received question (first 100 chars): {question[:100]}...")
200
 
201
  # Create a new Langfuse handler for this specific question to ensure separate traces
 
 
202
  handler = CallbackHandler()
203
 
204
  # Generate unique identifiers for this trace
 
229
  response_text = response['messages'][-1].content
230
  answer = extract_answer(response_text)
231
 
232
+ # Flush the langfuse client to ensure the trace is sent immediately
233
+ langfuse.flush()
234
 
235
  print(f"Trace logged for task_id: {task_id}")
236