OpenAI Assistants & more

After OpenAI DevDay last week we got busy working on our @trigger.dev/openai integration and we're happy to announce that we now support GPT-4 Turbo, the new Assistants API, Dalle-3, and more, as well as some additional enhancements.

GPT-4 Turbo

GPT-4 Turbo is the newest model from OpenAI that includes up to 128K context and lower prices, and is supported by our integration by specifying the gpt-4-1106-preview model:


_10
await io.openai.chat.completions.create("debater-completion", {
_10
model: "gpt-4-1106-preview",
_10
messages: [
_10
{
_10
role: "user",
_10
content:
_10
'I want you to act as a debater. I will provide you with some topics related to current events and your task is to research both sides of the debates, present valid arguments for each side, refute opposing points of view, and draw persuasive conclusions based on evidence. Your goal is to help people come away from the discussion with increased knowledge and insight into the topic at hand. My first request is "I want an opinion piece about Deno."',
_10
},
_10
],
_10
});

Although we recommend the backgroundCreate variant as even though it's called Turbo, during preview it can take awhile to complete:


_11
// This will run in the background, so you don't have to worry about serverless function timeouts
_11
await io.openai.chat.completions.backgroundCreate("debater-completion", {
_11
model: "gpt-4-1106-preview",
_11
messages: [
_11
{
_11
role: "user",
_11
content:
_11
'I want you to act as a debater. I will provide you with some topics related to current events and your task is to research both sides of the debates, present valid arguments for each side, refute opposing points of view, and draw persuasive conclusions based on evidence. Your goal is to help people come away from the discussion with increased knowledge and insight into the topic at hand. My first request is "I want an opinion piece about Deno."',
_11
},
_11
],
_11
});

We've also improved completion tasks and added additional properties that make it easier to see your rate limits and how many tokens you have left:

image

Additionally, if an OpenAI request fails because of a rate limit error, we will automatically retry the request only after the rate limit has been reset.

Assistants

Also released on DevDay was the new Assistants API, which we now have support for:


_44
// Create a file and wait for it to be processed
_44
const file = await io.openai.files.createAndWaitForProcessing("upload-file", {
_44
purpose: "assistants",
_44
file: fs.createReadStream("./fixtures/mydata.csv"),
_44
});
_44
_44
// Create the assistant
_44
const assistant = await io.openai.beta.assistants.create("create-assistant", {
_44
name: "Data visualizer",
_44
description:
_44
"You are great at creating beautiful data visualizations. You analyze data present in .csv files, understand trends, and come up with data visualizations relevant to those trends. You also share a brief text summary of the trends observed.",
_44
model: payload.model,
_44
tools: [{ type: "code_interpreter" }],
_44
file_ids: [file.id],
_44
});
_44
_44
// Sometime later, you can now use the assistant by the assistant id:
_44
const run = await io.openai.beta.threads.createAndRunUntilCompletion(
_44
"create-thread",
_44
{
_44
assistant_id: payload.id,
_44
thread: {
_44
messages: [
_44
{
_44
role: "user",
_44
content:
_44
"Create 3 data visualizations based on the trends in this file.",
_44
file_ids: [payload.fileId],
_44
},
_44
],
_44
},
_44
}
_44
);
_44
_44
if (run.status !== "completed") {
_44
throw new Error(
_44
`Run finished with status ${run.status}: ${JSON.stringify(run.last_error)}`
_44
);
_44
}
_44
_44
const messages = await io.openai.beta.threads.messages.list(
_44
"list-messages",
_44
run.thread_id
_44
);

For more about how to use Assistants, check out our new OpenAI docs.

Images

We've added support for creating images in the background, similar to how our background completion works:


_10
const response = await io.openai.images.backgroundCreate("dalle-3-background", {
_10
model: "dall-e-3",
_10
prompt:
_10
"Create a comic strip featuring miles morales and spiderpunk fighting off the sinister six",
_10
});

Files

You can now wait for a file to be processed before continuing:


_10
const file = await io.openai.files.create("upload-file", {
_10
purpose: "assistants",
_10
file: fs.createReadStream("./fixtures/mydata.csv"),
_10
});
_10
_10
await io.openai.files.waitForProcessing("wait-for-file", file.id);

Or you can combine that into a single call:


_10
const file = await io.openai.files.createAndWaitForProcessing("upload-file", {
_10
purpose: "assistants",
_10
file: fs.createReadStream("./fixtures/mydata.csv"),
_10
});

New Docs

We've completely rewritten our OpenAI docs to make it easier to understand how to use our integration. Check them out at here.

How to update

The trigger.dev/* packages are now at v2.2.6. You can update using the following command:


_10
npx @trigger.dev/cli@latest update