Skip to content

Instantly share code, notes, and snippets.

@jgoodie
Created November 4, 2024 04:40
Show Gist options
  • Save jgoodie/f2ada087d3e4c784bc1253e8490b2906 to your computer and use it in GitHub Desktop.
Save jgoodie/f2ada087d3e4c784bc1253e8490b2906 to your computer and use it in GitHub Desktop.
Function to summarize Tavily search results
def TavilySummary(state):
# Get state
context = state["context"]
question = state["question"]
# Template
answer_template = """
You are a competitive research analytist helping a team of product managers conduct competitive market research.
Answer the research question:
{question}
using this context:
{context}
"""
answer_instructions = answer_template.format(question=question, context=context)
# Answer
answer = llm.invoke([SystemMessage(content=answer_instructions)]+[HumanMessage(content=f"Answer the research question.")])
# Append it to state
return {"answer": answer}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment