Skip to content

Commit 3f7b05f

Browse files
Add mini model and dummy tool logic
The changes introduce a new #mini model with a large context window but no tool usage, and it is not recommended. A dummy_tool method is added to handle cases where no tools are assigned. The logic for selecting models based on tags is updated to include the new #mini model. Additionally, a check is added to append the dummy_tool if no tools are provided.
1 parent 1849665 commit 3f7b05f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pipes/smart_with_tools.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
3. Third, reason about what model would best be used. What do your guidelines say about that?
5959
2. Within the <answer> tag, write out your final answer. Your answer should be a comma seperated list.
6060
1. First choose the model the final-agent will use. Try to find a good balance between performance and cost. Larger models are bigger.
61+
- There is #mini, this is a very small model, however it has a very large context window. This model can not use tools. This model is mostly not recommended.
6162
- Use #small for the simple queries or queries that mostly involve summarization or simple "mindless" work. This also invloves very simple tool use, like converting a file, etc.
6263
- Use #medium for task that requiere some creativity, writing of code, or complex tool-use.
6364
- Use #large for tasks that are mostly creative or involve the writing of complex code, math, etc.
@@ -627,6 +628,9 @@ class Valves(BaseModel):
627628
)
628629
OPENAI_API_KEY: str = Field(default="", description="Primary API key")
629630
MODEL_PREFIX: str = Field(default="SMART", description="Prefix before model ID")
631+
MINI_MODEL: str = Field(
632+
default="google/gemini-flash-1.5", description="Model for small tasks"
633+
)
630634
SMALL_MODEL: str = Field(
631635
default="openai/gpt-4o-mini", description="Model for small tasks"
632636
)
@@ -900,6 +904,15 @@ async def image_to_image(self, prompt: str, image_url: str = "", image_size: str
900904
async with session.post(url, headers=headers, json=payload) as response:
901905
result = await response.json()
902906
return result
907+
908+
async def dummy_tool(self):
909+
"""
910+
Just ignore this tool. You get this message because the user has not assigned you any tools to use.
911+
912+
:return: None
913+
"""
914+
915+
return "You have not assigned any tools to use."
903916

904917
async def pipe(
905918
self,
@@ -921,6 +934,7 @@ async def pipe(
921934

922935
# print(f"{body=}")
923936

937+
mini_model_id = self.valves.MINI_MODEL
924938
small_model_id = self.valves.SMALL_MODEL
925939
large_model_id = self.valves.LARGE_MODEL
926940
huge_model_id = self.valves.HUGE_MODEL
@@ -1021,6 +1035,8 @@ async def pipe(
10211035
csv_hastag_list = re.findall(r"<answer>(.*?)</answer>", content)
10221036
csv_hastag_list = csv_hastag_list[0] if csv_hastag_list else "unknown"
10231037

1038+
if "#mini" in csv_hastag_list:
1039+
model_to_use_id = mini_model_id
10241040
if "#small" in csv_hastag_list:
10251041
model_to_use_id = small_model_id
10261042
elif "#medium" in csv_hastag_list:
@@ -1078,6 +1094,11 @@ async def pipe(
10781094
or "#small" in body["messages"][-1]["content"]
10791095
):
10801096
model_to_use_id = small_model_id
1097+
elif (
1098+
"#.!" in body["messages"][-1]["content"]
1099+
or "#mini" in body["messages"][-1]["content"]
1100+
):
1101+
model_to_use_id = mini_model_id
10811102

10821103
if (
10831104
"#*yes" in body["messages"][-1]["content"]
@@ -1090,6 +1111,9 @@ async def pipe(
10901111
):
10911112
is_reasoning_needed = "NO"
10921113

1114+
if model_to_use_id == huge_model_id and len(tool_list) == 0:
1115+
tool_list.append("dummy_tool")
1116+
10931117
await send_status(
10941118
status_message=f"Planning complete. Using Model: {model_to_use_id}. Reasoning needed: {is_reasoning_needed}.",
10951119
done=True,
@@ -1221,6 +1245,25 @@ def create_pydantic_model_from_docstring(func):
12211245
)
12221246
)
12231247
self.SYSTEM_PROMPT_INJECTION = self.SYSTEM_PROMPT_INJECTION + PROMPT_ImageGen
1248+
if tool == "dummy_tool":
1249+
dummy_tools = [
1250+
(
1251+
self.dummy_tool,
1252+
"This is a dummy tool that does nothing. It is used when the user hasn't assigned any tools.",
1253+
)
1254+
]
1255+
for func, desc in dummy_tools:
1256+
tools.append(
1257+
StructuredTool(
1258+
func=None,
1259+
name=func.__name__,
1260+
coroutine=func,
1261+
args_schema=create_pydantic_model_from_docstring(
1262+
func
1263+
),
1264+
description=desc,
1265+
)
1266+
)
12241267

12251268
model_to_use = ChatOpenAI(model=model_to_use_id, **self.openai_kwargs) # type: ignore
12261269

0 commit comments

Comments
 (0)