Source code for langchain_community.tools.passio_nutrition_ai.tool

"""Passio Nutrition AI API的工具。"""

from typing import Dict, Optional, Type

from langchain_core.callbacks import CallbackManagerForToolRun
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_core.tools import BaseTool

from langchain_community.utilities.passio_nutrition_ai import NutritionAIAPI


[docs]class NutritionAIInputs(BaseModel): """Passio营养AI工具的输入。""" query: str = Field( description="A query to look up using Passio Nutrition AI, usually a few words." )
[docs]class NutritionAI(BaseTool): """用于查询Passio Nutrition AI API的工具。""" name: str = "nutritionai_advanced_search" description: str = ( "A wrapper around the Passio Nutrition AI. " "Useful to retrieve nutrition facts. " "Input should be a search query string." ) api_wrapper: NutritionAIAPI args_schema: Type[BaseModel] = NutritionAIInputs def _run( self, query: str, run_manager: Optional[CallbackManagerForToolRun] = None, ) -> Optional[Dict]: """使用这个工具。""" return self.api_wrapper.run(query)