Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,8 @@
|
|
| 1 |
|
| 2 |
-
# app.py
|
| 3 |
-
|
| 4 |
# AI Agent Framework Imports
|
| 5 |
-
from smolagents import CodeAgent, HfApiModel, tool
|
| 6 |
|
| 7 |
-
# Standard Library Imports
|
| 8 |
-
import time
|
| 9 |
import yaml
|
| 10 |
|
| 11 |
# Final Answer and UI Handling
|
|
@@ -13,83 +10,26 @@ from tools.final_answer import FinalAnswerTool
|
|
| 13 |
from Gradio_UI import GradioUI
|
| 14 |
|
| 15 |
# --------------------------------------------
|
| 16 |
-
# Tool:
|
| 17 |
-
@tool
|
| 18 |
-
def detect_ambiguity(content: str) -> str:
|
| 19 |
-
"""Checks for vague instructions and suggests clarifications.
|
| 20 |
-
|
| 21 |
-
Args:
|
| 22 |
-
content: Text to analyze.
|
| 23 |
-
"""
|
| 24 |
-
return "Ambiguity detected. Click 'Is this ambiguous?' for help."
|
| 25 |
-
|
| 26 |
-
# --------------------------------------------
|
| 27 |
-
# Tool: explain_assumed_knowledge
|
| 28 |
-
@tool
|
| 29 |
-
def explain_assumed_knowledge(term: str) -> str:
|
| 30 |
-
"""Defines technical terms in a simple way.
|
| 31 |
-
|
| 32 |
-
Args:
|
| 33 |
-
term: The term to explain.
|
| 34 |
-
"""
|
| 35 |
-
return f"Definition of '{term}': [Detailed beginner-friendly explanation here]"
|
| 36 |
-
|
| 37 |
-
# --------------------------------------------
|
| 38 |
-
# Tool: highlight_elements (modified to a placeholder)
|
| 39 |
-
@tool
|
| 40 |
-
def highlight_elements(step: str, element: str, auto_execute: bool = False) -> str:
|
| 41 |
-
"""(Placeholder) Highlights a UI element and optionally performs an action.
|
| 42 |
-
|
| 43 |
-
Args:
|
| 44 |
-
step: The current step in the guide.
|
| 45 |
-
element: The UI element to highlight (as an identifier).
|
| 46 |
-
auto_execute: If True, the agent would auto-click the element.
|
| 47 |
-
"""
|
| 48 |
-
return "Highlight functionality is currently not available."
|
| 49 |
-
|
| 50 |
-
# --------------------------------------------
|
| 51 |
-
# Tool: explain_code_line
|
| 52 |
@tool
|
| 53 |
-
def
|
| 54 |
-
"""
|
| 55 |
|
| 56 |
Args:
|
| 57 |
-
|
| 58 |
-
"""
|
| 59 |
-
return f"Explanation for: {line} [Insert explanation here]"
|
| 60 |
-
|
| 61 |
-
# --------------------------------------------
|
| 62 |
-
# Tool: teacher_box_query
|
| 63 |
-
@tool
|
| 64 |
-
def teacher_box_query(question: str) -> str:
|
| 65 |
-
"""Allows users to ask the AI questions while browsing.
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
"""
|
| 70 |
-
return f"AI Answer: [Response for '{question}']"
|
| 71 |
-
|
| 72 |
-
# --------------------------------------------
|
| 73 |
-
# Tool: toggle_auto_execution
|
| 74 |
-
@tool
|
| 75 |
-
def toggle_auto_execution(enable: bool) -> str:
|
| 76 |
-
"""Lets the user turn automatic navigation on or off.
|
| 77 |
-
|
| 78 |
-
Args:
|
| 79 |
-
enable: True for auto-mode, False for manual steps.
|
| 80 |
"""
|
| 81 |
-
return "
|
| 82 |
|
| 83 |
# --------------------------------------------
|
| 84 |
# Configure the AI Model.
|
| 85 |
-
# If the
|
| 86 |
model = HfApiModel(
|
| 87 |
-
max_tokens=2096,
|
| 88 |
-
temperature=0.5,
|
| 89 |
-
# Use the following model_id if the primary model is overloaded:
|
| 90 |
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
|
| 91 |
-
# Alternatively, you can revert to the original model by using:
|
| 92 |
-
# model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 93 |
custom_role_conversions=None
|
| 94 |
)
|
| 95 |
|
|
@@ -102,15 +42,10 @@ agent = CodeAgent(
|
|
| 102 |
model=model,
|
| 103 |
tools=[
|
| 104 |
FinalAnswerTool(),
|
| 105 |
-
|
| 106 |
-
explain_assumed_knowledge,
|
| 107 |
-
highlight_elements,
|
| 108 |
-
explain_code_line,
|
| 109 |
-
teacher_box_query,
|
| 110 |
-
toggle_auto_execution
|
| 111 |
],
|
| 112 |
-
max_steps=6,
|
| 113 |
-
verbosity_level=1,
|
| 114 |
prompt_templates=prompt_templates
|
| 115 |
)
|
| 116 |
|
|
|
|
| 1 |
|
|
|
|
|
|
|
| 2 |
# AI Agent Framework Imports
|
| 3 |
+
from smolagents import CodeAgent, HfApiModel, tool
|
| 4 |
|
| 5 |
+
# Standard Library Imports
|
|
|
|
| 6 |
import yaml
|
| 7 |
|
| 8 |
# Final Answer and UI Handling
|
|
|
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
# --------------------------------------------
|
| 13 |
+
# Tool: simplify_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
@tool
|
| 15 |
+
def simplify_text(text: str) -> str:
|
| 16 |
+
"""Simplifies a technical sentence or paragraph into plain language.
|
| 17 |
|
| 18 |
Args:
|
| 19 |
+
text: A technical sentence or paragraph.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
Returns:
|
| 22 |
+
A simplified version of the text.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
"""
|
| 24 |
+
return "Simplified: " + text
|
| 25 |
|
| 26 |
# --------------------------------------------
|
| 27 |
# Configure the AI Model.
|
| 28 |
+
# If the primary model is overloaded, you may later switch the model_id to an alternative endpoint.
|
| 29 |
model = HfApiModel(
|
| 30 |
+
max_tokens=2096,
|
| 31 |
+
temperature=0.5,
|
|
|
|
| 32 |
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
|
|
|
|
|
|
|
| 33 |
custom_role_conversions=None
|
| 34 |
)
|
| 35 |
|
|
|
|
| 42 |
model=model,
|
| 43 |
tools=[
|
| 44 |
FinalAnswerTool(),
|
| 45 |
+
simplify_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
],
|
| 47 |
+
max_steps=6,
|
| 48 |
+
verbosity_level=1,
|
| 49 |
prompt_templates=prompt_templates
|
| 50 |
)
|
| 51 |
|