Add chat completion task
This commit is contained in:
@@ -69,6 +69,8 @@ const dynamicSchedule = new DynamicSchedule(client, {
|
||||
|
||||
const enabled = true;
|
||||
|
||||
const CHAT_MODELS = ["gpt-3.5-turbo"];
|
||||
|
||||
new Job(client, {
|
||||
id: "openai-test",
|
||||
name: "OpenAI Test",
|
||||
@@ -85,6 +87,20 @@ new Job(client, {
|
||||
openai,
|
||||
},
|
||||
run: async (payload, io, ctx) => {
|
||||
if (CHAT_MODELS.includes(payload.model)) {
|
||||
const completion = await io.openai.createChatCompletion("✨", {
|
||||
model: payload.model,
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: payload.prompt,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return completion;
|
||||
}
|
||||
|
||||
const completion = await io.openai.createCompletion("✨", {
|
||||
model: payload.model,
|
||||
prompt: payload.prompt,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { OpenAIApi, Configuration } from "openai";
|
||||
import type { IntegrationClient, TriggerIntegration } from "@trigger.dev/sdk";
|
||||
import { createCompletion } from "./tasks";
|
||||
import { createChatCompletion, createCompletion } from "./tasks";
|
||||
|
||||
const tasks = {
|
||||
createCompletion,
|
||||
createChatCompletion,
|
||||
};
|
||||
|
||||
export type OpenAIIntegrationOptions = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { AuthenticatedTask } from "@trigger.dev/sdk";
|
||||
import { Configuration, OpenAIApi } from "openai";
|
||||
import { CreateChatCompletionRequest, OpenAIApi } from "openai";
|
||||
|
||||
type OpenAIClientType = InstanceType<typeof OpenAIApi>;
|
||||
|
||||
@@ -40,3 +40,26 @@ export const createCompletion: AuthenticatedTask<
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const createChatCompletion: AuthenticatedTask<
|
||||
OpenAIClientType,
|
||||
CreateChatCompletionRequest,
|
||||
Awaited<ReturnType<OpenAIClientType["createChatCompletion"]>>["data"]
|
||||
> = {
|
||||
run: async (params, client) => {
|
||||
return client.createChatCompletion(params).then((res) => res.data);
|
||||
},
|
||||
init: (params) => {
|
||||
return {
|
||||
name: "Completion",
|
||||
params,
|
||||
icon: "openai",
|
||||
properties: [
|
||||
{
|
||||
label: "model",
|
||||
text: params.model,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -417,7 +417,7 @@ export const RunTaskOptionsSchema = z.object({
|
||||
delayUntil: z.coerce.date().optional(),
|
||||
description: z.string().optional(),
|
||||
properties: z.array(DisplayPropertySchema).optional(),
|
||||
params: SerializableJsonSchema.optional(),
|
||||
params: z.any(),
|
||||
trigger: TriggerMetadataSchema.optional(),
|
||||
redact: RedactSchema.optional(),
|
||||
connectionKey: z.string().optional(),
|
||||
|
||||
Generated
+1229
-472
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user