diff --git a/examples/nextjs-example/src/jobs/openai.ts b/examples/nextjs-example/src/jobs/openai.ts index 38a2a499e..f39ad1cee 100644 --- a/examples/nextjs-example/src/jobs/openai.ts +++ b/examples/nextjs-example/src/jobs/openai.ts @@ -58,6 +58,12 @@ new Job(client, { model: "text-davinci-003", prompt: "Create a good programming joke about Tasks", }); + + await io.openai.createEdit("edit", { + model: "text-davinci-edit-001", + input: "Thsi is ridddled with erors", + instruction: "Fix the spelling errors", + }); }, }); diff --git a/integrations/openai/src/index.ts b/integrations/openai/src/index.ts index 0cb2569d7..48a720036 100644 --- a/integrations/openai/src/index.ts +++ b/integrations/openai/src/index.ts @@ -6,6 +6,7 @@ import { cancelFineTune, createChatCompletion, createCompletion, + createEdit, createFile, createFineTune, createFineTuneFile, @@ -26,6 +27,7 @@ const tasks = { createChatCompletion, backgroundCreateCompletion, backgroundCreateChatCompletion, + createEdit, createFile, listFiles, createFineTuneFile, diff --git a/integrations/openai/src/tasks.ts b/integrations/openai/src/tasks.ts index 0f610ab49..6559dc870 100644 --- a/integrations/openai/src/tasks.ts +++ b/integrations/openai/src/tasks.ts @@ -2,12 +2,17 @@ import type { AuthenticatedTask } from "@trigger.dev/sdk"; import { CreateChatCompletionRequest, CreateCompletionRequest, + CreateEditRequest, CreateFineTuneRequest, OpenAIApi, } from "openai"; import { OpenAIIntegrationAuth } from "./types"; import { redactString } from "@trigger.dev/sdk"; -import { Prettify, fileFromString } from "@trigger.dev/integration-kit"; +import { + Prettify, + fileFromString, + truncate, +} from "@trigger.dev/integration-kit"; type OpenAIClientType = InstanceType; @@ -212,6 +217,47 @@ export const backgroundCreateChatCompletion: AuthenticatedTask< }, }; +type CreateEditResponseData = Prettify< + Awaited>["data"] +>; + +export const createEdit: AuthenticatedTask< + OpenAIClientType, + Prettify, + CreateEditResponseData +> = { + run: async (params, client) => { + return client.createEdit(params).then((res) => res.data); + }, + init: (params) => { + let properties = [ + { + label: "Model", + text: params.model, + }, + ]; + + if (params.input) { + properties.push({ + label: "Input", + text: truncate(params.input, 40), + }); + } + + properties.push({ + label: "Instruction", + text: truncate(params.instruction, 40), + }); + + return { + name: "Create edit", + params, + icon: "openai", + properties, + }; + }, +}; + type CreateFileResponseData = Awaited< ReturnType >["data"];