Skip to content

Commit 6cd2c5d

Browse files
authored
Merge branch 'main' into patch-1
2 parents 4cbb0e7 + 2477bb4 commit 6cd2c5d

2 files changed

Lines changed: 20 additions & 26 deletions

File tree

docs/google-gemini-integration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ VERTEX_AI_RAG_STORE="projects/your-project/locations/global/collections/default_
199199
>
200200
> Future versions may extend these settings to also optimize generated images before upload/display.
201201
202-
## Grounding with Google search
202+
## Web search and access
203203

204-
Grounding with Google search is enabled/disabled with the `google_search_tool` feature, which can be switched on/off in a Filter.
204+
[Grounding with Google search](https://ai.google.dev/gemini-api/docs/google-search) together with the [URL context tool](https://ai.google.dev/gemini-api/docs/url-context) are enabled/disabled together via the `google_search_tool` feature, which can be switched on/off in a Filter.
205205

206-
For instance, the following [Filter (google_search_tool.py)](../filters/google_search_tool.py) will replace Open Web UI default web search function with google search grounding.
206+
For instance, the following [Filter (google_search_tool.py)](../filters/google_search_tool.py) will replace Open Web UI default web search function with Google search grounding + the URL context tool.
207207

208-
When enabled, sources and google queries used by Gemini will be displayed with the response.
208+
When enabled, sources and google queries from the search used by Gemini will be displayed with the response.
209209

210210
## Grounding with Vertex AI Search
211211

pipelines/google/google_gemini.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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.8.4
7+
version: 1.9.1
88
required_open_webui_version: 0.6.26
99
license: Apache License 2.0
1010
description: Highly optimized Google Gemini pipeline with advanced image generation capabilities, intelligent compression, and streamlined processing workflows.
@@ -28,6 +28,7 @@
2828
- Intelligent grounding with Google search integration
2929
- Vertex AI Search grounding for RAG
3030
- Native tool calling support with automatic signature management
31+
- URL context grounding for specified web pages
3132
- Unified image processing with consolidated helper methods
3233
- Optimized payload creation for image generation models
3334
- Configurable image processing parameters (size, quality, compression)
@@ -1692,14 +1693,17 @@ def _configure_generation(
16921693
]
16931694
gen_config_params |= {"safety_settings": safety_settings}
16941695

1696+
# Add various tools to Gemini as required
16951697
features = __metadata__.get("features", {})
1698+
params = __metadata__.get("params", {})
1699+
tools = []
1700+
16961701
if features.get("google_search_tool", False):
16971702
self.log.debug("Enabling Google search grounding")
1698-
gen_config_params.setdefault("tools", []).append(
1699-
types.Tool(google_search=types.GoogleSearch())
1700-
)
1703+
tools.append(types.Tool(google_search=types.GoogleSearch()))
1704+
self.log.debug("Enabling URL context grounding")
1705+
tools.append(types.Tool(url_context=types.UrlContext()))
17011706

1702-
params = __metadata__.get("params", {})
17031707
if features.get("vertex_ai_search", False) or (
17041708
self.valves.USE_VERTEX_AI
17051709
and (self.valves.VERTEX_AI_RAG_STORE or os.getenv("VERTEX_AI_RAG_STORE"))
@@ -1713,7 +1717,7 @@ def _configure_generation(
17131717
self.log.debug(
17141718
f"Enabling Vertex AI Search grounding: {vertex_rag_store}"
17151719
)
1716-
gen_config_params.setdefault("tools", []).append(
1720+
tools.append(
17171721
types.Tool(
17181722
retrieval=types.Retrieval(
17191723
vertex_ai_search=types.VertexAISearch(
@@ -1726,14 +1730,18 @@ def _configure_generation(
17261730
self.log.warning(
17271731
"Vertex AI Search requested but vertex_rag_store not provided in params, valves, or env"
17281732
)
1733+
17291734
if __tools__ is not None and params.get("function_calling") == "native":
17301735
for name, tool_def in __tools__.items():
17311736
if not name.startswith("_"):
17321737
tool = tool_def["callable"]
17331738
self.log.debug(
17341739
f"Adding tool '{name}' with signature {tool.__signature__}"
17351740
)
1736-
gen_config_params.setdefault("tools", []).append(tool)
1741+
tools.append(tool)
1742+
1743+
if tools:
1744+
gen_config_params["tools"] = tools
17371745

17381746
# Filter out None values for generation config
17391747
filtered_params = {k: v for k, v in gen_config_params.items() if v is not None}
@@ -1783,8 +1791,6 @@ async def _process_grounding_metadata(
17831791
grounding_metadata_list: List[types.GroundingMetadata],
17841792
text: str,
17851793
__event_emitter__: Callable,
1786-
*,
1787-
emit_replace: bool = True,
17881794
):
17891795
"""Process and emit grounding metadata events."""
17901796
grounding_chunks = []
@@ -1852,17 +1858,8 @@ async def _process_grounding_metadata(
18521858
cited_chunks.append(text_bytes[last_byte_index:].decode(ENCODING))
18531859

18541860
replaced_text = "".join(cited_chunks)
1855-
if emit_replace:
1856-
await __event_emitter__(
1857-
{
1858-
"type": "replace",
1859-
"data": {"content": replaced_text},
1860-
}
1861-
)
18621861

1863-
# Return the transformed text when requested by caller
1864-
if not emit_replace:
1865-
return replaced_text if replaced_text is not None else text
1862+
return replaced_text if replaced_text is not None else text
18661863

18671864
async def _handle_streaming_response(
18681865
self,
@@ -2000,12 +1997,10 @@ async def emit_chat_event(event_type: str, data: Dict[str, Any]) -> None:
20001997
# After processing all chunks, handle grounding data
20011998
final_answer_text = "".join(answer_chunks)
20021999
if grounding_metadata_list and __event_emitter__:
2003-
# Don't emit replace here; we'll compose final content below
20042000
cited = await self._process_grounding_metadata(
20052001
grounding_metadata_list,
20062002
final_answer_text,
20072003
__event_emitter__,
2008-
emit_replace=False,
20092004
)
20102005
final_answer_text = cited or final_answer_text
20112006

@@ -2383,7 +2378,6 @@ async def get_response():
23832378
grounding_metadata_list,
23842379
final_answer,
23852380
__event_emitter__,
2386-
emit_replace=False,
23872381
)
23882382
final_answer = cited or final_answer
23892383

0 commit comments

Comments
 (0)