|
import os |
|
import dspy |
|
|
|
from dspy.predict.react import Tool |
|
from tavily import TavilyClient |
|
|
|
|
|
|
|
|
|
lm = dspy.LM('groq/qwen-qwq-32b') |
|
dspy.configure(lm=lm) |
|
|
|
search_client = TavilyClient(api_key=os.environ["T_TOKEN"]) |
|
|
|
INST="""Recommend banking financial product based on verbatim""" |
|
def web_search(query: str) -> list[str]: |
|
"""Run a web search to return the top 3 personal banking product that satisfy the query""" |
|
response = search_client.search(query) |
|
return [r["content"] for r in response["results"]] |
|
|
|
agent = dspy.ReAct("verbatim -> product", tools=[Tool(web_search)]) |
|
|
|
customer="Low APR and great customer service. I would highly recommend if you’re looking for a great credit card company and looking to rebuild your credit. I have had my credit limit increased annually and the annual fee is very low." |
|
|
|
def rival_product(customer:str): |
|
prediction = agent(verbatim=f"Which banking product name best serve this customer needs: {customer}") |
|
return prediction.product |