Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,33 +7,33 @@ from tools.final_answer import FinalAnswerTool as FinalAnswer
|
|
| 7 |
# Get current directory path
|
| 8 |
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 9 |
|
|
|
|
| 10 |
model = OpenAIServerModel(
|
| 11 |
model_id='qwen/qwen2.5-coder-32b-instruct',
|
| 12 |
api_key=os.getenv("OPENAI_API_KEY", "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"),
|
| 13 |
api_base=os.getenv("OPENAI_API_BASE", "https://integrate.api.nvidia.com/v1"),
|
| 14 |
)
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
final_answer = FinalAnswer()
|
| 18 |
|
|
|
|
| 19 |
with open(os.path.join(CURRENT_DIR, "prompts.yaml"), "r") as f:
|
| 20 |
raw_templates = yaml.safe_load(f)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
def unwrap_text_objects(obj):
|
| 24 |
if isinstance(obj, dict):
|
| 25 |
if obj.get("type") == "text" and "text" in obj:
|
| 26 |
return obj["text"]
|
| 27 |
return {k: unwrap_text_objects(v) for k, v in obj.items()}
|
| 28 |
elif isinstance(obj, list):
|
| 29 |
-
# If it's a list of strings, join it. If it's list of dicts, unwrap recursively.
|
| 30 |
return "\n".join(unwrap_text_objects(i) for i in obj)
|
| 31 |
return obj
|
| 32 |
|
| 33 |
-
|
| 34 |
-
prompt_templates =
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
# Create the agent
|
| 39 |
agent = CodeAgent(
|
|
@@ -49,6 +49,6 @@ agent = CodeAgent(
|
|
| 49 |
prompt_templates=prompt_templates
|
| 50 |
)
|
| 51 |
|
| 52 |
-
# Launch UI
|
| 53 |
if __name__ == "__main__":
|
| 54 |
-
GradioUI(agent).launch()
|
|
|
|
| 7 |
# Get current directory path
|
| 8 |
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 9 |
|
| 10 |
+
# Initialize the model
|
| 11 |
model = OpenAIServerModel(
|
| 12 |
model_id='qwen/qwen2.5-coder-32b-instruct',
|
| 13 |
api_key=os.getenv("OPENAI_API_KEY", "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"),
|
| 14 |
api_base=os.getenv("OPENAI_API_BASE", "https://integrate.api.nvidia.com/v1"),
|
| 15 |
)
|
| 16 |
|
| 17 |
+
# Initialize tools
|
| 18 |
+
web_search = WebSearch()
|
| 19 |
final_answer = FinalAnswer()
|
| 20 |
|
| 21 |
+
# Load YAML prompt templates
|
| 22 |
with open(os.path.join(CURRENT_DIR, "prompts.yaml"), "r") as f:
|
| 23 |
raw_templates = yaml.safe_load(f)
|
| 24 |
|
| 25 |
+
# ✅ FIXED: Function name corrected from unwrap_text_object to unwrap_text_objects
|
| 26 |
def unwrap_text_objects(obj):
|
| 27 |
if isinstance(obj, dict):
|
| 28 |
if obj.get("type") == "text" and "text" in obj:
|
| 29 |
return obj["text"]
|
| 30 |
return {k: unwrap_text_objects(v) for k, v in obj.items()}
|
| 31 |
elif isinstance(obj, list):
|
|
|
|
| 32 |
return "\n".join(unwrap_text_objects(i) for i in obj)
|
| 33 |
return obj
|
| 34 |
|
| 35 |
+
# Apply the unwrapping to raw templates
|
| 36 |
+
prompt_templates = unwrap_text_objects(raw_templates)
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# Create the agent
|
| 39 |
agent = CodeAgent(
|
|
|
|
| 49 |
prompt_templates=prompt_templates
|
| 50 |
)
|
| 51 |
|
| 52 |
+
# Launch the Gradio UI
|
| 53 |
if __name__ == "__main__":
|
| 54 |
+
GradioUI(agent).launch()
|