Update tools.py
Browse files
tools.py
CHANGED
|
@@ -42,6 +42,8 @@ from PIL import Image
|
|
| 42 |
from smolagents import DuckDuckGoSearchTool
|
| 43 |
|
| 44 |
|
|
|
|
|
|
|
| 45 |
|
| 46 |
def web_search(query, max_results=3):
|
| 47 |
searchtool = DuckDuckGoSearchTool(query)
|
|
@@ -49,8 +51,18 @@ def web_search(query, max_results=3):
|
|
| 49 |
return result
|
| 50 |
|
| 51 |
def wiki_search(query):
|
| 52 |
-
wikipedia.set_lang("en")
|
| 53 |
-
return wikipedia.summary(query, sentences=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
def python_repl(code):
|
| 56 |
code = "AkylaiBva/Final_Assignment_Template_AB/"+code
|
|
@@ -78,8 +90,7 @@ def speech_recognition(path):
|
|
| 78 |
return r.recognize_google(audio)
|
| 79 |
|
| 80 |
def reverse_string(s):
|
| 81 |
-
|
| 82 |
-
return web_search(rs)
|
| 83 |
|
| 84 |
def query_image(path):
|
| 85 |
path = "AkylaiBva/Final_Assignment_Template_AB/"+ path
|
|
|
|
| 42 |
from smolagents import DuckDuckGoSearchTool
|
| 43 |
|
| 44 |
|
| 45 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 46 |
+
|
| 47 |
|
| 48 |
def web_search(query, max_results=3):
|
| 49 |
searchtool = DuckDuckGoSearchTool(query)
|
|
|
|
| 51 |
return result
|
| 52 |
|
| 53 |
def wiki_search(query):
|
| 54 |
+
#wikipedia.set_lang("en")
|
| 55 |
+
#return wikipedia.summary(query, sentences=5)
|
| 56 |
+
|
| 57 |
+
model = "mistralai/Mistral-7B-Instruct-v0.2" # or another free model
|
| 58 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
| 59 |
+
model = AutoModelForCausalLM.from_pretrained(model)
|
| 60 |
+
|
| 61 |
+
chat = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 62 |
+
|
| 63 |
+
response = chat(query, max_new_tokens=50)
|
| 64 |
+
return response[0]['generated_text']
|
| 65 |
+
|
| 66 |
|
| 67 |
def python_repl(code):
|
| 68 |
code = "AkylaiBva/Final_Assignment_Template_AB/"+code
|
|
|
|
| 90 |
return r.recognize_google(audio)
|
| 91 |
|
| 92 |
def reverse_string(s):
|
| 93 |
+
return s[::-1]
|
|
|
|
| 94 |
|
| 95 |
def query_image(path):
|
| 96 |
path = "AkylaiBva/Final_Assignment_Template_AB/"+ path
|