Skip to content

karolk75/Cookidoo-Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cookidoo Agent

Cookidoo Agent is a sophisticated Python application that integrates the OpenAI API, Milvus vector database, and the Cookidoo API to fetch, process, and search for recipes based on natural language queries. This project is designed with modern Python best practices including asynchronous programming, modular architecture, and type hinting to deliver an impressive and efficient solution.

Table of Contents

Overview

Cookidoo Agent allows you to:

  • Fetch recipes asynchronously from the Cookidoo API.
  • Process recipes by generating condensed text representations.
  • Compute embeddings for these representations using OpenAI’s text-embedding-3-small model.
  • Store and index recipes in a Milvus vector database.
  • Search recipes via vector similarity and generate human-readable responses using OpenAI ChatGPT.

This application is ideal for demonstrating advanced Python programming, asynchronous I/O, and integration of multiple external APIs and services.

Features

  • Asynchronous Operations: Utilizes asyncio and aiohttp for efficient network operations.
  • Advanced API Integrations: Leverages OpenAI for both text embeddings and chat-based completions.
  • Vector Search: Uses Milvus for fast, scalable similarity searches on recipe embeddings.
  • Modular Codebase: Clear separation of concerns with well-structured packages and modules.
  • Comprehensive Logging & Error Handling: Centralized configuration ensures clear diagnostics.

Project Structure

cookidoo_agent/
├── __init__.py
├── config.py               # Central configuration (logging, env variables, API keys)
├── main.py                 # Entry point for CLI commands (query & load)
├── load_database.py        # Module for fetching and loading recipes into Milvus
├── query_recipe.py         # Module for processing queries and generating responses
├── utils.py                # Utility functions (e.g., embedding generation)
└── cookidoo/
    ├── __init__.py         # Cookidoo API integration
    ├── helpers.py          # Helper functions for localization
    └── types.py            # Domain models & dataclasses for recipe data
.env
.gitignore
requirements.txt
README.md

Prerequisites

  • Python 3.8+ (recommended)
  • A running Milvus instance (configured with host/port as specified in the .env)
  • A valid OpenAI API key
  • Internet connectivity (to access external APIs)

Installation

  1. Clone the repository
git clone https://github.com/karolk75/cookidoo-agent.git
cd cookidoo_agent
  1. Create a Virtual Environment
python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate
  1. Install Dependencies
pip install -r requirements.txt
  1. Configure Environment Variables Create a .env file (use .example.env) in the project root with the following content:
OPENAI_API_KEY=
MILVUS_HOST=
MILVUS_PORT=

Configuration

All configuration is centralized in cookidoo_agent/config.py:

  • OpenAI API Key: Loaded from the .env file.
  • Milvus Connection: Host and port are configurable via environment variables.
  • Logging: Configured to provide timestamped output with a consistent format.

Modify these settings as needed to match your environment.

Usage

The project provides two main functionalities:

Loading Recipes into Milvus

Load recipes from the Cookidoo API into the Milvus vector database. This command fetches recipes in batches, processes them, computes embeddings, and stores them.

Run the load command with:

python -m cookidoo_agent.main --command load

Note: This is fetching only Polish recipies. Adjust cookidoo.init.py file if needed

Querying Recipes

Query recipes by providing a natural language query. This will:

  • Extract key search criteria using ChatGPT.
  • Compute embeddings for the refined query.
  • Search the Milvus database for similar recipes.
  • Generate a human-readable answer with ChatGPT.
  • Run the query command as follows:
python -m cookidoo_agent.main --command query --query "Wyszukaj mi trzy przepisy na obiad, w których składniki są podobne (żeby kupić jak najmniej rzeczy)"

If you omit the --query argument, a test query is executed.

Contributing

Contributions are welcome! If you have ideas, bug fixes, or enhancements, please open an issue or submit a pull request. Follow the existing code style and documentation practices.

About

Python application integrating OpenAI, Milvus vector DB, and Cookidoo API for natural language recipe search using embeddings and ChatGPT

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors