mirror of
https://github.com/boxpositron/absolute-dotfiles.git
synced 2026-02-28 11:40:37 +00:00
feat(websearch.ts): add PerplexitySearch plugin for quick and deep research capabilities
This commit is contained in:
73
.config/opencode/plugin/websearch.ts
Normal file
73
.config/opencode/plugin/websearch.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import { type Plugin, tool } from "@opencode-ai/plugin";
|
||||||
|
|
||||||
|
export const PerplexitySearch: Plugin = async (ctx) => {
|
||||||
|
return {
|
||||||
|
tool: {
|
||||||
|
search: tool({
|
||||||
|
description:
|
||||||
|
"Run a quick search query to search the internet for results using Perplexity AI. Use this for quick lookups, latest information, and documentation.",
|
||||||
|
args: {
|
||||||
|
query: tool.schema.string().describe("Search query to execute"),
|
||||||
|
},
|
||||||
|
execute: async (args) => {
|
||||||
|
const url = "https://api.perplexity.ai/chat/completions";
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer " + process.env.PERPLEXITY_API_KEY,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: "sonar",
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: args.query,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
return JSON.stringify({
|
||||||
|
answer: data.choices?.[0]?.message?.content,
|
||||||
|
citations: data.citations || [],
|
||||||
|
sources: data.search_results || [],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
|
deepResearch: tool({
|
||||||
|
description:
|
||||||
|
"Conduct an in-depth research using Perplexity's deep research model. Use this for exhaustive research, detailed analysis, comprehensive reports, or complex multi-source synthesis.",
|
||||||
|
args: {
|
||||||
|
query: tool.schema.string().describe("Research query or topic for exhaustive analysis"),
|
||||||
|
},
|
||||||
|
execute: async (args) => {
|
||||||
|
const url = "https://api.perplexity.ai/chat/completions";
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer " + process.env.PERPLEXITY_API_KEY,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: "sonar-deep-research",
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: args.query,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
return JSON.stringify({
|
||||||
|
report: data.choices?.[0]?.message?.content,
|
||||||
|
citations: data.citations || [],
|
||||||
|
sources: data.search_results || [],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user