Skip to main content

A Python client for the Passio Nutrition AI API

Project description

Nutrition AI

Nutrition AI is a Python module that interfaces with the Passio Nutrition AI API. It provides functionalities for food product information retrieval, food searching, and interaction with an AI nutrition advisor.

Features

  • Authentication with the Passio API
  • Fetching food product information by UPC, food ID, or reference code
  • Searching for foods by name
  • Interaction with an AI nutrition advisor, including:
    • Starting conversation threads
    • Sending messages and receiving responses
    • Handling complex queries requiring additional data
    • Utilizing content tool hints for enhanced responses
    • Visual food extraction from images

Installation

You can install the Nutrition AI module using pip:

pip install nutrition-ai

You will need an API key from Passio to use this module. If you do not have one, you can obtain one here

Configuration

Before using the module, you need to set up your Passio API key as an environment variable:

export PASSIO_API_KEY=your_api_key_here

Usage

We've included a Jupyter notebook here which shows how to use the Nutrition AI module.

Here are some examples of how to use the Nutrition AI module:

Authentication

from nutrition_ai import auth

header, expiry = auth.get_header_and_expiry_time()

Fetching Product Information

from nutrition_ai import fetch

# Fetch by UPC
product = fetch.product_by_upc('698241110109', header)

# Fetch by food ID
product = fetch.product_by_food_id('1603211317047', header)

# Fetch by reference code
product = fetch.product_by_refCode('your_ref_code', header)

Searching for Foods

from nutrition_ai import search

results = search.food_matching('pepperoni pizza', header=header, limit=5)

Interacting with the AI Advisor

from nutrition_ai.advisor import conversation, tools

# Start a conversation thread
thread_response = conversation.start_thread(header)

# Send a simple message
message_response = conversation.send_message(
    thread_response.threadId, 
    'what does vitamin C do, briefly?', 
    header
)

# Handle complex queries
complex_response = conversation.send_message(
    thread_response.threadId,
    'what do you think of my food logs this week?',
    header
)

if complex_response.dataRequest:
    log_response = tools.detect_meal_logs_required(
        complex_response.threadId,
        complex_response.messageId,
        complex_response.dataRequest.toolCallId,
        complex_response.dataRequest.runId,
        "21 Pizzas",
        header
    )

# Use content tool hints
if 'SearchIngredientMatches' in response.contentToolHints:
    search_response = tools.search_ingredient_matches(
        response.threadId,
        response.messageId,
        header
    )

# Visual food extraction
from PIL import Image

img = Image.open("path/to/your/image.jpg").resize((512, 512))
response = tools.visual_food_extraction(
    thread_response.threadId,
    img,
    message="what did I have for lunch?",
    header=header
)

Running Tests

To run the unit tests for this module:

  1. Ensure you have set the PASSIO_API_KEY environment variable.
  2. Run the following command from the root of the project:
python -m unittest tests/test_nutrition_ai.py

License

MIT

Contact

For any queries or support, please contact james@passiolife.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nutrition_ai-0.1.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nutrition_ai-0.1.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file nutrition_ai-0.1.1.tar.gz.

File metadata

  • Download URL: nutrition_ai-0.1.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Darwin/23.6.0

File hashes

Hashes for nutrition_ai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dd9b5a98596c701bb2bf00dc21466f8f0d17ba98438997144f28f9f3a3a1abb5
MD5 48fdf6d85657572ad4f74eb33528d7af
BLAKE2b-256 71a89ae63b5df6a368c855c2679bc15366c887db3c9a13ccb34aa5593fb58374

See more details on using hashes here.

File details

Details for the file nutrition_ai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nutrition_ai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Darwin/23.6.0

File hashes

Hashes for nutrition_ai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a05724605a1b62a9f8dc327a6efffb622beff9af48f239b091dce4e9d4fc0ad2
MD5 bff6a6139c9edeecd28bee8c1ee7857c
BLAKE2b-256 a0f1a18b873ca80f4f35b2af2d1217991dca298f3ce0d85f08b182386da18661

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page