We've made a small tweak to our OpenAI integration that allows it to be used with any OpenAI compatible API, such as Perplexity.ai:


import { OpenAI } from "@trigger.dev/openai";
const perplexity = new OpenAI({
id: "perplexity",
apiKey: process.env["PERPLEXITY_API_KEY"]!,
baseURL: "https://api.perplexity.ai", // specify the base URL for Perplexity.ai
icon: "brand-open-source", // change the task icon to a generic open source logo
});

Since Perplexity.ai is compatible with OpenAI, you can use the same tasks as with OpenAI but using Open Source models, like minstral-7b-instruct:


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

We also support the Azure OpenAI Service through the defaultHeaders and defaultQuery options:


import { OpenAI } from "@trigger.dev/openai";
const azureOpenAI = new OpenAI({
id: "azure-openai",
apiKey: process.env["AZURE_API_KEY"]!,
icon: "brand-azure",
baseURL:
"https://my-resource.openai.azure.com/openai/deployments/my-gpt35-16k-deployment",
defaultQuery: { "api-version": "2023-06-01-preview" },
defaultHeaders: { "api-key": process.env["AZURE_API_KEY"] },
});

Ready to start building?

Build and deploy your first task in 3 minutes.

Get started now