Spaces:
Running
on
A10G
Running
on
A10G
Commit
·
a181016
1
Parent(s):
ae05573
Update
Browse files
octotools/models/initializer.py
CHANGED
@@ -113,7 +113,13 @@ class Initializer:
|
|
113 |
tool_class = getattr(module, tool_name)
|
114 |
|
115 |
# Instantiate the tool
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
# FIXME This is a temporary workaround to avoid running demo commands
|
119 |
self.available_tools.append(tool_name)
|
|
|
113 |
tool_class = getattr(module, tool_name)
|
114 |
|
115 |
# Instantiate the tool
|
116 |
+
inputs = {}
|
117 |
+
if hasattr(tool_class, 'require_llm_engine') and tool_class.require_llm_engine:
|
118 |
+
inputs['model_string'] = self.model_string
|
119 |
+
|
120 |
+
if hasattr(tool_class, 'require_api_key') and tool_class.require_api_key:
|
121 |
+
inputs['api_key'] = self.api_key
|
122 |
+
tool_instance = tool_class(**inputs)
|
123 |
|
124 |
# FIXME This is a temporary workaround to avoid running demo commands
|
125 |
self.available_tools.append(tool_name)
|
octotools/tools/image_captioner/tool.py
CHANGED
@@ -4,8 +4,9 @@ from octotools.engine.openai import ChatOpenAI
|
|
4 |
|
5 |
class Image_Captioner_Tool(BaseTool):
|
6 |
require_llm_engine = True
|
|
|
7 |
|
8 |
-
def __init__(self, model_string="gpt-4o-mini"):
|
9 |
super().__init__(
|
10 |
tool_name="Image_Captioner_Tool",
|
11 |
tool_description="A tool that generates captions for images using OpenAI's multimodal model.",
|
@@ -30,7 +31,7 @@ class Image_Captioner_Tool(BaseTool):
|
|
30 |
},
|
31 |
)
|
32 |
print(f"\nInitializing Image Captioner Tool with model: {model_string}")
|
33 |
-
self.llm_engine = ChatOpenAI(model_string=model_string, is_multimodal=True) if model_string else None
|
34 |
|
35 |
def execute(self, image, prompt="Describe this image in detail."):
|
36 |
try:
|
|
|
4 |
|
5 |
class Image_Captioner_Tool(BaseTool):
|
6 |
require_llm_engine = True
|
7 |
+
require_api_key = True
|
8 |
|
9 |
+
def __init__(self, model_string="gpt-4o-mini", api_key=None):
|
10 |
super().__init__(
|
11 |
tool_name="Image_Captioner_Tool",
|
12 |
tool_description="A tool that generates captions for images using OpenAI's multimodal model.",
|
|
|
31 |
},
|
32 |
)
|
33 |
print(f"\nInitializing Image Captioner Tool with model: {model_string}")
|
34 |
+
self.llm_engine = ChatOpenAI(model_string=model_string, is_multimodal=True, api_key=api_key) if model_string else None
|
35 |
|
36 |
def execute(self, image, prompt="Describe this image in detail."):
|
37 |
try:
|
octotools/tools/python_code_generator/tool.py
CHANGED
@@ -37,8 +37,9 @@ def timeout(seconds):
|
|
37 |
|
38 |
class Python_Code_Generator_Tool(BaseTool):
|
39 |
require_llm_engine = True
|
|
|
40 |
|
41 |
-
def __init__(self, model_string="gpt-4o-mini"):
|
42 |
super().__init__(
|
43 |
tool_name="Python_Code_Generator_Tool",
|
44 |
tool_description="A tool that generates and executes simple Python code snippets for basic arithmetical calculations and math-related problems. The generated code runs in a highly restricted environment with only basic mathematical operations available.",
|
@@ -83,7 +84,7 @@ class Python_Code_Generator_Tool(BaseTool):
|
|
83 |
}
|
84 |
)
|
85 |
print(f"\nInitializing Python_Code_Generator_Tool with model_string: {model_string}")
|
86 |
-
self.llm_engine = ChatOpenAI(model_string=model_string, is_multimodal=False) if model_string else None
|
87 |
|
88 |
@staticmethod
|
89 |
def preprocess_code(code):
|
|
|
37 |
|
38 |
class Python_Code_Generator_Tool(BaseTool):
|
39 |
require_llm_engine = True
|
40 |
+
require_api_key = True
|
41 |
|
42 |
+
def __init__(self, model_string="gpt-4o-mini", api_key=None):
|
43 |
super().__init__(
|
44 |
tool_name="Python_Code_Generator_Tool",
|
45 |
tool_description="A tool that generates and executes simple Python code snippets for basic arithmetical calculations and math-related problems. The generated code runs in a highly restricted environment with only basic mathematical operations available.",
|
|
|
84 |
}
|
85 |
)
|
86 |
print(f"\nInitializing Python_Code_Generator_Tool with model_string: {model_string}")
|
87 |
+
self.llm_engine = ChatOpenAI(model_string=model_string, is_multimodal=False, api_key=api_key) if model_string else None
|
88 |
|
89 |
@staticmethod
|
90 |
def preprocess_code(code):
|
octotools/tools/relevant_patch_zoomer/tool.py
CHANGED
@@ -10,8 +10,9 @@ class PatchZoomerResponse(BaseModel):
|
|
10 |
|
11 |
class Relevant_Patch_Zoomer_Tool(BaseTool):
|
12 |
require_llm_engine = True
|
|
|
13 |
|
14 |
-
def __init__(self, model_string="gpt-4o"):
|
15 |
super().__init__(
|
16 |
tool_name="Relevant_Patch_Zoomer_Tool",
|
17 |
tool_description="A tool that analyzes an image, divides it into 5 regions (4 quarters + center), and identifies the most relevant patches based on a question. The returned patches are zoomed in by a factor of 2.",
|
@@ -44,7 +45,7 @@ class Relevant_Patch_Zoomer_Tool(BaseTool):
|
|
44 |
}
|
45 |
|
46 |
print(f"\nInitializing Patch Zoomer Tool with model: {model_string}")
|
47 |
-
self.llm_engine = ChatOpenAI(model_string=model_string, is_multimodal=True) if model_string else None
|
48 |
|
49 |
def _save_patch(self, image_path, patch, save_path, zoom_factor=2):
|
50 |
"""Extract and save a specific patch from the image with 10% margins."""
|
|
|
10 |
|
11 |
class Relevant_Patch_Zoomer_Tool(BaseTool):
|
12 |
require_llm_engine = True
|
13 |
+
require_api_key = True
|
14 |
|
15 |
+
def __init__(self, model_string="gpt-4o", api_key=None):
|
16 |
super().__init__(
|
17 |
tool_name="Relevant_Patch_Zoomer_Tool",
|
18 |
tool_description="A tool that analyzes an image, divides it into 5 regions (4 quarters + center), and identifies the most relevant patches based on a question. The returned patches are zoomed in by a factor of 2.",
|
|
|
45 |
}
|
46 |
|
47 |
print(f"\nInitializing Patch Zoomer Tool with model: {model_string}")
|
48 |
+
self.llm_engine = ChatOpenAI(model_string=model_string, is_multimodal=True, api_key=api_key) if model_string else None
|
49 |
|
50 |
def _save_patch(self, image_path, patch, save_path, zoom_factor=2):
|
51 |
"""Extract and save a specific patch from the image with 10% margins."""
|