CindyDelage commited on
Commit
0dbf350
·
verified ·
1 Parent(s): 92b1f5d

Upload tools.py

Browse files
Files changed (1) hide show
  1. tools.py +54 -0
tools.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import DuckDuckGoSearchTool
2
+ from smolagents import Tool
3
+ from huggingface_hub import InferenceClient
4
+
5
+ class Web_research(Tool):
6
+ name="web_research"
7
+ #description="You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don’t use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."
8
+ description = "Web search on a specific topic."
9
+ inputs = {
10
+ "topic": {
11
+ "type": "string",
12
+ "description": "The topic on which the user wants the latest news"
13
+ }
14
+ }
15
+ output_type = "string"
16
+
17
+ def forward(self, topic: str):
18
+ search_tool = DuckDuckGoSearchTool()
19
+ # Example usage
20
+ results = search_tool(f"{topic}")
21
+ return f"Here is what we can find on the web for {topic} : str({results})"
22
+
23
+ class image_interpreter(Tool):
24
+ name="multimodal_tool"
25
+ description = "Allows you to answer any question which relies on image input."
26
+ inputs = {
27
+ 'image': {"type": "image", "description": "the image of interest"},
28
+ 'prompt': {"type": "string", "description": "Any specific question you have on the image. For example, the prompt can be : Summarise this image in one sentence."}
29
+ }
30
+ output_type = "image"
31
+ output_type = "string"
32
+ model_sdxl = "trillionlabs/Trillion-LLaVA-7B"
33
+ client = InferenceClient(model_sdxl)
34
+
35
+ def forward(self, prompt, image):
36
+ output = client.chat.completions.create(
37
+ messages=[
38
+ {
39
+ "role": "user",
40
+ "content": [
41
+ {
42
+ "type": "image",
43
+ "image": {image},
44
+ },
45
+ {
46
+ "type": "text",
47
+ "text": {prompt},
48
+ },
49
+ ],
50
+ },
51
+ ],
52
+ )
53
+ return output
54
+