OpenAI: createEdit
This commit is contained in:
@@ -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",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<typeof OpenAIApi>;
|
||||
|
||||
@@ -212,6 +217,47 @@ export const backgroundCreateChatCompletion: AuthenticatedTask<
|
||||
},
|
||||
};
|
||||
|
||||
type CreateEditResponseData = Prettify<
|
||||
Awaited<ReturnType<OpenAIClientType["createEdit"]>>["data"]
|
||||
>;
|
||||
|
||||
export const createEdit: AuthenticatedTask<
|
||||
OpenAIClientType,
|
||||
Prettify<CreateEditRequest>,
|
||||
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<OpenAIClientType["createFile"]>
|
||||
>["data"];
|
||||
|
||||
Reference in New Issue
Block a user