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.0.tar.gz (7.1 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.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nutrition_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5ee866c95a4f60a8bc4e382e502d05242e40a0ab8dd1e521f8ff55ed1d388618
MD5 7d3efa2fd6e3b15be03314a1bf4f0998
BLAKE2b-256 6f3675dd0c358de537d57e65cc63d9d1ed420c8f786628ff65b73916adcfbd3e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nutrition_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 376d74e0bcb0a89a7821fbd77246f3fa5fb16ceb242d78d42f2b31c5b1f0923f
MD5 d68134479f318949b0e14598cee43513
BLAKE2b-256 c015a7b1316fd4221c649c6381ab06bc0707de720b1768ccb00e90b0814ab081

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