diff --git a/docs/images/perplexity.png b/docs/images/perplexity.png new file mode 100644 index 000000000..557c8fa44 Binary files /dev/null and b/docs/images/perplexity.png differ diff --git a/docs/integrations/apis/openai.mdx b/docs/integrations/apis/openai.mdx index 9e19ef187..bef359982 100644 --- a/docs/integrations/apis/openai.mdx +++ b/docs/integrations/apis/openai.mdx @@ -56,3 +56,60 @@ Once you have set up a OpenAI client, you can use it to create tasks. Perform different AI-powered tasks using OpenAI. + +## Usage as Universal Client + +You can use our OpenAI integration as a universal client to interact with other OpenAI-compatible APIs, such as [Perplexity.ai](https://docs.perplexity.ai/) + +```ts +import { OpenAI } from "@trigger.dev/openai"; + +const perplexity = new OpenAI({ + id: "perplexity", + apiKey: process.env["PERPLEXITY_API_KEY"]!, + baseURL: "https://api.perplexity.ai", + icon: "brand-open-source", +}); +``` + +Since [Perplexity.ai](https://docs.perplexity.ai/) is compatible with OpenAI, you can use the same tasks as with OpenAI. + +```ts +client.defineJob({ + id: "perplexity-tasks", + name: "Perplexity Tasks", + version: "0.0.1", + trigger: eventTrigger({ + name: "perplexity.tasks", + }), + integrations: { + perplexity, + }, + run: async (payload, io, ctx) => { + await io.perplexity.chat.completions.create("chat-completion", { + model: "mistral-7b-instruct", + messages: [ + { + role: "user", + content: "Create a good programming joke about background jobs", + }, + ], + }); + + // Run this in the background + await io.perplexity.chat.completions.backgroundCreate("background-chat-completion", { + model: "mistral-7b-instruct", + messages: [ + { + role: "user", + content: "If you were a programming language, what would you be and why?", + }, + ], + }); + }, +}); +``` + +And you'll get the same experience in the Run Dashboard when viewing the logs: + +![Perplexity.ai logs](/images/perplexity.png) diff --git a/references/job-catalog/src/openai.ts b/references/job-catalog/src/openai.ts index 222e5b11d..e8e96f5f6 100644 --- a/references/job-catalog/src/openai.ts +++ b/references/job-catalog/src/openai.ts @@ -90,7 +90,7 @@ client.defineJob({ perplexity, }, run: async (payload, io, ctx) => { - await io.perplexity.createChatCompletion("chat-completion", { + await io.perplexity.chat.completions.create("chat-completion", { model: "mistral-7b-instruct", messages: [ { @@ -100,7 +100,7 @@ client.defineJob({ ], }); - await io.perplexity.backgroundCreateChatCompletion("background-chat-completion", { + await io.perplexity.chat.completions.backgroundCreate("background-chat-completion", { model: "mistral-7b-instruct", messages: [ {