Update app.py
Browse filesUse Gemini as the model.
app.py
CHANGED
|
@@ -1,13 +1,17 @@
|
|
| 1 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool,
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
import subprocess
|
|
|
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
@tool
|
| 13 |
def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
@@ -67,13 +71,17 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 67 |
|
| 68 |
|
| 69 |
final_answer = FinalAnswerTool()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
model = HfApiModel(
|
| 71 |
max_tokens=2096,
|
| 72 |
temperature=0.5,
|
| 73 |
model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
|
| 74 |
custom_role_conversions=None,
|
| 75 |
)
|
| 76 |
-
|
| 77 |
|
| 78 |
# Import tool from Hub
|
| 79 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
@@ -83,7 +91,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 83 |
|
| 84 |
agent = CodeAgent(
|
| 85 |
model=model,
|
| 86 |
-
tools=[final_answer,
|
| 87 |
max_steps=6,
|
| 88 |
verbosity_level=1,
|
| 89 |
grammar=None,
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, load_tool, tool, LiteLLMModel # replace HfApiModel
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
import subprocess
|
| 7 |
+
import os #retreive your secret api key for LiteLLMModel
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
+
# Retrieve your "secret" google api key named GEMINI_API_KEY for LiteLLMModel
|
| 13 |
+
os.environ["GEMINI_API_KEY"] = os.getenv('GEMINI_API_KEY')
|
| 14 |
+
|
| 15 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 16 |
@tool
|
| 17 |
def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
final_answer = FinalAnswerTool()
|
| 74 |
+
model = LiteLLMModel(model_id="gemini/gemini-2.0-flash")
|
| 75 |
+
|
| 76 |
+
# Coment out the other model API
|
| 77 |
+
'''
|
| 78 |
model = HfApiModel(
|
| 79 |
max_tokens=2096,
|
| 80 |
temperature=0.5,
|
| 81 |
model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
|
| 82 |
custom_role_conversions=None,
|
| 83 |
)
|
| 84 |
+
'''
|
| 85 |
|
| 86 |
# Import tool from Hub
|
| 87 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
|
|
| 91 |
|
| 92 |
agent = CodeAgent(
|
| 93 |
model=model,
|
| 94 |
+
tools=[final_answer, linux_shell_interface, duckduckgo_search], ## add your tools here (don't remove final answer)
|
| 95 |
max_steps=6,
|
| 96 |
verbosity_level=1,
|
| 97 |
grammar=None,
|