Skip to content

search: SearXNG + Perplexity providers (Wave 2) - #81

Merged
FMXExpress merged 1 commit into
mainfrom
claude/web-search-wave2
May 30, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/web-search-wave2

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Two more providers plugged into the same factory PR #80 landed. Both drop into web_search without touching its handler — the factory's case ladder grew two branches.

PasClaw.Search.SearXNG

Self-hosted meta-search adapter. SearXNG instances are per-user, so there's no public default — web_search.base_url MUST be set (e.g. "https://searx.be") or the factory returns a clear "base_url missing" error.

GET <base>/search?format=json&safesearch=1&pageno=1&q=<url-enc>

Response is {"results":[{"title","url","content","engine","score"}, …], "number_of_results": N}. SearXNG already dedupes across upstream engines and orders by score, so the first N are the best.

Most public instances are open. Protected ones get an optional bearer via $PASCLAW_SEARXNG_API_KEY (env wins over web_search.api_key).

PasClaw.Search.Perplexity

Sonar API adapter. Perplexity returns a synthesised answer plus a flat citations[] array of URLs — not raw search hits. The adapter maps that into ISearchProvider by treating the answer as the first "hit":

  • Hits[0] — Title "Perplexity answer", URL = first citation, Snippet = answer text (truncated at 1200 chars).
  • Hits[1..] — bare citation URLs the model can web_fetch for more detail.

Caps at the caller's count so a 10-citation answer still respects k=3.

POST api.perplexity.ai/chat/completions
{"model":"sonar","messages":[{"role":"user","content":Q}],"max_tokens":1024}

Config + factory

TWebSearchConfig gains BaseURL: string (serialised only when non-empty so existing config.json round-trips byte-identical). The factory grows two more case branches; each new provider's env-var probe ($PASCLAW_SEARXNG_API_KEY, $PASCLAW_PERPLEXITY_API_KEY) wins over web_search.api_key.

README

  • Env-var table picks up $PASCLAW_SEARXNG_API_KEY + $PASCLAW_PERPLEXITY_API_KEY.
  • Provider table grows two rows explaining SearXNG's base_url requirement and Perplexity's one-answer-plus-citations shape.
  • Repository-layout search/ line spells out the full set (5 providers).

Verification

  • make — clean build under FPC 3.2.2 (5 providers + HTML helper + factory all compile in one pass).
  • Existing 13/13 HTMLToText smoke from Wave 1 still passes (unchanged code).
  • pasclaw status and --help byte-identical.

Wave 3 (Gemini Google Search) follows on a branch off this one so the factory edits don't textually conflict. GLM (Zhipu) and Baidu (Qianfan) intentionally skipped per the maintainer.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

Two more web-search providers plugged into the same factory PR #80
landed. Both drop into the existing web_search tool without touching
its handler — the factory's case ladder grew two branches.

PasClaw.Search.SearXNG
  Self-hosted meta-search adapter. SearXNG instances are per-user,
  so there's no public default — config.web_search.base_url MUST be
  set (e.g. "https://searx.be") or the factory returns a clear
  "base_url missing" error. Endpoint:
    GET <base>/search?format=json&safesearch=1&pageno=1&q=<url-enc>
  Response: {"results":[{"title","url","content","engine","score"},…],
             "number_of_results": N}
  We pick title/url/content; SearXNG dedupes across upstream engines
  and orders by score so the first N already are the best.

  Most public instances are open. For protected ones an optional
  bearer token plumbs in via $PASCLAW_SEARXNG_API_KEY (env wins
  over web_search.api_key, same rule the other providers use).

PasClaw.Search.Perplexity
  Sonar API adapter. Perplexity returns a synthesised answer plus
  a flat citations[] array of URLs — not raw search hits. The
  adapter maps that into ISearchProvider by treating the answer as
  the first "hit" (title="Perplexity answer", URL=first citation
  if any, snippet=answer text truncated to 1200 chars) and each
  subsequent citation as a bare URL the model can web_fetch for
  more detail. Caps at the caller's count so a 10-citation answer
  still respects k=3.
  Endpoint: POST api.perplexity.ai/chat/completions
  Body:     {"model":"sonar","messages":[{"role":"user","content":Q}],
             "max_tokens":1024}

TWebSearchConfig + factory
  TWebSearchConfig gains BaseURL: string (serialised only when
  non-empty, matches the rest of the field's emit-when-non-default
  rule so existing config.json round-trips byte-identical). The
  factory grows two more case branches in the obvious places, plus
  one new env-var probe each.

PasClaw.dproj DCCReference for the two new units. Makefile and the
tool registration sites unchanged — both providers slot into the
existing web_search dispatch.

README
  env-var table picks up $PASCLAW_SEARXNG_API_KEY +
  $PASCLAW_PERPLEXITY_API_KEY. Provider table grows two rows
  explaining the base_url requirement for SearXNG and the
  one-answer-plus-citations shape of Perplexity. Repository-layout
  search/ line spells out the full set.

Verified locally:
  make builds clean under FPC 3.2.2 (5 search providers + 1 HTML
  helper + 1 factory all compile in one pass).
  Existing 13/13 HTMLToText smoke from Wave 1 still passes.
  pasclaw status + --help byte-identical.

Wave 3 follows: Gemini Google Search on top of this branch so the
factory edits don't textually conflict. GLM (Zhipu) and Baidu
(Qianfan) intentionally skipped per the maintainer — narrower
audience for the auth ceremony.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8fdf33db18

ℹ️ 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".

Comment on lines +158 to +159
Citations := Root.ChildArray('citations');
if Citations <> nil then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Perplexity answers when citations are null

When Perplexity returns a normal choices[0].message.content but citations is null/omitted (the official schema marks citations as nullable: https://docs.perplexity.ai/api-reference/sonar-post), this guard skips all hit construction, so web_search reports no hits and drops the answer entirely. Move the synthesized-answer hit creation outside the citations-only branch and only use citations to populate URLs/additional results.

Useful? React with 👍 / 👎.

@FMXExpress
FMXExpress merged commit 6e2b35d into main May 30, 2026
FMXExpress pushed a commit that referenced this pull request May 30, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants