Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,9 @@ import subprocess
|
|
7 |
import pandas as pd
|
8 |
import torch
|
9 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
10 |
-
from smolagents import CodeAgent,
|
11 |
from smolagents.models import ChatMessage
|
12 |
-
from huggingface_hub import InferenceClient, hf_hub_download
|
13 |
|
14 |
subprocess.run(["playwright", "install"], check=True)
|
15 |
|
@@ -85,7 +85,7 @@ class BasicAgent:
|
|
85 |
# Initialize the tools other than the base tools
|
86 |
# See list of base tools in https://github.com/huggingface/smolagents/blob/main/src/smolagents/default_tools.py
|
87 |
|
88 |
-
#
|
89 |
tok = AutoTokenizer.from_pretrained(model_id, token=hf_token)
|
90 |
mod = AutoModelForCausalLM.from_pretrained(
|
91 |
model_id,
|
@@ -101,7 +101,14 @@ class BasicAgent:
|
|
101 |
return_full_text=False, # <— only get the completion, not the prompt + completion
|
102 |
# temperature=1.0,
|
103 |
)
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
def _serialize_messages(self, messages):
|
107 |
prompt = []
|
|
|
7 |
import pandas as pd
|
8 |
import torch
|
9 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
10 |
+
from smolagents import CodeAgent, WebSearchTool, WikipediaSearchTool
|
11 |
from smolagents.models import ChatMessage
|
12 |
+
# from huggingface_hub import InferenceClient, hf_hub_download
|
13 |
|
14 |
subprocess.run(["playwright", "install"], check=True)
|
15 |
|
|
|
85 |
# Initialize the tools other than the base tools
|
86 |
# See list of base tools in https://github.com/huggingface/smolagents/blob/main/src/smolagents/default_tools.py
|
87 |
|
88 |
+
# Download the model weights and build the pipeline
|
89 |
tok = AutoTokenizer.from_pretrained(model_id, token=hf_token)
|
90 |
mod = AutoModelForCausalLM.from_pretrained(
|
91 |
model_id,
|
|
|
101 |
return_full_text=False, # <— only get the completion, not the prompt + completion
|
102 |
# temperature=1.0,
|
103 |
)
|
104 |
+
# Introduce tools
|
105 |
+
wiki_tool = WikipediaSearchTool()
|
106 |
+
search_tool = WebSearchTool()
|
107 |
+
# Initialize the agent
|
108 |
+
self.agent = CodeAgent(model=self,
|
109 |
+
tools=[wiki_tool, search_tool],
|
110 |
+
add_base_tools=True,
|
111 |
+
additional_authorized_imports=["dateparser"])
|
112 |
|
113 |
def _serialize_messages(self, messages):
|
114 |
prompt = []
|