Skip to content

Commit 1d49b39

Browse files
committed
Merge remote-tracking branch 'origin/main' into test
2 parents f280a04 + 8872fea commit 1d49b39

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

pet_clinic_ai_agents/nutrition_agent/nutrition_agent.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,22 @@
1616
def get_nutrition_data(pet_type):
1717
"""Helper function to get nutrition data from the API"""
1818
if not NUTRITION_SERVICE_URL:
19-
return {"facts": "Error: Nutrition service not found", "products": "", "has_data": False}
19+
return {"facts": "Error: Nutrition service not found", "products": ""}
2020

2121
try:
2222
response = requests.get(f"{NUTRITION_SERVICE_URL}/{pet_type.lower()}", timeout=5)
2323

2424
if response.status_code == 200:
2525
data = response.json()
26-
return {"facts": data.get('facts', ''), "products": data.get('products', ''), "has_data": True}
27-
elif response.status_code == 404:
28-
return {"facts": f"We don't currently have nutrition information for {pet_type} in our database", "products": "", "has_data": False}
29-
return {"facts": f"Error: Nutrition service could not find information for pet: {pet_type.lower()}", "products": "", "has_data": False}
26+
return {"facts": data.get('facts', ''), "products": data.get('products', '')}
27+
return {"facts": f"Error: Nutrition service could not find information for pet: {pet_type.lower()}", "products": ""}
3028
except requests.RequestException:
31-
return {"facts": "Error: Nutrition service down", "products": "", "has_data": False}
29+
return {"facts": "Error: Nutrition service down", "products": ""}
3230

3331
@tool
3432
def get_feeding_guidelines(pet_type):
3533
"""Get feeding guidelines based on pet type"""
3634
data = get_nutrition_data(pet_type)
37-
if not data['has_data']:
38-
return data['facts']
39-
4035
result = f"Nutrition info for {pet_type}: {data['facts']}"
4136
if data['products']:
4237
result += f" Recommended products available at our clinic: {data['products']}"
@@ -46,9 +41,6 @@ def get_feeding_guidelines(pet_type):
4641
def get_dietary_restrictions(pet_type):
4742
"""Get dietary recommendations for specific health conditions by animal type"""
4843
data = get_nutrition_data(pet_type)
49-
if not data['has_data']:
50-
return data['facts']
51-
5244
result = f"Dietary info for {pet_type}: {data['facts']}. Consult veterinarian for condition-specific advice."
5345
if data['products']:
5446
result += f" Recommended products available at our clinic: {data['products']}"
@@ -58,9 +50,6 @@ def get_dietary_restrictions(pet_type):
5850
def get_nutritional_supplements(pet_type):
5951
"""Get supplement recommendations by animal type"""
6052
data = get_nutrition_data(pet_type)
61-
if not data['has_data']:
62-
return data['facts']
63-
6453
result = f"Supplement info for {pet_type}: {data['facts']}. Consult veterinarian for supplements."
6554
if data['products']:
6655
result += f" Recommended products available at our clinic: {data['products']}"
@@ -71,9 +60,6 @@ def create_order(product_name, pet_type, quantity=1):
7160
"""Create an order for a recommended product. Requires product_name, pet_type, and optional quantity (default 1)."""
7261
product_lower = product_name.lower()
7362
data = get_nutrition_data(pet_type)
74-
if not data['has_data']:
75-
return f"Sorry, we don't currently have nutrition information for {pet_type} in our database, so we cannot process orders for this pet type."
76-
7763
if data['products'] and product_name.lower() in data['products'].lower():
7864
order_id = f"ORD-{uuid.uuid4().hex[:8].upper()}"
7965
return f"Order {order_id} created for {quantity}x {product_name}. Total: ${quantity * 29.99:.2f}. Expected delivery: 3-5 business days. You can pick it up at our clinic or we'll ship it to you."
@@ -91,18 +77,14 @@ def create_nutrition_agent():
9177
"You are a specialized pet nutrition expert at our veterinary clinic, providing accurate, evidence-based dietary guidance for pets. "
9278
"Never mention using any API, tools, or external services - present all advice as your own expert knowledge.\n\n"
9379
"When providing nutrition guidance:\n"
94-
"- ONLY provide recommendations when you have specific nutrition information available for the requested pet type\n"
95-
"- If you don't have nutrition information for a specific pet type, clearly state that we don't currently have that information in our database\n"
96-
"- NEVER fabricate or hallucinate product names, nutrition facts, or recommendations when data is not available\n"
97-
"- When you DO have nutrition information available, use it as the foundation for your recommendations\n"
98-
"- Only recommend SPECIFIC PRODUCT NAMES that are actually provided to you in the nutrition data\n"
99-
"- Mention our branded products by name (like PurrfectChoice, BarkBite, FeatherFeast, etc.) ONLY when they are available in our database\n"
100-
"- Emphasize that we carry high-quality, veterinarian-recommended food brands at our clinic ONLY for pets we have data for\n"
101-
"- Give actionable dietary recommendations including feeding guidelines, restrictions, and supplements ONLY when data is available\n"
102-
"- Expand on basic nutrition facts with comprehensive guidance for age, weight, and health conditions ONLY when you have the underlying data\n"
103-
"- Always mention that pet owners can purchase the recommended food items directly from our clinic for convenience and quality assurance ONLY when products are available\n"
104-
"- If asked to order or purchase a product for a pet type we don't have data for, politely decline and explain we don't have information for that pet type\n"
105-
"- For unsupported pet types, suggest contacting our clinic directly for personalized consultation"
80+
"- Use the specific nutrition information available to you as the foundation for your recommendations\n"
81+
"- Always recommend the SPECIFIC PRODUCT NAMES provided to you that pet owners should buy FROM OUR PET CLINIC\n"
82+
"- Mention our branded products by name (like PurrfectChoice, BarkBite, FeatherFeast, etc.) when recommending food\n"
83+
"- Emphasize that we carry high-quality, veterinarian-recommended food brands at our clinic\n"
84+
"- Give actionable dietary recommendations including feeding guidelines, restrictions, and supplements\n"
85+
"- Expand on basic nutrition facts with comprehensive guidance for age, weight, and health conditions\n"
86+
"- Always mention that pet owners can purchase the recommended food items directly from our clinic for convenience and quality assurance\n"
87+
"- If asked to order or purchase a product, use the create_order tool to place the order"
10688
)
10789

10890
return Agent(model=model, tools=tools, system_prompt=system_prompt)

0 commit comments

Comments
 (0)