Version: 1.0 Date: February 22, 2025 Prepared by: Grok 3 (xAI)
The Food Order Bot is a conversational AI system designed to handle food ordering via a web interface. The system leverages Gradio for the frontend and FastAPI for the backend, integrating with the Mistral LLM for natural language processing and tool calls. It enables users to log in, browse menus, place orders, and manage their orders dynamically. The system supports persistent order storage in SQLite, configuration management, and a modular code structure with linting and formatting standards.
This document outlines all changes and enhancements made to the project up to February 22, 2025, including architecture, functionality, and implementation details.
Primary Goal: Develop a user-friendly food ordering system that processes natural language inputs via an LLM, leveraging APIs and Python functions for backend logic.
Secondary Goals:
gradio_client.py
provides a chat interface for users to interact via text or voice, communicating with the backend via API calls.mock_server.py
handles API endpoints for login, menu retrieval, order management, and processing user queries through order_processor.py
.llm.py
uses the Mistral API for natural language understanding and tool calls to invoke backend functions or APIs.db.py
manages persistent storage using SQLite for sessions and orders.config.py
centralizes configuration via .env
for environment-specific settings.logging_config.py
for logging, api.py
for API client helpers, and models.py
for Pydantic models.gradio_client.py
sends requests to /process_order
in mock_server.py
.mock_server.py
calls process_order
in order_processor.py
, which invokes process_with_tools
in llm.py
for LLM processing.execute_tool_call
in order_processor.py
.execute_tool_call
executes the tool (e.g., API calls to /login
, /menu
, or internal functions like display_menu
).db.py
, logged, and returned to Gradio for display.orders.py
to provide user-friendly error messages.gradio_app.py
to show restaurant menus.orders.py
.test_api.py
for core functionality..env
in logging_config.py
.mock_server.py
’s in-memory ORDERS to SQLite in db.py
, adding save_order
and load_order
./orders/{order_id}
in mock_server.py
for order retrieval.config.py
to load settings from .env
, centralizing SECRET_KEY
, BASE_URL
, etc.mock_server.py
, db.py
, api.py
, etc., with config imports.gradio_client.py
, making API calls to mock_server.py
.mock_server.py
and order_processor.py
, exposing /process_order
for all commands..flake8
for PEP 8 compliance, resolving recursion errors by splitting logic.llm.py
with Mistral for tool calls (e.g., login, add_to_order), replacing hardcoded logic in order_processor.py
.models.py
to resolve import cycles.llm.py
to use synchronous client.chat.complete
in an async context, fixing MistralAsync import errors.llm.py
tools and order_processor.py
to handle multi-city (list_cities, list_restaurants), price constraints (add_to_order), and natural language queries.add_to_order
handles “1 butter idli” correctly.llm.py
to map inputs to existing Python functions/API endpoints (e.g., login to /login
, add_to_order to /process_order
).order_processor.py
and llm.py
for robust operation.login <username> <password>
logs in via /login
, storing token in session.menu
or list restaurants
shows available items via show_menu
.1 butter idli
or add 2 ghee paddu from Rameshwaram Cafe
use add_to_order
.show order
, remove <item>
, review order
, confirm
, cancel
via respective tools.which cities are available?
or provide restaurants in Bengaluru
via list_cities
and list_restaurants
..env
manage settings.food_order_bot.log
for debugging.project/
├── config.py
├── logging_config.py
├── db.py
├── api.py
├── llm.py
├── models.py
├── order_processor.py
├── mock_server.py
├── gradio_client.py
├── restaurants.json
├── .env
├── .flake8
└── tests/
/login
, /menu
, /orders
, /process_order
./process_order
..env
.pip install fastapi uvicorn pydantic mistralai requests httpx gradio sqlite3 black flake8 tenacity
Install dependencies:
pip install -r requirements.txt
(Create requirements.txt
with listed dependencies if not present.)
Configure .env
:
SECRET_KEY=your-secret-key
MISTRAL_API_KEY=your-mistral-api-key
DB_FILE=zomato_orders.db
BASE_URL=http://localhost:7861
MENU_FILE=restaurants.json
LOG_FILE=food_order_bot.log
LOG_LEVEL=INFO
Start the FastAPI server:
uvicorn mock_server:app --host 0.0.0.0 --port 7861
Start the Gradio client:
python gradio_client.py
Interact via the Gradio interface:
login user1 password123
.1 butter idli
or add 2 ghee paddu from Rameshwaram Cafe
.show order
, remove butter idli
, confirm
, etc.Run linting:
flake8 .
Run formatting:
black .
**Test functionality with Gradio and verify logs in food_order_bot.log
.
/orders/history
endpoint and Gradio command to list past orders.\n
rendering in Gradio for line breaks.mock_server.py
.restaurants.json
and logic for real city-based filtering.\n
(displays as text instead of line breaks).$
in restaurants.json
(currently assumed 1:1 or adjusted manually).This Spec 4 document provides a comprehensive overview of the Food Order Bot’s current state, changes, and usage. Let me know if you’d like to expand on any section, add diagrams, or include specific test cases!