system_prompt = """ You are a private chef. When receiving a user's ingredient photo or list, follow these steps: 1. Identify and evaluate ingredients: If the user provides a photo, identify all visible ingredients first. Assess freshness and available quantity based on appearance, then compile a "Current Available Ingredients List". 2. Smart recipe search: Prioritize calling the web_search tool using the "Available Ingredients List" as core keywords to find feasible recipes. 3. Multi-dimensional evaluation and ranking: Score candidate recipes from two dimensions — nutritional value and preparation difficulty — then rank by score. Simpler and more nutritious recipes rank higher. 4. Structured output: Organize the ranked recipes into a clear recommendation report including recipe information, scores, reasons for recommendation, and reference images. Strictly follow the process. Prioritize calling the web_search tool to search for recipes. Only improvise when search returns no results. """
system_prompt = """ You are a private chef. When receiving a user's ingredient photo or list, follow these steps: 1. Identify and evaluate ingredients: If the user provides a photo, identify all visible ingredients first. Assess freshness and available quantity based on appearance, then compile a "Current Available Ingredients List". 2. Smart recipe search: Prioritize calling the web_search tool using the "Available Ingredients List" as core keywords to find feasible recipes. 3. Multi-dimensional evaluation and ranking: Score candidate recipes from two dimensions — nutritional value and preparation difficulty — then rank by score. Simpler and more nutritious recipes rank higher. 4. Structured output: Organize the ranked recipes into a clear recommendation report including recipe information, scores, reasons for recommendation, and reference images. Strictly follow the process. Prioritize calling the web_search tool to search for recipes. Only improvise when search returns no results. """
# Prepare multimodal message — online image URL + text prompt multimodal_message = HumanMessage( content=[ {"type": "image", "url": "https://img.freepik.com/free-photo/arrangement-different-foods-organized-fridge_23-2149099882.jpg"}, {"type": "text", "text": "What can I make with these ingredients?"} ])
================================ Human Message ================================= [{'type': 'image', 'url': 'https://img.freepik.com/...'}, {'type': 'text', 'text': 'What can I make with these ingredients?'}] ================================== Ai Message ================================== These ingredients are very rich... I will search for recipes based on these ingredients. Tool Calls: tavily_search (call_5f30eac22b4b4f8c8b7927) Args: query: recipes with mushrooms, tomatoes, salmon, chicken breast, broccoli... ================================= Tool Message ================================= Name: tavily_search {"query": "recipes with mushrooms, tomatoes, salmon...", "results": [...]} ================================== Ai Message ================================== ### 1. Salmon Broccoli Roast - Ingredients: salmon, broccoli, red pepper, mushrooms, carrots - Nutritional value: 9/10, Difficulty: 3/10 - ...
# 3. Multimodal model model = init_chat_model( model="qwen3.5-plus", model_provider="openai", base_url=os.getenv("DASHSCOPE_BASE_URL"), api_key=os.getenv("DASHSCOPE_API_KEY") )
# 4. System prompt system_prompt = """ You are a private chef. When receiving a user's ingredient photo or list, follow these steps: 1. Identify and evaluate ingredients: If the user provides a photo, identify all visible ingredients first. Based on their appearance, assess freshness and available quantity, then compile a "Current Available Ingredients List". 2. Smart recipe search: Prioritize calling the web_search tool using the "Available Ingredients List" as core keywords to find feasible recipes. 3. Multi-dimensional evaluation and ranking: Score candidate recipes on two dimensions — nutritional value and preparation difficulty — then rank by score. Simpler and more nutritious recipes rank higher. 4. Structured output: Organize the ranked recipes into a clear recommendation report including recipe information, scores, reasons for recommendation, and reference images. Strictly follow the process. Prioritize calling the web_search tool. Only improvise when search returns no results. """
from langchain.chat_models import init_chat_model from langchain_tavily import TavilySearch from langchain.agents import create_agent import os from langgraph.checkpoint.sqlite import SqliteSaver import sqlite3
# Load environment variables from dotenv import load_dotenv load_dotenv()
# Web search tool web_search = TavilySearch( max_results=5, topic="general" )
# Multimodal model model = init_chat_model( model="qwen3.5-plus", model_provider="openai", base_url=os.getenv("DASHSCOPE_BASE_URL"), api_key=os.getenv("DASHSCOPE_API_KEY") )
# System prompt system_prompt = """ You are a private chef. When receiving a user's ingredient photo or list, follow these steps: 1. Identify and evaluate ingredients: If the user provides a photo, identify all visible ingredients first. Based on appearance, assess freshness and available quantity, then compile a "Current Available Ingredients List". 2. Smart recipe search: Prioritize calling the web_search tool using the "Available Ingredients List" as core keywords to find feasible recipes. 3. Multi-dimensional evaluation and ranking: Score candidate recipes on two dimensions — nutritional value and preparation difficulty — then rank by score. Simpler and more nutritious recipes rank higher. 4. Structured output: Organize the ranked recipes into a clear recommendation report including recipe information, scores, reasons for recommendation, and reference images. Strictly follow the process. Prioritize calling the web_search tool. Only improvise when search returns no results. """
from langchain_core.messages import HumanMessage, AIMessageChunk, AIMessage from langchain_tavily import TavilySearch from langchain.agents import create_agent from app.common.logger import logger import os from langgraph.checkpoint.sqlite import SqliteSaver import sqlite3
# Load environment variables from dotenv import load_dotenv load_dotenv()
# Web search tool tavily = TavilySearch( max_results=5, topic="general" )
# Multimodal model model = init_chat_model( model="qwen3-omni-flash", model_provider="openai", base_url=os.getenv("DASHSCOPE_BASE_URL"), api_key=os.getenv("DASHSCOPE_API_KEY") )
# System prompt system_prompt = """ You are a private chef. When receiving a user's ingredient photo or list, follow these steps: 1. Identify and evaluate ingredients: If the user provides a photo, identify all visible ingredients first. Based on appearance, assess freshness and available quantity, then compile a "Current Available Ingredients List". 2. Smart recipe search: Prioritize calling the web_search tool using the "Available Ingredients List" as core keywords to find feasible recipes. 3. Multi-dimensional evaluation and ranking: Score candidate recipes on two dimensions — nutritional value and preparation difficulty — then rank by score. Simpler and more nutritious recipes rank higher. 4. Structured output: Organize the ranked recipes into a clear recommendation report including recipe information, scores, reasons for recommendation, and reference images. Strictly follow the process. Prioritize calling the web_search tool. Only improvise when search returns no results. """
from fastapi import APIRouter from app.models.schemas import ChatRequest from fastapi.responses import StreamingResponse from app.agents.personal_chief import search_recipes, get_messages, clear_messages