Repository navigation
search: Gemini Google Search grounding provider (Wave 3) - #82
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a2fc1c8a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| PasClaw.Providers.HTTP; | ||
|
|
||
| const | ||
| GEMINI_MODEL = 'gemini-1.5-flash'; |
There was a problem hiding this comment.
Use the legacy grounding tool with 1.5 Flash
With GEMINI_MODEL hardcoded to gemini-1.5-flash, the request body below enables the google_search tool, but Google's grounding docs show Gemini 1.5 REST requests using the legacy google_search_retrieval field and reserve google_search for Gemini 2.0+ models. In the default configuration this provider will send an invalid tool payload and fail instead of returning search results; either switch the default model to a 2.0+/2.5 model or emit the 1.5-specific tool shape.
Useful? React with 👍 / 👎.
|
|
||
| if (Kind = 'gemini') or (Kind = 'google_search') then | ||
| begin | ||
| Key := PickKey(Cfg.WebSearch.APIKey, 'PASCLAW_GEMINI_API_KEY'); |
There was a problem hiding this comment.
Honor PASCLAW_GOOGLE_API_KEY before config
For Gemini, PickKey returns Cfg.WebSearch.APIKey before this branch ever checks PASCLAW_GOOGLE_API_KEY, so a user with any api_key in config cannot override it with the Google-branded env var despite the new README documenting that either Gemini env var overrides api_key. This matters when rotating secrets or keeping a stale placeholder in config: PASCLAW_GOOGLE_API_KEY is silently ignored unless the config key is empty.
Useful? React with 👍 / 👎.
Sixth and (per the maintainer call) final port from picoclaw's
web-search lineup. Gemini isn't a traditional search endpoint — it's
the Gemini LLM with google_search as an enabled tool, so the API
returns a synthesised answer plus the source URLs the model
consulted. The adapter folds that into ISearchProvider's uniform
shape the same way Perplexity does:
Hits[0] = the synthesised answer (title="Gemini summary",
URL=first grounding URL if any, snippet=text truncated
to 1200 chars).
Hits[1..] = remaining groundingChunks[].web entries with real
{title, uri} pairs Gemini supplies (unlike Perplexity
which returns bare URLs).
Caps total hits at the caller's count.
PasClaw.Search.Gemini
Endpoint: POST https://generativelanguage.googleapis.com/v1beta/
models/gemini-1.5-flash:generateContent?key=<api-key>
Body: { "contents":[{"parts":[{"text":Q}]}],
"tools":[{"google_search":{}}] }
Model is hardcoded to gemini-1.5-flash — free-tier-friendly,
supports google_search grounding, fast. Switching to 1.5-pro or
2.0-flash is a one-constant patch; we don't add another config
field for one provider.
Response parsing has two helpers:
ExtractAnswer walks candidates[0].content.parts[].text
and concatenates non-empty pieces.
ExtractGroundingURLs walks candidates[0].groundingMetadata.
groundingChunks[].web → fills parallel
Titles/URLs arrays up to their declared
length. Drops chunks with no uri.
Factory
Two case branches under one if — "gemini" or "google_search" both
map to the Gemini provider, picoclaw uses the longer label and I
want either to work. Reads $PASCLAW_GEMINI_API_KEY first, then
$PASCLAW_GOOGLE_API_KEY as a fallback (some users already have
the Google-branded var set from gcloud / aistudio defaults
rather than the explicit Gemini key name).
dproj DCCReference for the new unit. Makefile unchanged (channels
dir already on UNIT_DIRS).
README
env-var table picks up PASCLAW_GEMINI_API_KEY (with note that
PASCLAW_GOOGLE_API_KEY works too). Provider table grows a sixth
row explaining the google_search-grounding shape. Repo-layout
search/ line spells out the full set of six providers.
Verified locally:
make builds clean under FPC 3.2.2.
pasclaw status / --help byte-identical.
Closes the picoclaw web-search catch-up. Maintainer skipped GLM
(Zhipu) and Baidu (Qianfan) — narrower Delphi/FPC audience for the
Chinese-ecosystem auth ceremonies; can land later if anyone shows
up wanting them.
PR ordering: this stacks on PR #81 (Wave 2 — SearXNG + Perplexity)
so the factory case ladder lands in one coherent shape rather than
fighting textual conflicts. Merge #81 first.
https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
3a2fc1c to
3f1e8af
Compare
Sixth and (per the maintainer call) final port from picoclaw's web-search lineup. Gemini isn't a traditional search endpoint — it's the Gemini LLM with
google_searchas an enabled tool, so the API returns a synthesised answer plus the source URLs the model consulted. The adapter folds that intoISearchProvider's uniform shape the same way Perplexity does:Hits[0]—Title="Gemini summary",URL=first grounding URL if any,Snippet=answer text truncated to 1200 chars.Hits[1..]— remaininggroundingChunks[].webentries with real{title, uri}pairs Gemini supplies (unlike Perplexity which returns bare URLs).Caps total hits at the caller's
count.PasClaw.Search.GeminiModel hardcoded to
gemini-1.5-flash— free-tier-friendly, supportsgoogle_searchgrounding, fast. Switching to 1.5-pro or 2.0-flash is a one-constant patch; not adding a config field for one provider.Response parsing has two helpers:
ExtractAnswercandidates[0].content.parts[].textand concatenates non-empty pieces.ExtractGroundingURLscandidates[0].groundingMetadata.groundingChunks[].web→ fills parallel Titles/URLs arrays up to their declared length. Drops chunks with nouri.Factory + env
Two case branches under one
if—geminiorgoogle_searchboth map to the Gemini provider, picoclaw uses the longer label and either works here. Env probe reads$PASCLAW_GEMINI_API_KEYfirst, then falls back to$PASCLAW_GOOGLE_API_KEY(some users already have the Google-branded var set fromgcloud/ AI Studio defaults).README
PASCLAW_GEMINI_API_KEY(with the_GOOGLE_API_KEYnote).google_search-grounding shape.search/line spells out the full set of six providers.Verification
make— clean build under FPC 3.2.2.pasclaw statusand--helpbyte-identical.What's next
Closes the picoclaw web-search catch-up at six providers. Maintainer skipped GLM (Zhipu) and Baidu (Qianfan) — narrower Delphi/FPC audience for the Chinese-ecosystem auth ceremonies; can land later if anyone shows up wanting them.
PR ordering
This branch stacks on PR #81 (Wave 2 — SearXNG + Perplexity) so the factory case ladder lands in one coherent shape rather than fighting textual conflicts. Please merge #81 first; this PR's base will auto-retarget to
mainafter that.https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code