- 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:
@@ -74,8 +74,12 @@ Once installed, the agent automatically calls `perplexity_search` whenever it ne
|
|||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| `query` | string | ✅ | The search query |
|
| `query` | string | ✅ | The search query |
|
||||||
| `recency` | string | — | Filter by age: `hour` · `day` · `week` · `month` · `year` |
|
| `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 (1–50) |
|
| `limit` | number | — | Max sources to include (1–50) |
|
||||||
|
|
||||||
|
**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.
|
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
|
### Output format
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ export default function (pi: ExtensionAPI) {
|
|||||||
description: "Filter results by recency",
|
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(
|
limit: Type.Optional(
|
||||||
Type.Number({ description: "Max sources to return", minimum: 1, maximum: 50 }),
|
Type.Number({ description: "Max sources to return", minimum: 1, maximum: 50 }),
|
||||||
),
|
),
|
||||||
@@ -77,6 +86,7 @@ export default function (pi: ExtensionAPI) {
|
|||||||
query: params.query,
|
query: params.query,
|
||||||
model,
|
model,
|
||||||
...(params.recency !== undefined ? { recency: params.recency } : {}),
|
...(params.recency !== undefined ? { recency: params.recency } : {}),
|
||||||
|
...(params.focus !== undefined ? { focus: params.focus } : {}),
|
||||||
},
|
},
|
||||||
auth,
|
auth,
|
||||||
signal,
|
signal,
|
||||||
|
|||||||
+30
-5
@@ -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";
|
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 {
|
export interface SearchParams {
|
||||||
query: string;
|
query: string;
|
||||||
recency?: "hour" | "day" | "week" | "month" | "year";
|
recency?: "hour" | "day" | "week" | "month" | "year";
|
||||||
model: string;
|
focus?: FocusMode;
|
||||||
|
model: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeUrl(url: string): string {
|
function normalizeUrl(url: string): string {
|
||||||
@@ -120,10 +145,10 @@ function buildRequestBody(params: SearchParams): Record<string, unknown> {
|
|||||||
query_str: query,
|
query_str: query,
|
||||||
params: {
|
params: {
|
||||||
query_str: query,
|
query_str: query,
|
||||||
search_focus: "internet",
|
search_focus: FOCUS_MAP[params.focus ?? "internet"].focus,
|
||||||
mode: "copilot",
|
mode: "copilot",
|
||||||
model_preference: params.model,
|
model_preference: params.model,
|
||||||
sources: ["web"],
|
sources: FOCUS_MAP[params.focus ?? "internet"].sources,
|
||||||
attachments: [],
|
attachments: [],
|
||||||
frontend_uuid: randomUUID(),
|
frontend_uuid: randomUUID(),
|
||||||
frontend_context_uuid: randomUUID(),
|
frontend_context_uuid: randomUUID(),
|
||||||
|
|||||||
Reference in New Issue
Block a user