Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,45 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
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(
|
13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
-
"""
|
15 |
Args:
|
16 |
-
|
17 |
-
|
18 |
"""
|
19 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -40,13 +63,13 @@ final_answer = FinalAnswerTool()
|
|
40 |
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
41 |
# model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
42 |
|
43 |
-
model = HfApiModel(
|
44 |
-
max_tokens=2096,
|
45 |
-
temperature=0.5,
|
46 |
-
model_id=model_id,# it is possible that this model may be overloaded
|
47 |
-
custom_role_conversions=None,
|
48 |
-
)
|
49 |
-
|
50 |
|
51 |
# Import tool from Hub
|
52 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
@@ -56,14 +79,15 @@ with open("prompts.yaml", 'r') as stream:
|
|
56 |
|
57 |
agent = CodeAgent(
|
58 |
model=model,
|
59 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
60 |
max_steps=6,
|
61 |
verbosity_level=1,
|
62 |
grammar=None,
|
63 |
planning_interval=None,
|
64 |
name=None,
|
65 |
description=None,
|
66 |
-
prompt_templates=prompt_templates
|
|
|
67 |
)
|
68 |
|
69 |
|
|
|
1 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool, LiteLLMModel
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
import os
|
8 |
+
from random import randint
|
9 |
+
import typing
|
10 |
+
import pandas as pd
|
11 |
|
12 |
from Gradio_UI import GradioUI
|
13 |
|
14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
15 |
@tool
|
16 |
+
def my_custom_tool(personality1:str, personality2:str)-> str: #it's import to specify the return type
|
17 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
18 |
+
"""Этот иснтумент определяет, кто из двух людей круче.
|
19 |
Args:
|
20 |
+
personality1: Первый человек
|
21 |
+
personality2: Второй человек
|
22 |
"""
|
23 |
+
return personality1 if randint(0, 1) else personality2
|
24 |
+
|
25 |
+
@tool
|
26 |
+
def create_excel(data:typing.List[typing.List[str]], columns:typing.List[str], file_name:str)-> str: #it's import to specify the return type
|
27 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
28 |
+
"""Этот иснтумент сохраняет датафрейм pandas в excel файл. И возвращает ответ, успешно или нет записан файл.
|
29 |
+
Args:
|
30 |
+
data: Параметр данных для загрузки в pandas и сохранения в файл. Формат список списков.
|
31 |
+
columns: Параметр список имен колонок.
|
32 |
+
file_name: Имя файла для сохранения.
|
33 |
+
"""
|
34 |
+
|
35 |
+
df = pd.DataFrame(data, columns=columns)
|
36 |
+
|
37 |
+
try:
|
38 |
+
df.to_excel(file_name, index=False)
|
39 |
+
except Exception as e:
|
40 |
+
return e
|
41 |
+
|
42 |
+
return "Файл успешно сохранен"
|
43 |
|
44 |
@tool
|
45 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
63 |
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
64 |
# model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
65 |
|
66 |
+
# model = HfApiModel(
|
67 |
+
# max_tokens=2096,
|
68 |
+
# temperature=0.5,
|
69 |
+
# model_id=model_id,# it is possible that this model may be overloaded
|
70 |
+
# custom_role_conversions=None,
|
71 |
+
# )
|
72 |
+
model = LiteLLMModel(model_id="together_ai/meta-llama/Llama-3.3-70B-Instruct-Turbo-Free", api_key=os.environ['TOGETHER_API_KEY'])
|
73 |
|
74 |
# Import tool from Hub
|
75 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
|
79 |
|
80 |
agent = CodeAgent(
|
81 |
model=model,
|
82 |
+
tools=[final_answer, get_current_time_in_timezone, my_custom_tool, create_excel], ## add your tools here (don't remove final answer)
|
83 |
max_steps=6,
|
84 |
verbosity_level=1,
|
85 |
grammar=None,
|
86 |
planning_interval=None,
|
87 |
name=None,
|
88 |
description=None,
|
89 |
+
prompt_templates=prompt_templates,
|
90 |
+
additional_authorized_imports=['matplotlib', 'numpy', 'matplotlib.pyplot']
|
91 |
)
|
92 |
|
93 |
|