angry-meow commited on
Commit
954011f
·
1 Parent(s): b210243

tavily search agent

Browse files
Files changed (2) hide show
  1. graph.py +6 -19
  2. prompts.py +9 -11
graph.py CHANGED
@@ -25,24 +25,11 @@ qdrant_research_chain = (
25
  )
26
 
27
  # Web Search Agent Pieces
28
- tavily_tool = TavilySearchResults(max_results=5)
29
- web_search_chain = (
30
- {
31
- "topic": itemgetter("topic"),
32
- "qdrant_results": itemgetter("qdrant_results"),
33
- }
34
- | prompts.search_query_prompt
35
- | models.gpt4o_mini
36
- | StrOutputParser()
37
- | tavily_tool
38
- | {
39
- "topic": itemgetter("topic"),
40
- "qdrant_results": itemgetter("qdrant_results"),
41
- "search_results": RunnablePassthrough()
42
- }
43
- | prompts.summarize_prompt
44
- | models.gpt4o_mini
45
- | StrOutputParser()
46
  )
47
 
48
  def query_qdrant(state: State) -> State:
@@ -65,7 +52,7 @@ def web_search(state: State) -> State:
65
  qdrant_results = state["research_data"].get("qdrant_results", "No previous results available.")
66
 
67
  # Run the web search chain
68
- result = web_search_chain.invoke({
69
  "topic": topic,
70
  "qdrant_results": qdrant_results
71
  })
 
25
  )
26
 
27
  # Web Search Agent Pieces
28
+ tavily_tool = TavilySearchResults(max_results=3)
29
+ query_chain = ( prompts.search_query_prompt | models.gpt4o_mini | StrOutputParser() )
30
+ tavily_simple = ({"tav_results": tavily_tool} | prompts.tavily_prompt | models.gpt4o_mini | StrOutputParser())
31
+ tavily_chain = (
32
+ {"query": query_chain} | tavily_simple
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  )
34
 
35
  def query_qdrant(state: State) -> State:
 
52
  qdrant_results = state["research_data"].get("qdrant_results", "No previous results available.")
53
 
54
  # Run the web search chain
55
+ result = tavily_chain.invoke({
56
  "topic": topic,
57
  "qdrant_results": qdrant_results
58
  })
prompts.py CHANGED
@@ -48,18 +48,16 @@ search_query_prompt = ChatPromptTemplate.from_template(
48
  """
49
  )
50
 
51
- # Create a prompt for summarizing the search results
52
- summarize_prompt = ChatPromptTemplate.from_template(
53
- """Summarize the following search results, focusing on information that is complementary to what we already know from our database. Include sources for each piece of information:
54
 
55
- Topic: {topic}
56
-
57
- Information from our database:
58
- {qdrant_results}
59
-
60
- Search results:
61
- {search_results}
62
 
63
- Complementary summary with sources:
 
 
 
 
 
64
  """
65
  )
 
48
  """
49
  )
50
 
51
+ tavily_prompt = ChatPromptTemplate.from_template(
52
+ """Summarize the query results into the following format:
 
53
 
54
+ Query results: {tav_results}
 
 
 
 
 
 
55
 
56
+ Output:
57
+ Search Result 1 source: ...
58
+ Search Result 1 summary: ...
59
+ Search Result 2 source: ...
60
+ Search Result 2 summary: ...
61
+ ...
62
  """
63
  )