llm-recipes

Specification Document (Spec 4) for Food Order Bot Project

Version: 1.0 Date: February 22, 2025 Prepared by: Grok 3 (xAI)


1. Overview

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.


2. Objectives

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:


3. System Architecture

3.1 Components

3.2 Data Flow

  1. User Input: User inputs text/voice in Gradio.
  2. Request Handling: gradio_client.py sends requests to /process_order in mock_server.py.
  3. Order Processing: mock_server.py calls process_order in order_processor.py, which invokes process_with_tools in llm.py for LLM processing.
  4. Tool Call Execution: The LLM identifies tool calls (e.g., login, add_to_order) and returns them to execute_tool_call in order_processor.py.
  5. API Calls: execute_tool_call executes the tool (e.g., API calls to /login, /menu, or internal functions like display_menu).
  6. Storage and Logging: Responses are stored in SQLite via db.py, logged, and returned to Gradio for display.

3.3 Dependencies


4. Changes and Enhancements (Chronological)

4.1 Initial Setup (Step 1–5)

4.2 Persistent Storage (Step 6)

4.3 Config Management (Step 7)

4.4 Split UX and Server Logic (Step 8)

4.5 Linting and Formatting (Step 9)

4.6 LLM with Tool Calls (Step 10–11)

4.7 Enhanced Tool Calls (Step 12–13)

4.8 Current State (February 22, 2025)


5. Functionality

5.1 User Interactions

5.2 Technical Features


6. Implementation Details

6.1 Directory Structure

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/

6.2 Key Files

6.3 Dependencies

pip install fastapi uvicorn pydantic mistralai requests httpx gradio sqlite3 black flake8 tenacity

7. Usage Instructions

7.1 Setup

  1. Clone the repository or create the project structure above.
  2. Install dependencies:

     pip install -r requirements.txt
    

    (Create requirements.txt with listed dependencies if not present.)

  3. 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
    

7.2 Running the Application

  1. Start the FastAPI server:

     uvicorn mock_server:app --host 0.0.0.0 --port 7861
    
  2. Start the Gradio client:

     python gradio_client.py
    
  3. Interact via the Gradio interface:

    • Log in with login user1 password123.
    • Order with 1 butter idli or add 2 ghee paddu from Rameshwaram Cafe.
    • Manage orders with show order, remove butter idli, confirm, etc.

7.3 Testing

  1. Run linting:

     flake8 .
    
  2. Run formatting:

     black .
    
  3. **Test functionality with Gradio and verify logs in food_order_bot.log.


8. Future Enhancements


9. Known Issues


10. Contact Information


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!