import os from langchain_core.tools import tool # ← this needs to be before the decorator from langchain_openai import ChatOpenAI from loguru import logger from pydantic import SecretStr @tool("produce_classifier_tool", parse_docstring=True) def produce_classifier(food_name: str) -> str: """ Classifies a food item as either 'fruit' or 'vegetable' from a botanical perspective. Args: food_name (str): The name of the food item to classify. Returns: str: The classification of the food item, either 'fruit' or 'vegetable'. """ logger.info(f"use produce_classifier_tool with param: {food_name}") chat = ChatOpenAI( model="gpt-4o-mini", temperature=0, api_key=SecretStr(os.environ['OPENAI_API_KEY']) ) prompt = (f"From a botanical perspective, classify {food_name} as either 'fruit' or 'vegetable'. " f"Respond only with a JSON in this exact format: " f"{{\"name\": \"{food_name}\", \"kind\": \"[classification]\"}}") return chat.invoke(prompt).content