Add summary tool
Browse files
app.py
CHANGED
@@ -1,22 +1,43 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
-
from
|
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
|
13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
-
"""A tool that
|
15 |
Args:
|
16 |
-
|
17 |
-
arg2: the second argument
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -35,23 +56,28 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
35 |
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
38 |
-
|
39 |
-
max_tokens=2096,
|
40 |
-
temperature=0.5,
|
41 |
-
model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
|
42 |
-
custom_role_conversions=None,
|
43 |
)
|
44 |
|
45 |
|
46 |
# Import tool from Hub
|
47 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
48 |
|
49 |
-
with open(
|
50 |
prompt_templates = yaml.safe_load(stream)
|
51 |
|
52 |
agent = CodeAgent(
|
53 |
-
model=
|
54 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
55 |
max_steps=6,
|
56 |
verbosity_level=1,
|
57 |
grammar=None,
|
|
|
|
|
1 |
import datetime
|
2 |
import requests
|
3 |
import pytz
|
4 |
import yaml
|
5 |
+
from typing import List
|
6 |
|
7 |
from Gradio_UI import GradioUI
|
8 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
9 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
10 |
+
from tools.final_answer import FinalAnswerTool
|
11 |
+
from tools.visit_webpage import VisitWebpageTool
|
12 |
+
|
13 |
+
|
14 |
+
summary_model = HfApiModel(
|
15 |
+
max_tokens=1024,
|
16 |
+
temperature=0.5,
|
17 |
+
model_id='mistralai/Mistral-7B-Instruct-v0.2',
|
18 |
+
custom_role_conversions=None,
|
19 |
+
)
|
20 |
+
|
21 |
|
22 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
23 |
@tool
|
24 |
+
def summarize_text(texts: List[str])-> str: #it's import to specify the return type
|
25 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
26 |
+
"""A tool that writes a summary based on a list of texts provided.
|
27 |
Args:
|
28 |
+
texts: A list of input texts based on which a summary is to be generated
|
|
|
29 |
"""
|
30 |
+
|
31 |
+
texts = '\n\n'.join(texts)
|
32 |
+
messages = [
|
33 |
+
{
|
34 |
+
'role': 'user',
|
35 |
+
'content': f'Summarize the following text:\n{texts}'
|
36 |
+
}
|
37 |
+
]
|
38 |
+
response = summary_model(messages)
|
39 |
+
return response.content
|
40 |
+
|
41 |
|
42 |
@tool
|
43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
56 |
|
57 |
|
58 |
final_answer = FinalAnswerTool()
|
59 |
+
code_model = HfApiModel(
|
60 |
+
max_tokens=2096,
|
61 |
+
temperature=0.5,
|
62 |
+
model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
|
63 |
+
custom_role_conversions=None,
|
64 |
)
|
65 |
|
66 |
|
67 |
# Import tool from Hub
|
68 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
69 |
|
70 |
+
with open('prompts.yaml', 'r') as stream:
|
71 |
prompt_templates = yaml.safe_load(stream)
|
72 |
|
73 |
agent = CodeAgent(
|
74 |
+
model=code_model,
|
75 |
+
tools=[
|
76 |
+
DuckDuckGoSearchTool,
|
77 |
+
VisitWebpageTool,
|
78 |
+
summarize_text,
|
79 |
+
final_answer,
|
80 |
+
], ## add your tools here (don't remove final answer)
|
81 |
max_steps=6,
|
82 |
verbosity_level=1,
|
83 |
grammar=None,
|