File size: 1,163 Bytes
ee74471
 
 
 
 
 
 
3525314
 
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
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')
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 and return the personal banking product from the top 5 search results"""
    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 best serve this customer needs, pain points: {customer}")
    return prediction.product