Martin Bär commited on
Commit
eaf9631
·
1 Parent(s): 8cb5d70

Add langfuse

Browse files
Files changed (3) hide show
  1. .gitignore +2 -1
  2. basic_agent.py +5 -0
  3. requirements.txt +2 -1
.gitignore CHANGED
@@ -1,3 +1,4 @@
1
  __pycache__
2
  .venv
3
- tool_tests.ipynb
 
 
1
  __pycache__
2
  .venv
3
+ tool_tests.ipynb
4
+ .env
basic_agent.py CHANGED
@@ -7,11 +7,15 @@ from llama_index.tools.wikipedia import WikipediaToolSpec
7
  from llama_index.core.tools.tool_spec.load_and_search import LoadAndSearchToolSpec
8
  from llama_index.readers.web import SimpleWebPageReader
9
  from llama_index.core.tools.ondemand_loader_tool import OnDemandLoaderTool
 
10
 
11
  class BasicAgent:
12
  def __init__(self):
13
  llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-Coder-32B-Instruct")
14
 
 
 
 
15
  # Initialize tools
16
  tool_spec = DuckDuckGoSearchToolSpec()
17
  search_tool = FunctionTool.from_defaults(tool_spec.duckduckgo_full_search)
@@ -47,4 +51,5 @@ class BasicAgent:
47
 
48
  async def __call__(self, question: str) -> str:
49
  response = await self.agent.run(user_msg=question) # ctx=self.ctx)
 
50
  return response.response.content
 
7
  from llama_index.core.tools.tool_spec.load_and_search import LoadAndSearchToolSpec
8
  from llama_index.readers.web import SimpleWebPageReader
9
  from llama_index.core.tools.ondemand_loader_tool import OnDemandLoaderTool
10
+ from langfuse.llama_index import LlamaIndexInstrumentor
11
 
12
  class BasicAgent:
13
  def __init__(self):
14
  llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-Coder-32B-Instruct")
15
 
16
+ # Langfuse
17
+ self.instrumentor = LlamaIndexInstrumentor()
18
+
19
  # Initialize tools
20
  tool_spec = DuckDuckGoSearchToolSpec()
21
  search_tool = FunctionTool.from_defaults(tool_spec.duckduckgo_full_search)
 
51
 
52
  async def __call__(self, question: str) -> str:
53
  response = await self.agent.run(user_msg=question) # ctx=self.ctx)
54
+ self.instrumentor.flush()
55
  return response.response.content
requirements.txt CHANGED
@@ -6,4 +6,5 @@ llama_index-tools-duckduckgo
6
  llama_index-tools-wikipedia
7
  llama-index-indices-managed-bge-m3
8
  llama-index-embeddings-huggingface
9
- llama-index-readers-web
 
 
6
  llama_index-tools-wikipedia
7
  llama-index-indices-managed-bge-m3
8
  llama-index-embeddings-huggingface
9
+ llama-index-readers-web
10
+ langfuse llama-index