File size: 1,188 Bytes
ee74471
 
 
 
 
 
 
3525314
ab83b05
93d1163
ee74471
 
 
 
 
 
dbb7591
ee74471
 
 
 
 
 
 
 
dbb7591
ee74471
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import dspy

from dspy.predict.react import Tool
from tavily import TavilyClient

#lm = dspy.LM('ollama_chat/deepseek-r1', api_base='http://localhost:11434', api_key='')
#lm = dspy.LM('huggingface/Qwen/Qwen2.5-Coder-32B-Instruct')
#lm = dspy.LM('huggingface/meta-llama/Llama-3.2-1B')
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