feat: supporto ai Focus Modes di Perplexity (parametro 'focus')
CI / test (push) Canceled after 0s

- Aggiunto il parametro 'focus' al tool perplexity_search per selezionare la
  fonte di conoscenza (Focus Mode).
- FOCUS_MAP: mappa focus -> search_focus + sources usati dall'endpoint
  perplexity_ask (internet/web, academic/scholar, writing, wolfram, youtube,
  reddit, math, social, finance).
- default: internet (comportamento invariato).
- README aggiornato.
This commit is contained in:
Matteo Benedetto
2026-08-11 21:22:56 +02:00
parent 72ce74541f
commit a5e1a80301
3 changed files with 44 additions and 5 deletions
+4
View File
@@ -74,8 +74,12 @@ Once installed, the agent automatically calls `perplexity_search` whenever it ne
|---|---|---|---|
| `query` | string | ✅ | The search query |
| `recency` | string | — | Filter by age: `hour` · `day` · `week` · `month` · `year` |
| `focus` | string | — | Perplexity **Focus Mode** (source domain): `internet` · `academic` · `writing` · `wolfram` · `youtube` · `reddit` · `math` · `social` · `finance` (default `internet`) |
| `limit` | number | — | Max sources to include (150) |
**Focus Modes** let the agent route the search to a specific knowledge source:
`academic` → peer-reviewed/scholarly (PubMed, arXiv, Semantic Scholar), `youtube` → video transcripts, `reddit` → community/opinions, `wolfram`/`math` → computations, `social` → social platforms, `finance` → financial/SEC data, `writing` → model-only (no live search).
Model selection is configured globally with `/perplexity-config` or `PI_PERPLEXITY_MODEL`; it is not exposed as a tool parameter, so agent-generated tool calls cannot accidentally override your configured model.
### Output format
+10
View File
@@ -27,6 +27,15 @@ export default function (pi: ExtensionAPI) {
description: "Filter results by recency",
}),
),
focus: Type.Optional(
StringEnum(
["internet", "academic", "writing", "wolfram", "youtube", "reddit", "math", "social", "finance"] as const,
{
description:
"Perplexity Focus Mode: source domain to search (internet=web, academic, writing, wolfram/math, youtube, reddit, social, finance)",
},
),
),
limit: Type.Optional(
Type.Number({ description: "Max sources to return", minimum: 1, maximum: 50 }),
),
@@ -77,6 +86,7 @@ export default function (pi: ExtensionAPI) {
query: params.query,
model,
...(params.recency !== undefined ? { recency: params.recency } : {}),
...(params.focus !== undefined ? { focus: params.focus } : {}),
},
auth,
signal,
+30 -5
View File
@@ -8,10 +8,35 @@ import { PERPLEXITY_USER_AGENT, PERPLEXITY_API_VERSION } from "../constants.js";
const PERPLEXITY_ENDPOINT = "https://www.perplexity.ai/rest/sse/perplexity_ask";
export type FocusMode =
| "internet"
| "academic"
| "writing"
| "wolfram"
| "youtube"
| "reddit"
| "math"
| "social"
| "finance";
// Mappa Focus Mode → search_focus + sources usati dall'endpoint perplexity_ask
const FOCUS_MAP: Record<FocusMode, { focus: string; sources: string[] }> = {
internet: { focus: "internet", sources: ["web"] },
academic: { focus: "academic", sources: ["scholar"] },
writing: { focus: "writing", sources: [] },
wolfram: { focus: "wolfram", sources: ["wolfram"] },
youtube: { focus: "youtube", sources: ["youtube"] },
reddit: { focus: "reddit", sources: ["reddit"] },
math: { focus: "math", sources: ["wolfram"] },
social: { focus: "social", sources: ["social"] },
finance: { focus: "finance", sources: ["finance"] },
};
export interface SearchParams {
query: string;
recency?: "hour" | "day" | "week" | "month" | "year";
model: string;
query: string;
recency?: "hour" | "day" | "week" | "month" | "year";
focus?: FocusMode;
model: string;
}
function normalizeUrl(url: string): string {
@@ -120,10 +145,10 @@ function buildRequestBody(params: SearchParams): Record<string, unknown> {
query_str: query,
params: {
query_str: query,
search_focus: "internet",
search_focus: FOCUS_MAP[params.focus ?? "internet"].focus,
mode: "copilot",
model_preference: params.model,
sources: ["web"],
sources: FOCUS_MAP[params.focus ?? "internet"].sources,
attachments: [],
frontend_uuid: randomUUID(),
frontend_context_uuid: randomUUID(),