@trigger.dev/openai: Upgrade to openai-node SDK 4.13.0, add support for request options and defaultQuery/defaultHeaders
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@trigger.dev/openai": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Upgrade to openai-node SDK 4.13.0, add support for request options and defaultQuery/defaultHeaders
|
||||||
@@ -16,19 +16,21 @@
|
|||||||
"@trigger.dev/tsconfig": "workspace:*",
|
"@trigger.dev/tsconfig": "workspace:*",
|
||||||
"@types/node": "18",
|
"@types/node": "18",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"tsup": "^6.5.0"
|
"tsup": "^6.5.0",
|
||||||
|
"typescript": "^4.9.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"build": "npm run clean && npm run build:tsup",
|
"build": "npm run clean && npm run build:tsup",
|
||||||
"build:tsup": "tsup"
|
"build:tsup": "tsup",
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"openai": "^4.2.0",
|
"openai": "^4.13.0",
|
||||||
"@trigger.dev/sdk": "workspace:^2.2.1",
|
"@trigger.dev/sdk": "workspace:^2.2.1",
|
||||||
"@trigger.dev/integration-kit": "workspace:^2.2.1"
|
"@trigger.dev/integration-kit": "workspace:^2.2.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.8.0"
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,32 @@
|
|||||||
import { IntegrationTaskKey, Prettify, redactString } from "@trigger.dev/sdk";
|
import { IntegrationTaskKey, Prettify } from "@trigger.dev/sdk";
|
||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
import { OpenAIRunTask } from "./index";
|
import { OpenAIRunTask } from "./index";
|
||||||
import { createTaskUsageProperties } from "./taskUtils";
|
import {
|
||||||
|
backgroundTaskRetries,
|
||||||
|
createBackgroundFetchHeaders,
|
||||||
|
createBackgroundFetchUrl,
|
||||||
|
createTaskUsageProperties,
|
||||||
|
} from "./taskUtils";
|
||||||
|
import { OpenAIIntegrationOptions, OpenAIRequestOptions } from "./types";
|
||||||
|
|
||||||
export class Chat {
|
export class Chat {
|
||||||
constructor(private runTask: OpenAIRunTask) {}
|
constructor(
|
||||||
|
private runTask: OpenAIRunTask,
|
||||||
|
private options: OpenAIIntegrationOptions
|
||||||
|
) {}
|
||||||
|
|
||||||
completions = {
|
completions = {
|
||||||
create: (
|
create: (
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: Prettify<OpenAI.Chat.CompletionCreateParamsNonStreaming>
|
params: Prettify<OpenAI.Chat.ChatCompletionCreateParamsNonStreaming>,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.Chat.ChatCompletion> => {
|
): Promise<OpenAI.Chat.ChatCompletion> => {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
const response = await client.chat.completions.create(params, {
|
const response = await client.chat.completions.create(params, {
|
||||||
idempotencyKey: task.idempotencyKey,
|
idempotencyKey: task.idempotencyKey,
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
task.outputProperties = createTaskUsageProperties(response.usage);
|
task.outputProperties = createTaskUsageProperties(response.usage);
|
||||||
return response;
|
return response;
|
||||||
@@ -35,49 +46,33 @@ export class Chat {
|
|||||||
|
|
||||||
backgroundCreate: (
|
backgroundCreate: (
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: Prettify<OpenAI.Chat.CompletionCreateParamsNonStreaming>
|
params: Prettify<OpenAI.Chat.ChatCompletionCreateParamsNonStreaming>,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.Chat.ChatCompletion> => {
|
): Promise<OpenAI.Chat.ChatCompletion> => {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task, io) => {
|
async (client, task, io) => {
|
||||||
let baseURL = client.baseURL ?? "https://api.openai.com/v1";
|
const url = createBackgroundFetchUrl(
|
||||||
if (baseURL.endsWith("/")) {
|
client,
|
||||||
baseURL = baseURL.slice(0, -1);
|
"/chat/completions",
|
||||||
}
|
this.options.defaultQuery,
|
||||||
|
options
|
||||||
const chatCompletionsURL = `${baseURL}/chat/completions`;
|
);
|
||||||
|
|
||||||
const response = await io.backgroundFetch<OpenAI.Chat.ChatCompletion>(
|
const response = await io.backgroundFetch<OpenAI.Chat.ChatCompletion>(
|
||||||
"background",
|
"background",
|
||||||
chatCompletionsURL,
|
url,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: options.method ?? "POST",
|
||||||
headers: {
|
headers: createBackgroundFetchHeaders(
|
||||||
"Content-Type": "application/json",
|
client,
|
||||||
Authorization: redactString`Bearer ${client.apiKey}`,
|
task.idempotencyKey,
|
||||||
...(client.organization ? { "OpenAI-Organization": client.organization } : {}),
|
this.options.defaultHeaders,
|
||||||
"Idempotency-Key": task.idempotencyKey,
|
options
|
||||||
},
|
),
|
||||||
body: JSON.stringify(params),
|
body: JSON.stringify(params),
|
||||||
},
|
},
|
||||||
{
|
backgroundTaskRetries
|
||||||
"500-599": {
|
|
||||||
strategy: "backoff",
|
|
||||||
limit: 5,
|
|
||||||
minTimeoutInMs: 1000,
|
|
||||||
maxTimeoutInMs: 30000,
|
|
||||||
factor: 1.8,
|
|
||||||
randomize: true,
|
|
||||||
},
|
|
||||||
"429": {
|
|
||||||
strategy: "backoff",
|
|
||||||
limit: 10,
|
|
||||||
minTimeoutInMs: 1000,
|
|
||||||
maxTimeoutInMs: 60000,
|
|
||||||
factor: 2,
|
|
||||||
randomize: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
task.outputProperties = createTaskUsageProperties(response.usage);
|
task.outputProperties = createTaskUsageProperties(response.usage);
|
||||||
|
|||||||
@@ -1,24 +1,31 @@
|
|||||||
import { IntegrationTaskKey, Prettify, redactString } from "@trigger.dev/sdk";
|
import { IntegrationTaskKey, Prettify, redactString } from "@trigger.dev/sdk";
|
||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
import { OpenAIRunTask } from "./index";
|
import { OpenAIRunTask } from "./index";
|
||||||
import { createTaskUsageProperties } from "./taskUtils";
|
import {
|
||||||
|
backgroundTaskRetries,
|
||||||
|
createBackgroundFetchHeaders,
|
||||||
|
createBackgroundFetchUrl,
|
||||||
|
createTaskUsageProperties,
|
||||||
|
} from "./taskUtils";
|
||||||
|
import { OpenAIIntegrationOptions, OpenAIRequestOptions } from "./types";
|
||||||
|
|
||||||
export class Completions {
|
export class Completions {
|
||||||
runTask: OpenAIRunTask;
|
constructor(
|
||||||
|
private runTask: OpenAIRunTask,
|
||||||
constructor(runTask: OpenAIRunTask) {
|
private options: OpenAIIntegrationOptions
|
||||||
this.runTask = runTask;
|
) {}
|
||||||
}
|
|
||||||
|
|
||||||
create(
|
create(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: Prettify<OpenAI.CompletionCreateParamsNonStreaming>
|
params: Prettify<OpenAI.CompletionCreateParamsNonStreaming>,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.Completion> {
|
): Promise<OpenAI.Completion> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
const response = await client.completions.create(params, {
|
const response = await client.completions.create(params, {
|
||||||
idempotencyKey: task.idempotencyKey,
|
idempotencyKey: task.idempotencyKey,
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
task.outputProperties = createTaskUsageProperties(response.usage);
|
task.outputProperties = createTaskUsageProperties(response.usage);
|
||||||
return response;
|
return response;
|
||||||
@@ -38,49 +45,33 @@ export class Completions {
|
|||||||
|
|
||||||
backgroundCreate(
|
backgroundCreate(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: Prettify<OpenAI.CompletionCreateParamsNonStreaming>
|
params: Prettify<OpenAI.CompletionCreateParamsNonStreaming>,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.Completion> {
|
): Promise<OpenAI.Completion> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task, io) => {
|
async (client, task, io) => {
|
||||||
let baseURL = client.baseURL ?? "https://api.openai.com/v1";
|
const url = createBackgroundFetchUrl(
|
||||||
if (baseURL.endsWith("/")) {
|
client,
|
||||||
baseURL = baseURL.slice(0, -1);
|
"/completions",
|
||||||
}
|
this.options.defaultQuery,
|
||||||
|
options
|
||||||
const chatCompletionsURL = `${baseURL}/chat/completions`;
|
);
|
||||||
|
|
||||||
const response = await io.backgroundFetch<OpenAI.Completion>(
|
const response = await io.backgroundFetch<OpenAI.Completion>(
|
||||||
"background",
|
"background",
|
||||||
chatCompletionsURL,
|
url,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: createBackgroundFetchHeaders(
|
||||||
"Content-Type": "application/json",
|
client,
|
||||||
Authorization: redactString`Bearer ${client.apiKey}`,
|
task.idempotencyKey,
|
||||||
...(client.organization ? { "OpenAI-Organization": client.organization } : {}),
|
this.options.defaultHeaders,
|
||||||
"Idempotency-Key": task.idempotencyKey,
|
options
|
||||||
},
|
),
|
||||||
body: JSON.stringify(params),
|
body: JSON.stringify(params),
|
||||||
},
|
},
|
||||||
{
|
backgroundTaskRetries
|
||||||
"500-599": {
|
|
||||||
strategy: "backoff",
|
|
||||||
limit: 5,
|
|
||||||
minTimeoutInMs: 1000,
|
|
||||||
maxTimeoutInMs: 30000,
|
|
||||||
factor: 1.8,
|
|
||||||
randomize: true,
|
|
||||||
},
|
|
||||||
"429": {
|
|
||||||
strategy: "backoff",
|
|
||||||
limit: 10,
|
|
||||||
minTimeoutInMs: 1000,
|
|
||||||
maxTimeoutInMs: 60000,
|
|
||||||
factor: 2,
|
|
||||||
randomize: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
task.outputProperties = createTaskUsageProperties(response.usage);
|
task.outputProperties = createTaskUsageProperties(response.usage);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { IntegrationTaskKey, Prettify } from "@trigger.dev/sdk";
|
|||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
import { OpenAIRunTask } from "./index";
|
import { OpenAIRunTask } from "./index";
|
||||||
import { createTaskUsageProperties } from "./taskUtils";
|
import { createTaskUsageProperties } from "./taskUtils";
|
||||||
|
import { OpenAIRequestOptions } from "./types";
|
||||||
|
|
||||||
export class Edits {
|
export class Edits {
|
||||||
runTask: OpenAIRunTask;
|
runTask: OpenAIRunTask;
|
||||||
@@ -14,7 +15,11 @@ export class Edits {
|
|||||||
/**
|
/**
|
||||||
* @deprecated The Edits API is deprecated; please use Chat Completions instead.
|
* @deprecated The Edits API is deprecated; please use Chat Completions instead.
|
||||||
*/
|
*/
|
||||||
create(key: IntegrationTaskKey, params: Prettify<OpenAI.EditCreateParams>): Promise<OpenAI.Edit> {
|
create(
|
||||||
|
key: IntegrationTaskKey,
|
||||||
|
params: Prettify<OpenAI.EditCreateParams>,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
|
): Promise<OpenAI.Edit> {
|
||||||
let properties = [
|
let properties = [
|
||||||
{
|
{
|
||||||
label: "Model",
|
label: "Model",
|
||||||
@@ -37,7 +42,10 @@ export class Edits {
|
|||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
const response = await client.edits.create(params, { idempotencyKey: task.idempotencyKey });
|
const response = await client.edits.create(params, {
|
||||||
|
idempotencyKey: task.idempotencyKey,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
task.outputProperties = createTaskUsageProperties(response.usage);
|
task.outputProperties = createTaskUsageProperties(response.usage);
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { IntegrationTaskKey } from "@trigger.dev/sdk";
|
|||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
import { OpenAIRunTask } from "./index";
|
import { OpenAIRunTask } from "./index";
|
||||||
import { createTaskUsageProperties } from "./taskUtils";
|
import { createTaskUsageProperties } from "./taskUtils";
|
||||||
|
import { OpenAIRequestOptions } from "./types";
|
||||||
|
|
||||||
export class Embeddings {
|
export class Embeddings {
|
||||||
runTask: OpenAIRunTask;
|
runTask: OpenAIRunTask;
|
||||||
@@ -12,13 +13,15 @@ export class Embeddings {
|
|||||||
|
|
||||||
create(
|
create(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: OpenAI.EmbeddingCreateParams
|
params: OpenAI.EmbeddingCreateParams,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.Embeddings.CreateEmbeddingResponse> {
|
): Promise<OpenAI.Embeddings.CreateEmbeddingResponse> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
const response = await client.embeddings.create(params, {
|
const response = await client.embeddings.create(params, {
|
||||||
idempotencyKey: task.idempotencyKey,
|
idempotencyKey: task.idempotencyKey,
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
task.outputProperties = createTaskUsageProperties(response.usage);
|
task.outputProperties = createTaskUsageProperties(response.usage);
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { fileFromString } from "@trigger.dev/integration-kit";
|
|||||||
import { IntegrationTaskKey } from "@trigger.dev/sdk";
|
import { IntegrationTaskKey } from "@trigger.dev/sdk";
|
||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
import { OpenAIRunTask } from "./index";
|
import { OpenAIRunTask } from "./index";
|
||||||
|
import { OpenAIRequestOptions } from "./types";
|
||||||
|
|
||||||
type CreateFileRequest = {
|
type CreateFileRequest = {
|
||||||
file: string | File;
|
file: string | File;
|
||||||
@@ -24,7 +25,11 @@ export class Files {
|
|||||||
this.runTask = runTask;
|
this.runTask = runTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
create(key: IntegrationTaskKey, params: CreateFileRequest): Promise<OpenAI.Files.FileObject> {
|
create(
|
||||||
|
key: IntegrationTaskKey,
|
||||||
|
params: CreateFileRequest,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
|
): Promise<OpenAI.Files.FileObject> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
@@ -38,7 +43,7 @@ export class Files {
|
|||||||
|
|
||||||
return client.files.create(
|
return client.files.create(
|
||||||
{ file, purpose: params.purpose },
|
{ file, purpose: params.purpose },
|
||||||
{ idempotencyKey: task.idempotencyKey }
|
{ idempotencyKey: task.idempotencyKey, ...options }
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -58,11 +63,14 @@ export class Files {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
list(key: IntegrationTaskKey): Promise<OpenAI.Files.FileObject[]> {
|
list(
|
||||||
|
key: IntegrationTaskKey,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
|
): Promise<OpenAI.Files.FileObject[]> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
const response = await client.files.list();
|
const response = await client.files.list(options);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -74,7 +82,8 @@ export class Files {
|
|||||||
|
|
||||||
createFineTune(
|
createFineTune(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: CreateFineTuneFileRequest
|
params: CreateFineTuneFileRequest,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.Files.FileObject> {
|
): Promise<OpenAI.Files.FileObject> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
@@ -86,7 +95,7 @@ export class Files {
|
|||||||
|
|
||||||
return client.files.create(
|
return client.files.create(
|
||||||
{ file, purpose: "fine-tune" },
|
{ file, purpose: "fine-tune" },
|
||||||
{ idempotencyKey: task.idempotencyKey }
|
{ idempotencyKey: task.idempotencyKey, ...options }
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { IntegrationTaskKey } from "@trigger.dev/sdk";
|
import { IntegrationTaskKey } from "@trigger.dev/sdk";
|
||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
import { OpenAIRunTask } from "./index";
|
import { OpenAIRunTask } from "./index";
|
||||||
|
import { OpenAIRequestOptions } from "./types";
|
||||||
|
|
||||||
type SpecificFineTuneRequest = {
|
type SpecificFineTuneRequest = {
|
||||||
fineTuneId: string;
|
fineTuneId: string;
|
||||||
@@ -15,7 +16,8 @@ export class FineTunes {
|
|||||||
|
|
||||||
create(
|
create(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: OpenAI.FineTuneCreateParams
|
params: OpenAI.FineTuneCreateParams,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.FineTunes.FineTune> {
|
): Promise<OpenAI.FineTunes.FineTune> {
|
||||||
let properties = [
|
let properties = [
|
||||||
{
|
{
|
||||||
@@ -41,7 +43,7 @@ export class FineTunes {
|
|||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
return client.fineTunes.create(params, { idempotencyKey: task.idempotencyKey });
|
return client.fineTunes.create(params, { idempotencyKey: task.idempotencyKey, ...options });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Create fine tune",
|
name: "Create fine tune",
|
||||||
@@ -51,11 +53,14 @@ export class FineTunes {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
list(key: IntegrationTaskKey): Promise<OpenAI.FineTunes.FineTune[]> {
|
list(
|
||||||
|
key: IntegrationTaskKey,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
|
): Promise<OpenAI.FineTunes.FineTune[]> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
const response = await client.fineTunes.list();
|
const response = await client.fineTunes.list(options);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -67,12 +72,13 @@ export class FineTunes {
|
|||||||
|
|
||||||
retrieve(
|
retrieve(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: SpecificFineTuneRequest
|
params: SpecificFineTuneRequest,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.FineTunes.FineTune> {
|
): Promise<OpenAI.FineTunes.FineTune> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
return client.fineTunes.retrieve(params.fineTuneId);
|
return client.fineTunes.retrieve(params.fineTuneId, options);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Retrieve fine tune",
|
name: "Retrieve fine tune",
|
||||||
@@ -89,12 +95,16 @@ export class FineTunes {
|
|||||||
|
|
||||||
cancel(
|
cancel(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: SpecificFineTuneRequest
|
params: SpecificFineTuneRequest,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.FineTunes.FineTune> {
|
): Promise<OpenAI.FineTunes.FineTune> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
return client.fineTunes.cancel(params.fineTuneId, { idempotencyKey: task.idempotencyKey });
|
return client.fineTunes.cancel(params.fineTuneId, {
|
||||||
|
idempotencyKey: task.idempotencyKey,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Cancel fine tune",
|
name: "Cancel fine tune",
|
||||||
@@ -111,12 +121,13 @@ export class FineTunes {
|
|||||||
|
|
||||||
listEvents(
|
listEvents(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: SpecificFineTuneRequest
|
params: SpecificFineTuneRequest,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.FineTuneEventsListResponse> {
|
): Promise<OpenAI.FineTuneEventsListResponse> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
return client.fineTunes.listEvents(params.fineTuneId, { stream: false });
|
return client.fineTunes.listEvents(params.fineTuneId, { stream: false, ...options });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "List fine tune events",
|
name: "List fine tune events",
|
||||||
@@ -142,7 +153,8 @@ export class FineTunes {
|
|||||||
*/
|
*/
|
||||||
create: (
|
create: (
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: OpenAI.FineTuning.JobCreateParams
|
params: OpenAI.FineTuning.JobCreateParams,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.FineTuning.FineTuningJob> => {
|
): Promise<OpenAI.FineTuning.FineTuningJob> => {
|
||||||
let properties = [
|
let properties = [
|
||||||
{
|
{
|
||||||
@@ -168,7 +180,10 @@ export class FineTunes {
|
|||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
return client.fineTuning.jobs.create(params, { idempotencyKey: task.idempotencyKey });
|
return client.fineTuning.jobs.create(params, {
|
||||||
|
idempotencyKey: task.idempotencyKey,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Create Fine Tuning Job",
|
name: "Create Fine Tuning Job",
|
||||||
@@ -180,12 +195,13 @@ export class FineTunes {
|
|||||||
|
|
||||||
retrieve: (
|
retrieve: (
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: { id: string }
|
params: { id: string },
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.FineTuning.FineTuningJob> => {
|
): Promise<OpenAI.FineTuning.FineTuningJob> => {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
return client.fineTuning.jobs.retrieve(params.id);
|
return client.fineTuning.jobs.retrieve(params.id, options);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Retrieve Fine Tuning Job",
|
name: "Retrieve Fine Tuning Job",
|
||||||
@@ -202,12 +218,16 @@ export class FineTunes {
|
|||||||
|
|
||||||
cancel: (
|
cancel: (
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: { id: string }
|
params: { id: string },
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.FineTuning.FineTuningJob> => {
|
): Promise<OpenAI.FineTuning.FineTuningJob> => {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
return client.fineTuning.jobs.cancel(params.id, { idempotencyKey: task.idempotencyKey });
|
return client.fineTuning.jobs.cancel(params.id, {
|
||||||
|
idempotencyKey: task.idempotencyKey,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Cancel Fine Tuning Job",
|
name: "Cancel Fine Tuning Job",
|
||||||
@@ -224,12 +244,13 @@ export class FineTunes {
|
|||||||
|
|
||||||
listEvents: (
|
listEvents: (
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: { id: string }
|
params: { id: string },
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.FineTuning.FineTuningJobEvent[]> => {
|
): Promise<OpenAI.FineTuning.FineTuningJobEvent[]> => {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
const response = await client.fineTuning.jobs.listEvents(params.id);
|
const response = await client.fineTuning.jobs.listEvents(params.id, options);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -247,12 +268,13 @@ export class FineTunes {
|
|||||||
|
|
||||||
list: (
|
list: (
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: OpenAI.FineTuning.JobListParams
|
params: OpenAI.FineTuning.JobListParams,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.FineTuning.FineTuningJob[]> => {
|
): Promise<OpenAI.FineTuning.FineTuningJob[]> => {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
const response = await client.fineTuning.jobs.list(params);
|
const response = await client.fineTuning.jobs.list(params, options);
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { fileFromUrl, truncate } from "@trigger.dev/integration-kit";
|
import { fileFromUrl } from "@trigger.dev/integration-kit";
|
||||||
import { IntegrationTaskKey, Prettify } from "@trigger.dev/sdk";
|
import { IntegrationTaskKey, Prettify } from "@trigger.dev/sdk";
|
||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
import { OpenAIRunTask } from "./index";
|
import { OpenAIRunTask } from "./index";
|
||||||
import { createTaskUsageProperties } from "./taskUtils";
|
import { OpenAIRequestOptions } from "./types";
|
||||||
|
|
||||||
export type CreateImageEditRequest = {
|
export type CreateImageEditRequest = {
|
||||||
image: string | File;
|
image: string | File;
|
||||||
@@ -31,7 +31,8 @@ export class Images {
|
|||||||
|
|
||||||
generate(
|
generate(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: Prettify<OpenAI.Images.ImageGenerateParams>
|
params: Prettify<OpenAI.Images.ImageGenerateParams>,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.Images.ImagesResponse> {
|
): Promise<OpenAI.Images.ImagesResponse> {
|
||||||
let properties = [
|
let properties = [
|
||||||
{
|
{
|
||||||
@@ -64,7 +65,7 @@ export class Images {
|
|||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client, task) => {
|
async (client, task) => {
|
||||||
return client.images.generate(params, { idempotencyKey: task.idempotencyKey });
|
return client.images.generate(params, { idempotencyKey: task.idempotencyKey, ...options });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Create image",
|
name: "Create image",
|
||||||
@@ -76,7 +77,8 @@ export class Images {
|
|||||||
|
|
||||||
edit(
|
edit(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: CreateImageEditRequest
|
params: CreateImageEditRequest,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.Images.ImagesResponse> {
|
): Promise<OpenAI.Images.ImagesResponse> {
|
||||||
let properties = [];
|
let properties = [];
|
||||||
|
|
||||||
@@ -131,7 +133,7 @@ export class Images {
|
|||||||
response_format: params.response_format,
|
response_format: params.response_format,
|
||||||
user: params.user,
|
user: params.user,
|
||||||
},
|
},
|
||||||
{ idempotencyKey: task.idempotencyKey }
|
{ idempotencyKey: task.idempotencyKey, ...options }
|
||||||
);
|
);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
@@ -146,7 +148,8 @@ export class Images {
|
|||||||
|
|
||||||
createVariation(
|
createVariation(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: CreateImageVariationRequest
|
params: CreateImageVariationRequest,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.Images.ImagesResponse> {
|
): Promise<OpenAI.Images.ImagesResponse> {
|
||||||
let properties = [];
|
let properties = [];
|
||||||
|
|
||||||
@@ -193,7 +196,7 @@ export class Images {
|
|||||||
response_format: params.response_format,
|
response_format: params.response_format,
|
||||||
user: params.user,
|
user: params.user,
|
||||||
},
|
},
|
||||||
{ idempotencyKey: task.idempotencyKey }
|
{ idempotencyKey: task.idempotencyKey, ...options }
|
||||||
);
|
);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ export class OpenAI implements TriggerIntegration {
|
|||||||
apiKey: options.apiKey,
|
apiKey: options.apiKey,
|
||||||
organization: options.organization,
|
organization: options.organization,
|
||||||
baseURL: options.baseURL,
|
baseURL: options.baseURL,
|
||||||
|
defaultHeaders: options.defaultHeaders,
|
||||||
|
defaultQuery: options.defaultQuery,
|
||||||
|
maxRetries: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +82,9 @@ export class OpenAI implements TriggerIntegration {
|
|||||||
apiKey,
|
apiKey,
|
||||||
organization: this._options.organization,
|
organization: this._options.organization,
|
||||||
baseURL: this._options.baseURL ?? "https://api.openai.com/v1",
|
baseURL: this._options.baseURL ?? "https://api.openai.com/v1",
|
||||||
|
defaultHeaders: this._options.defaultHeaders,
|
||||||
|
defaultQuery: this._options.defaultQuery,
|
||||||
|
maxRetries: 0,
|
||||||
});
|
});
|
||||||
return openai;
|
return openai;
|
||||||
}
|
}
|
||||||
@@ -120,11 +126,11 @@ export class OpenAI implements TriggerIntegration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get completions() {
|
get completions() {
|
||||||
return new Completions(this.runTask.bind(this));
|
return new Completions(this.runTask.bind(this), this._options);
|
||||||
}
|
}
|
||||||
|
|
||||||
get chat() {
|
get chat() {
|
||||||
return new Chat(this.runTask.bind(this));
|
return new Chat(this.runTask.bind(this), this._options);
|
||||||
}
|
}
|
||||||
|
|
||||||
get edits() {
|
get edits() {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { IntegrationTaskKey } from "@trigger.dev/sdk";
|
|||||||
import { Model } from "openai/resources";
|
import { Model } from "openai/resources";
|
||||||
import { OpenAIRunTask } from "./index";
|
import { OpenAIRunTask } from "./index";
|
||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
|
import { OpenAIRequestOptions } from "./types";
|
||||||
|
|
||||||
type DeleteFineTunedModelRequest = {
|
type DeleteFineTunedModelRequest = {
|
||||||
fineTunedModelId: string;
|
fineTunedModelId: string;
|
||||||
@@ -13,11 +14,15 @@ export class Models {
|
|||||||
this.runTask = runTask;
|
this.runTask = runTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
retrieve(key: IntegrationTaskKey, params: { model: string }): Promise<Model> {
|
retrieve(
|
||||||
|
key: IntegrationTaskKey,
|
||||||
|
params: { model: string },
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
|
): Promise<Model> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client) => {
|
async (client) => {
|
||||||
return client.models.retrieve(params.model);
|
return client.models.retrieve(params.model, options);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Retrieve model",
|
name: "Retrieve model",
|
||||||
@@ -32,11 +37,11 @@ export class Models {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
list(key: IntegrationTaskKey): Promise<Model[]> {
|
list(key: IntegrationTaskKey, options: OpenAIRequestOptions = {}): Promise<Model[]> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client) => {
|
async (client) => {
|
||||||
const result = await client.models.list();
|
const result = await client.models.list(options);
|
||||||
return result.data;
|
return result.data;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -48,12 +53,13 @@ export class Models {
|
|||||||
|
|
||||||
delete(
|
delete(
|
||||||
key: IntegrationTaskKey,
|
key: IntegrationTaskKey,
|
||||||
params: DeleteFineTunedModelRequest
|
params: DeleteFineTunedModelRequest,
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
): Promise<OpenAI.Models.ModelDeleted> {
|
): Promise<OpenAI.Models.ModelDeleted> {
|
||||||
return this.runTask(
|
return this.runTask(
|
||||||
key,
|
key,
|
||||||
async (client) => {
|
async (client) => {
|
||||||
return client.models.del(params.fineTunedModelId);
|
return client.models.del(params.fineTunedModelId, options);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Delete fine tune model",
|
name: "Delete fine tune model",
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
|
import { OpenAIRequestOptions } from "./types";
|
||||||
|
import { redactString } from "@trigger.dev/sdk";
|
||||||
|
|
||||||
export function createTaskUsageProperties(
|
export function createTaskUsageProperties(
|
||||||
usage: OpenAI.Completions.CompletionUsage | OpenAI.CreateEmbeddingResponse.Usage | undefined
|
usage: OpenAI.Completions.CompletionUsage | OpenAI.CreateEmbeddingResponse.Usage | undefined
|
||||||
@@ -30,3 +32,80 @@ export function createTaskUsageProperties(
|
|||||||
export function onTaskError(error: unknown) {
|
export function onTaskError(error: unknown) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createBackgroundFetchUrl(
|
||||||
|
client: OpenAI,
|
||||||
|
endpoint: string,
|
||||||
|
defaultQuery: OpenAIRequestOptions["query"] = {},
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
|
) {
|
||||||
|
let baseURL = client.baseURL ?? "https://api.openai.com/v1";
|
||||||
|
if (baseURL.endsWith("/")) {
|
||||||
|
baseURL = baseURL.slice(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = options.path ?? endpoint;
|
||||||
|
|
||||||
|
const url = new URL(`${baseURL}${path}`);
|
||||||
|
|
||||||
|
if (options.query) {
|
||||||
|
for (const [key, value] of Object.entries(options.query)) {
|
||||||
|
if (value !== undefined) {
|
||||||
|
url.searchParams.append(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(defaultQuery)) {
|
||||||
|
if (value !== undefined) {
|
||||||
|
url.searchParams.append(key, value);
|
||||||
|
} else {
|
||||||
|
url.searchParams.delete(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return url.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createBackgroundFetchHeaders(
|
||||||
|
client: OpenAI,
|
||||||
|
idempotencyKey: string,
|
||||||
|
defaultHeaders: OpenAIRequestOptions["headers"] = {},
|
||||||
|
options: OpenAIRequestOptions = {}
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: redactString`Bearer ${client.apiKey}`,
|
||||||
|
...(client.organization ? { "OpenAI-Organization": client.organization } : {}),
|
||||||
|
"Idempotency-Key": options.idempotencyKey ?? idempotencyKey,
|
||||||
|
...(options.headers ?? {}),
|
||||||
|
...defaultHeaders,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const backgroundTaskRetries = {
|
||||||
|
"500-599": {
|
||||||
|
strategy: "backoff",
|
||||||
|
limit: 5,
|
||||||
|
minTimeoutInMs: 1000,
|
||||||
|
maxTimeoutInMs: 30000,
|
||||||
|
factor: 1.8,
|
||||||
|
randomize: true,
|
||||||
|
},
|
||||||
|
"429": {
|
||||||
|
strategy: "backoff",
|
||||||
|
limit: 10,
|
||||||
|
minTimeoutInMs: 1000,
|
||||||
|
maxTimeoutInMs: 60000,
|
||||||
|
factor: 2,
|
||||||
|
randomize: true,
|
||||||
|
},
|
||||||
|
"408-409": {
|
||||||
|
strategy: "backoff",
|
||||||
|
limit: 3,
|
||||||
|
minTimeoutInMs: 1000,
|
||||||
|
maxTimeoutInMs: 60000,
|
||||||
|
factor: 2,
|
||||||
|
randomize: true,
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|||||||
@@ -1,9 +1,37 @@
|
|||||||
|
type OpenAIHTTPMethod = "get" | "post" | "put" | "patch" | "delete";
|
||||||
|
type OpenAIHeaders = Record<string, string | null | undefined>;
|
||||||
|
type OpenAIQuery = Record<string, string | undefined>;
|
||||||
|
|
||||||
export type OpenAIIntegrationOptions = {
|
export type OpenAIIntegrationOptions = {
|
||||||
id: string;
|
id: string;
|
||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
organization?: string;
|
organization?: string;
|
||||||
baseURL?: string;
|
baseURL?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default headers to include with every request to the API.
|
||||||
|
*
|
||||||
|
* These can be removed in individual requests by explicitly setting the
|
||||||
|
* header to `undefined` or `null` in request options.
|
||||||
|
*/
|
||||||
|
defaultHeaders?: OpenAIHeaders;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default query parameters to include with every request to the API.
|
||||||
|
*
|
||||||
|
* These can be removed in individual requests by explicitly setting the
|
||||||
|
* param to `undefined` in request options.
|
||||||
|
*/
|
||||||
|
defaultQuery?: OpenAIQuery;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OpenAIIntegrationAuth = Omit<OpenAIIntegrationOptions, "id">;
|
export type OpenAIIntegrationAuth = Omit<OpenAIIntegrationOptions, "id">;
|
||||||
|
|
||||||
|
export type OpenAIRequestOptions = {
|
||||||
|
method?: OpenAIHTTPMethod;
|
||||||
|
query?: OpenAIQuery;
|
||||||
|
path?: string;
|
||||||
|
headers?: OpenAIHeaders;
|
||||||
|
idempotencyKey?: string;
|
||||||
|
};
|
||||||
|
|||||||
Generated
+8
-5
@@ -457,18 +457,20 @@ importers:
|
|||||||
'@trigger.dev/sdk': workspace:^2.2.1
|
'@trigger.dev/sdk': workspace:^2.2.1
|
||||||
'@trigger.dev/tsconfig': workspace:*
|
'@trigger.dev/tsconfig': workspace:*
|
||||||
'@types/node': '18'
|
'@types/node': '18'
|
||||||
openai: ^4.2.0
|
openai: ^4.13.0
|
||||||
rimraf: ^3.0.2
|
rimraf: ^3.0.2
|
||||||
tsup: ^6.5.0
|
tsup: ^6.5.0
|
||||||
|
typescript: ^4.9.4
|
||||||
dependencies:
|
dependencies:
|
||||||
'@trigger.dev/integration-kit': link:../../packages/integration-kit
|
'@trigger.dev/integration-kit': link:../../packages/integration-kit
|
||||||
'@trigger.dev/sdk': link:../../packages/trigger-sdk
|
'@trigger.dev/sdk': link:../../packages/trigger-sdk
|
||||||
openai: 4.2.0
|
openai: 4.13.0
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@trigger.dev/tsconfig': link:../../config-packages/tsconfig
|
'@trigger.dev/tsconfig': link:../../config-packages/tsconfig
|
||||||
'@types/node': 18.15.13
|
'@types/node': 18.15.13
|
||||||
rimraf: 3.0.2
|
rimraf: 3.0.2
|
||||||
tsup: 6.6.3
|
tsup: 6.6.3_typescript@4.9.5
|
||||||
|
typescript: 4.9.5
|
||||||
|
|
||||||
integrations/plain:
|
integrations/plain:
|
||||||
specifiers:
|
specifiers:
|
||||||
@@ -25374,8 +25376,8 @@ packages:
|
|||||||
is-docker: 2.2.1
|
is-docker: 2.2.1
|
||||||
is-wsl: 2.2.0
|
is-wsl: 2.2.0
|
||||||
|
|
||||||
/openai/4.2.0:
|
/openai/4.13.0:
|
||||||
resolution: {integrity: sha512-zfvpO2eITIxIjTG8T6Cek7NB2dMvP/LW0TRUJ4P9E8+qbBNKw00DrtfF64b+fAV2+wUYCVyynT6iSycJ//TtbA==}
|
resolution: {integrity: sha512-EPqHcB0got9cXDZmQae1KytgA4YWtTnUc7tV8hlahZtcO70DMa4kiaXoxnutj9lwmeKQO7ntG+6pmXtrCMejuQ==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 18.17.1
|
'@types/node': 18.17.1
|
||||||
@@ -25386,6 +25388,7 @@ packages:
|
|||||||
form-data-encoder: 1.7.2
|
form-data-encoder: 1.7.2
|
||||||
formdata-node: 4.4.1
|
formdata-node: 4.4.1
|
||||||
node-fetch: 2.6.12
|
node-fetch: 2.6.12
|
||||||
|
web-streams-polyfill: 3.2.1
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- encoding
|
- encoding
|
||||||
dev: false
|
dev: false
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export const client = new TriggerClient({
|
|||||||
const openai = new OpenAI({
|
const openai = new OpenAI({
|
||||||
id: "openai",
|
id: "openai",
|
||||||
apiKey: process.env["OPENAI_API_KEY"]!,
|
apiKey: process.env["OPENAI_API_KEY"]!,
|
||||||
|
defaultHeaders: { "user-agent": "trigger.dev job-catalog reference 1.0" },
|
||||||
});
|
});
|
||||||
|
|
||||||
client.defineJob({
|
client.defineJob({
|
||||||
@@ -34,7 +35,7 @@ client.defineJob({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await io.openai.backgroundCreateChatCompletion("background-chat-completion", {
|
await io.openai.chat.completions.backgroundCreate("background-chat-completion", {
|
||||||
model: "gpt-3.5-turbo",
|
model: "gpt-3.5-turbo",
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -44,7 +45,7 @@ client.defineJob({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
await io.openai.createChatCompletion("chat-completion", {
|
await io.openai.chat.completions.create("chat-completion", {
|
||||||
model: "gpt-3.5-turbo",
|
model: "gpt-3.5-turbo",
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -54,7 +55,12 @@ client.defineJob({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
await io.openai.createCompletion("completion", {
|
await io.openai.completions.backgroundCreate("background-completion", {
|
||||||
|
model: "text-davinci-003",
|
||||||
|
prompt: "Create a good programming joke about Tasks",
|
||||||
|
});
|
||||||
|
|
||||||
|
await io.openai.completions.create("completion", {
|
||||||
model: "text-davinci-003",
|
model: "text-davinci-003",
|
||||||
prompt: "Create a good programming joke about Tasks",
|
prompt: "Create a good programming joke about Tasks",
|
||||||
});
|
});
|
||||||
@@ -112,4 +118,54 @@ client.defineJob({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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"] },
|
||||||
|
});
|
||||||
|
|
||||||
|
client.defineJob({
|
||||||
|
id: "azure-tasks",
|
||||||
|
name: "azure Tasks",
|
||||||
|
version: "0.0.1",
|
||||||
|
trigger: eventTrigger({
|
||||||
|
name: "azure.tasks",
|
||||||
|
}),
|
||||||
|
integrations: {
|
||||||
|
azureOpenAI,
|
||||||
|
},
|
||||||
|
run: async (payload, io, ctx) => {
|
||||||
|
await io.azureOpenAI.chat.completions.create(
|
||||||
|
"chat-completion",
|
||||||
|
{
|
||||||
|
model: "my-gpt35-16k-deployment",
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: "Create a good programming joke about background jobs",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"User-Agent": "Trigger.dev",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await io.azureOpenAI.chat.completions.backgroundCreate("background-chat-completion", {
|
||||||
|
model: "my-gpt35-16k-deployment",
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: "If you were a programming language, what would you be and why?",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
createExpressServer(client);
|
createExpressServer(client);
|
||||||
|
|||||||
Reference in New Issue
Block a user