Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import gradio as gr
|
|
| 7 |
import pandas as pd
|
| 8 |
import requests
|
| 9 |
from smolagents import (
|
| 10 |
-
AmazonBedrockServerModel,
|
| 11 |
DuckDuckGoSearchTool,
|
| 12 |
FinalAnswerPromptTemplate,
|
| 13 |
ManagedAgentPromptTemplate,
|
|
@@ -15,44 +14,10 @@ from smolagents import (
|
|
| 15 |
OpenAIServerModel,
|
| 16 |
PlanningPromptTemplate,
|
| 17 |
PromptTemplates,
|
| 18 |
-
Tool,
|
| 19 |
ToolCallingAgent,
|
| 20 |
VisitWebpageTool,
|
| 21 |
)
|
| 22 |
|
| 23 |
-
|
| 24 |
-
class CustomAmazonBedrockServerModel(AmazonBedrockServerModel):
|
| 25 |
-
"""
|
| 26 |
-
Fixed model class to handle Amazon Bedrock model.
|
| 27 |
-
"""
|
| 28 |
-
|
| 29 |
-
def _prepare_completion_kwargs(
|
| 30 |
-
self,
|
| 31 |
-
messages: list[dict[str, str]],
|
| 32 |
-
stop_sequences: list[str] | None = None,
|
| 33 |
-
grammar: str | None = None,
|
| 34 |
-
tools_to_call_from: list[Tool] | None = None,
|
| 35 |
-
custom_role_conversions: dict[str, str] | None = None,
|
| 36 |
-
convert_images_to_image_urls: bool = False,
|
| 37 |
-
**kwargs,
|
| 38 |
-
) -> dict:
|
| 39 |
-
"""Remove invalid keys."""
|
| 40 |
-
completion_kwargs = super()._prepare_completion_kwargs(
|
| 41 |
-
messages=messages,
|
| 42 |
-
stop_sequences=None, # Bedrock support stop_sequence using Inference Config
|
| 43 |
-
grammar=None, # Bedrock doesn't support grammar
|
| 44 |
-
tools_to_call_from=tools_to_call_from,
|
| 45 |
-
custom_role_conversions=custom_role_conversions,
|
| 46 |
-
convert_images_to_image_urls=convert_images_to_image_urls,
|
| 47 |
-
**kwargs,
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
completion_kwargs.pop("tools")
|
| 51 |
-
completion_kwargs.pop("tool_choice")
|
| 52 |
-
|
| 53 |
-
return completion_kwargs
|
| 54 |
-
|
| 55 |
-
|
| 56 |
# (Keep Constants as is)
|
| 57 |
# --- Constants ---
|
| 58 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -61,9 +26,12 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 61 |
# --- Basic Agent Definition ---
|
| 62 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 63 |
class GAIAgent:
|
| 64 |
-
SYSTEM_PROMPT =
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
def __init__(self, model: Model):
|
| 69 |
prompt_templates = PromptTemplates(
|
|
|
|
| 7 |
import pandas as pd
|
| 8 |
import requests
|
| 9 |
from smolagents import (
|
|
|
|
| 10 |
DuckDuckGoSearchTool,
|
| 11 |
FinalAnswerPromptTemplate,
|
| 12 |
ManagedAgentPromptTemplate,
|
|
|
|
| 14 |
OpenAIServerModel,
|
| 15 |
PlanningPromptTemplate,
|
| 16 |
PromptTemplates,
|
|
|
|
| 17 |
ToolCallingAgent,
|
| 18 |
VisitWebpageTool,
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# (Keep Constants as is)
|
| 22 |
# --- Constants ---
|
| 23 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 26 |
# --- Basic Agent Definition ---
|
| 27 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 28 |
class GAIAgent:
|
| 29 |
+
SYSTEM_PROMPT = (
|
| 30 |
+
"You are a helpful assistant with data and image analysis and web browsing capabilities. You can search the "
|
| 31 |
+
"web and visit webpages to find relevant information. You should answer user questions based on the "
|
| 32 |
+
"information you find.\n"
|
| 33 |
+
"Your final answer should only contain the answer to the question and nothing else."
|
| 34 |
+
)
|
| 35 |
|
| 36 |
def __init__(self, model: Model):
|
| 37 |
prompt_templates = PromptTemplates(
|