Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,43 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
@@ -18,6 +55,66 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -55,7 +152,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from typing import List, Dict
|
| 11 |
+
|
| 12 |
+
def generate_test_cases(topic: str) -> List[Dict[str, str]]:
|
| 13 |
+
"""
|
| 14 |
+
Suggest simple QA test cases for a given topic.
|
| 15 |
+
Args:
|
| 16 |
+
topic: The feature, function, or topic to generate test cases for.
|
| 17 |
+
Returns:
|
| 18 |
+
A list of test cases, each with input and expected output.
|
| 19 |
+
"""
|
| 20 |
+
topic_lower = topic.lower()
|
| 21 |
+
test_cases = []
|
| 22 |
+
|
| 23 |
+
if "login" in topic_lower:
|
| 24 |
+
test_cases = [
|
| 25 |
+
{"test_case": "Valid login", "input": "Correct username/password", "expected_output": "User is logged in successfully"},
|
| 26 |
+
{"test_case": "Invalid password", "input": "Wrong password", "expected_output": "Error message displayed"},
|
| 27 |
+
{"test_case": "Empty username", "input": "Username left blank", "expected_output": "Error message displayed"},
|
| 28 |
+
{"test_case": "Empty password", "input": "Password left blank", "expected_output": "Error message displayed"},
|
| 29 |
+
]
|
| 30 |
+
elif "calculator" in topic_lower:
|
| 31 |
+
test_cases = [
|
| 32 |
+
{"test_case": "Addition", "input": "2 + 3", "expected_output": "5"},
|
| 33 |
+
{"test_case": "Subtraction", "input": "5 - 2", "expected_output": "3"},
|
| 34 |
+
{"test_case": "Multiplication", "input": "4 * 5", "expected_output": "20"},
|
| 35 |
+
{"test_case": "Divide by zero", "input": "5 / 0", "expected_output": "Error handled gracefully"},
|
| 36 |
+
]
|
| 37 |
+
else:
|
| 38 |
+
# Generic template
|
| 39 |
+
test_cases = [
|
| 40 |
+
{"test_case": f"Test case 1 for {topic}", "input": "Sample input", "expected_output": "Expected behavior"},
|
| 41 |
+
{"test_case": f"Test case 2 for {topic}", "input": "Another input", "expected_output": "Expected behavior"},
|
| 42 |
+
{"test_case": f"Test case 3 for {topic}", "input": "Additional input", "expected_output": "Expected behavior"},
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
return test_cases
|
| 46 |
+
|
| 47 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 48 |
@tool
|
| 49 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 55 |
"""
|
| 56 |
return "What magic will you build ?"
|
| 57 |
|
| 58 |
+
@tool
|
| 59 |
+
def suggest_test_cases(topic: str) -> list:
|
| 60 |
+
"""
|
| 61 |
+
Suggest simple QA test cases for a given topic.
|
| 62 |
+
|
| 63 |
+
Args:
|
| 64 |
+
topic: Feature or topic to generate test cases for.
|
| 65 |
+
|
| 66 |
+
Returns:
|
| 67 |
+
A list of test cases with input and expected output.
|
| 68 |
+
"""
|
| 69 |
+
return generate_test_cases(topic)
|
| 70 |
+
|
| 71 |
+
@tool
|
| 72 |
+
def time_difference(ts1: str, tz1: str, ts2: str, tz2: str, signed: bool = False) -> str:
|
| 73 |
+
"""
|
| 74 |
+
Calculate the duration between two timestamps in different timezones.
|
| 75 |
+
Args:
|
| 76 |
+
ts1: First timestamp string in 'YYYY-MM-DD HH:MM:SS' format.
|
| 77 |
+
tz1: Timezone of ts1 (e.g. 'UTC', 'America/New_York').
|
| 78 |
+
ts2: Second timestamp string in 'YYYY-MM-DD HH:MM:SS' format.
|
| 79 |
+
tz2: Timezone of ts2.
|
| 80 |
+
signed: If True, return negative values when ts2 is earlier than ts1.
|
| 81 |
+
If False, return absolute difference.
|
| 82 |
+
Returns:
|
| 83 |
+
A formatted string showing the difference in days, hours, minutes, and seconds.
|
| 84 |
+
"""
|
| 85 |
+
try:
|
| 86 |
+
# Parse timestamps
|
| 87 |
+
fmt = "%Y-%m-%d %H:%M:%S"
|
| 88 |
+
dt1_naive = datetime.datetime.strptime(ts1, fmt)
|
| 89 |
+
dt2_naive = datetime.datetime.strptime(ts2, fmt)
|
| 90 |
+
|
| 91 |
+
# Apply timezones
|
| 92 |
+
dt1 = pytz.timezone(tz1).localize(dt1_naive)
|
| 93 |
+
dt2 = pytz.timezone(tz2).localize(dt2_naive)
|
| 94 |
+
|
| 95 |
+
# Convert to UTC for accurate comparison
|
| 96 |
+
dt1_utc = dt1.astimezone(pytz.UTC)
|
| 97 |
+
dt2_utc = dt2.astimezone(pytz.UTC)
|
| 98 |
+
|
| 99 |
+
# Difference
|
| 100 |
+
diff = dt2_utc - dt1_utc
|
| 101 |
+
|
| 102 |
+
if not signed:
|
| 103 |
+
diff = abs(diff)
|
| 104 |
+
|
| 105 |
+
# Break down difference
|
| 106 |
+
total_seconds = int(diff.total_seconds())
|
| 107 |
+
days = total_seconds // 86400
|
| 108 |
+
hours = (total_seconds % 86400) // 3600
|
| 109 |
+
minutes = (total_seconds % 3600) // 60
|
| 110 |
+
seconds = total_seconds % 60
|
| 111 |
+
|
| 112 |
+
result = f"Difference: {days}d {hours}h {minutes}m {seconds}s (total {total_seconds} seconds)"
|
| 113 |
+
return result
|
| 114 |
+
|
| 115 |
+
except Exception as e:
|
| 116 |
+
return f"Error calculating time difference: {str(e)}"
|
| 117 |
+
|
| 118 |
@tool
|
| 119 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 120 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 152 |
|
| 153 |
agent = CodeAgent(
|
| 154 |
model=model,
|
| 155 |
+
tools=[final_answer, suggest_test_cases, time_difference], ## add your tools here (don't remove final answer)
|
| 156 |
max_steps=6,
|
| 157 |
verbosity_level=1,
|
| 158 |
grammar=None,
|