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:
- Ensure you have set the
PASSIO_API_KEYenvironment variable. - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nutrition_ai-0.1.3.tar.gz.
File metadata
- Download URL: nutrition_ai-0.1.3.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.14 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df60190c61b72cfff5e2b6e1bc0ca67e0d06e525fb87e4038ceb2dc9e1c588bb
|
|
| MD5 |
3aa9d26d6e378d03d04c007260a6a765
|
|
| BLAKE2b-256 |
25a4dc4ee62755a914cb62ffcc021afb9f4c98e991a4517ede71f0f34d085f8f
|
File details
Details for the file nutrition_ai-0.1.3-py3-none-any.whl.
File metadata
- Download URL: nutrition_ai-0.1.3-py3-none-any.whl
- Upload date:
- Size: 13.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
969895e82ee8fa388c84649c5f511550036e774c3cfcd727f4153c0351aefaeb
|
|
| MD5 |
18e28cbccb0fae44eb86f1ac4658100a
|
|
| BLAKE2b-256 |
78a02c5347d1867ae38822b746c7bdb05812d11b89abd10ee6acbf5970701efa
|