import os | |
import dspy | |
from dspy.predict.react import Tool | |
from tavily import TavilyClient | |
#lm = dspy.LM('ollama_chat/llama3.2', 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/llama-3.1-8b-instant', api_base='https://api.groq.com/openai/v1', api_key=os.environ["GROQ_API_KEY"]) | |
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 | |
if __name__ == '__main__': | |
print(rival_product(customer)) |