1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { PplxRequest, PplxResponse } from "https://esm.town/v/nbbaier/pplxTypes";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=42";
export const pplx = async (options: PplxRequest & { apiKey?: string }): Promise<PplxResponse> => {
const token = options.apiKey ? options.apiKey : Deno.env.get("PERPLEXITY_API_KEY");
return await fetchJSON("https://api.perplexity.ai/chat/completions", {
method: "POST",
headers: {
"accept": "application/json",
"authorization": `Bearer ${token}`,
"content-type": "application/json",
},
body: JSON.stringify(options),
});
};