In [ ]:
from dotenv import load_dotenv
load_dotenv()
In [ ]:
import os
from langchain.chat_models import init_chat_model
DEEPSEEK_MODEL = "deepseek-chat"
DEEPSEEK_BASE_URL = "https://api.deepseek.com"
def deepseek_model(model: str = DEEPSEEK_MODEL, max_tokens=1000, **kwargs):
return init_chat_model(
model=model,
# DeepSeek uses LangChain's OpenAI-compatible transport.
model_provider="openai",
api_key=os.environ["DEEPSEEK_API_KEY"],
base_url=DEEPSEEK_BASE_URL,
max_tokens=max_tokens,
**kwargs,
)
In [ ]:
from langchain.tools import tool
from typing import Dict, Any
from tavily import TavilyClient
tavily_client = TavilyClient()
@tool
def web_search(query: str) -> Dict[str, Any]:
"""Search the web for information"""
return tavily_client.search(query)
In [ ]:
system_prompt = """
You are a personal chef. The user will give you a list of ingredients they have left over in their house.
Using the web search tool, search the web for recipes that can be made with the ingredients they have.
Return recipe suggestions and eventually the recipe instructions to the user, if requested.
"""
In [ ]:
from langchain.agents import create_agent
from langgraph.checkpoint.memory import InMemorySaver
agent = create_agent(
model=deepseek_model(),
tools=[web_search],
system_prompt=system_prompt,
checkpointer=InMemorySaver()
)
In [ ]:
from langchain.messages import HumanMessage
config = {"configurable": {"thread_id": "1"}}
response = agent.invoke(
{"messages": [HumanMessage(content="I have some leftover chicken and rice. What can I make?")]},
config
)
print(response['messages'][-1].content)
In [ ]:
from pprint import pprint
pprint(response)
In [ ]: