Skip to content

Commit 5ae107d

Browse files
authored
Merge pull request #115 from olivier-lacroix/feat/url-context
Add URL context to google search
2 parents 7131114 + 303a198 commit 5ae107d

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

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: 15 additions & 7 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.0
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)
@@ -1687,14 +1688,17 @@ def _configure_generation(
16871688
]
16881689
gen_config_params |= {"safety_settings": safety_settings}
16891690

1691+
# Add various tools to Gemini as required
16901692
features = __metadata__.get("features", {})
1693+
params = __metadata__.get("params", {})
1694+
tools = []
1695+
16911696
if features.get("google_search_tool", False):
16921697
self.log.debug("Enabling Google search grounding")
1693-
gen_config_params.setdefault("tools", []).append(
1694-
types.Tool(google_search=types.GoogleSearch())
1695-
)
1698+
tools.append(types.Tool(google_search=types.GoogleSearch()))
1699+
self.log.debug("Enabling URL context grounding")
1700+
tools.append(types.Tool(url_context=types.UrlContext()))
16961701

1697-
params = __metadata__.get("params", {})
16981702
if features.get("vertex_ai_search", False) or (
16991703
self.valves.USE_VERTEX_AI
17001704
and (self.valves.VERTEX_AI_RAG_STORE or os.getenv("VERTEX_AI_RAG_STORE"))
@@ -1708,7 +1712,7 @@ def _configure_generation(
17081712
self.log.debug(
17091713
f"Enabling Vertex AI Search grounding: {vertex_rag_store}"
17101714
)
1711-
gen_config_params.setdefault("tools", []).append(
1715+
tools.append(
17121716
types.Tool(
17131717
retrieval=types.Retrieval(
17141718
vertex_ai_search=types.VertexAISearch(
@@ -1721,14 +1725,18 @@ def _configure_generation(
17211725
self.log.warning(
17221726
"Vertex AI Search requested but vertex_rag_store not provided in params, valves, or env"
17231727
)
1728+
17241729
if __tools__ is not None and params.get("function_calling") == "native":
17251730
for name, tool_def in __tools__.items():
17261731
if not name.startswith("_"):
17271732
tool = tool_def["callable"]
17281733
self.log.debug(
17291734
f"Adding tool '{name}' with signature {tool.__signature__}"
17301735
)
1731-
gen_config_params.setdefault("tools", []).append(tool)
1736+
tools.append(tool)
1737+
1738+
if tools:
1739+
gen_config_params["tools"] = tools
17321740

17331741
# Filter out None values for generation config
17341742
filtered_params = {k: v for k, v in gen_config_params.items() if v is not None}

0 commit comments

Comments
 (0)