Skip to content

Commit ee847c6

Browse files
authored
Merge pull request #88 from olivier-lacroix/feat/remove-tool-wrapper
Remove tool wrapper
2 parents c4ea784 + 8b66317 commit ee847c6

File tree

1 file changed

+8
-56
lines changed

1 file changed

+8
-56
lines changed

pipelines/google/google_gemini.py

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
author_url: https://github.com/owndev/
55
project_url: https://github.com/owndev/Open-WebUI-Functions
66
funding_url: https://github.com/sponsors/owndev
7-
version: 1.6.6
7+
version: 1.6.7
8+
required_open_webui_version: 0.6.26
89
license: Apache License 2.0
910
description: Highly optimized Google Gemini pipeline with advanced image generation capabilities, intelligent compression, and streamlined processing workflows.
1011
features:
@@ -33,8 +34,6 @@
3334
"""
3435

3536
import os
36-
import inspect
37-
from functools import update_wrapper
3837
import re
3938
import time
4039
import asyncio
@@ -1340,53 +1339,6 @@ def _upload_image(
13401339
# Fallback to data URL if upload fails
13411340
return f"data:{mime_type};base64,{image_data}"
13421341

1343-
@staticmethod
1344-
def _create_tool(tool_def):
1345-
"""OpenwebUI tool is a functools.partial coroutine, which genai does not support directly.
1346-
See https://github.com/googleapis/python-genai/issues/907
1347-
1348-
This function wraps the tool into a callable that can be used with genai.
1349-
In particular, it sets the signature of the function properly,
1350-
removing any frozen keyword arguments (extra_params).
1351-
"""
1352-
bound_callable = tool_def["callable"]
1353-
1354-
# Create a wrapper for bound_callable, which is always async
1355-
async def wrapper(*args, **kwargs):
1356-
return await bound_callable(*args, **kwargs)
1357-
1358-
# Remove 'frozen' keyword arguments (extra_params) from the signature
1359-
original_sig = inspect.signature(bound_callable)
1360-
frozen_kwargs = {
1361-
"__event_emitter__",
1362-
"__event_call__",
1363-
"__user__",
1364-
"__metadata__",
1365-
"__request__",
1366-
"__model__",
1367-
}
1368-
new_parameters = []
1369-
1370-
for name, parameter in original_sig.parameters.items():
1371-
# Exclude keyword arguments that are frozen
1372-
if name in frozen_kwargs and parameter.kind in (
1373-
inspect.Parameter.POSITIONAL_OR_KEYWORD,
1374-
inspect.Parameter.KEYWORD_ONLY,
1375-
):
1376-
continue
1377-
# Keep remaining parameters
1378-
new_parameters.append(parameter)
1379-
1380-
new_sig = inspect.Signature(
1381-
parameters=new_parameters, return_annotation=original_sig.return_annotation
1382-
)
1383-
1384-
# Ensure name, docstring and signature are properly set
1385-
update_wrapper(wrapper, bound_callable)
1386-
wrapper.__signature__ = new_sig
1387-
1388-
return wrapper
1389-
13901342
def _configure_generation(
13911343
self,
13921344
body: Dict[str, Any],
@@ -1462,8 +1414,7 @@ def _configure_generation(
14621414
)
14631415

14641416
if __tools__ is not None and __metadata__.get("function_calling") == "native":
1465-
for name, tool_def in __tools__.items():
1466-
tool = self._create_tool(tool_def)
1417+
for name, tool in __tools__.items():
14671418
self.log.debug(
14681419
f"Adding tool '{name}' with signature {tool.__signature__}"
14691420
)
@@ -1923,10 +1874,11 @@ async def pipe(
19231874
# For image generation models, gather ALL images from the last user turn
19241875
if supports_image_generation:
19251876
try:
1926-
contents, system_instruction = (
1927-
await self._build_image_generation_contents(
1928-
messages, __event_emitter__
1929-
)
1877+
(
1878+
contents,
1879+
system_instruction,
1880+
) = await self._build_image_generation_contents(
1881+
messages, __event_emitter__
19301882
)
19311883
# For image generation, system_instruction is integrated into the prompt
19321884
# so it will be None here (this is expected and correct)

0 commit comments

Comments
 (0)