Skip to content

Passio nutrition ai

NutritionAIToolSpec #

Bases: BaseToolSpec

Tool that queries the Passio Nutrition AI API.

Source code in llama-index-integrations/tools/llama-index-tools-passio-nutrition-ai/llama_index/tools/passio_nutrition_ai/base.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
class NutritionAIToolSpec(BaseToolSpec):
    """Tool that queries the Passio Nutrition AI API."""

    spec_functions = ["nutrition_ai_search"]
    auth_: ManagedPassioLifeAuth

    def __init__(self, api_key: str) -> None:
        """Initialize with parameters."""
        self.auth_ = ManagedPassioLifeAuth(api_key)

    @retry(
        retry=retry_if_result(is_http_retryable),
        stop=stop_after_attempt(4),
        wait=wait_random(0, 0.3) + wait_exponential(multiplier=1, min=0.1, max=2),
    )
    def _http_get(self, query: str):
        return requests.get(
            ENDPOINT_BASE_URL,
            headers=self.auth_.headers,
            params={"term": query},  # type: ignore
        )

    def _nutrition_request(self, query: str):
        response = self._http_get(query)
        if not response:
            raise ValueError("No response from NutritionAI API.")
        return response.json()

    def nutrition_ai_search(self, query: str):
        """
        Retrieve nutrition facts for a given food item.
        Input should be a search query string for the food item.

        Args:
            query (str): The food item to look for.

        Returns a JSON result with the nutrition facts for the food item and, if available, alternative food items which sometimes are a better match.
        """
        return self._nutrition_request(query)
nutrition_ai_search(query: str)

Retrieve nutrition facts for a given food item. Input should be a search query string for the food item.

Parameters:

Name Type Description Default
query str

The food item to look for.

required

Returns a JSON result with the nutrition facts for the food item and, if available, alternative food items which sometimes are a better match.

Source code in llama-index-integrations/tools/llama-index-tools-passio-nutrition-ai/llama_index/tools/passio_nutrition_ai/base.py
134
135
136
137
138
139
140
141
142
143
144
def nutrition_ai_search(self, query: str):
    """
    Retrieve nutrition facts for a given food item.
    Input should be a search query string for the food item.

    Args:
        query (str): The food item to look for.

    Returns a JSON result with the nutrition facts for the food item and, if available, alternative food items which sometimes are a better match.
    """
    return self._nutrition_request(query)