OpenAI: retrieveModel
This commit is contained in:
@@ -20,7 +20,11 @@ new Job(client, {
|
||||
openai,
|
||||
},
|
||||
run: async (payload, io, ctx) => {
|
||||
await io.openai.listModels("list-models");
|
||||
const models = await io.openai.listModels("list-models");
|
||||
|
||||
await io.openai.retrieveModel("get-model", {
|
||||
model: models[0].id,
|
||||
});
|
||||
|
||||
await io.openai.backgroundCreateChatCompletion(
|
||||
"background-chat-completion",
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
import { OpenAIApi, Configuration } from "openai";
|
||||
import type { IntegrationClient, TriggerIntegration } from "@trigger.dev/sdk";
|
||||
import { Configuration, OpenAIApi } from "openai";
|
||||
import {
|
||||
backgroundCreateChatCompletion,
|
||||
backgroundCreateCompletion,
|
||||
cancelFineTune,
|
||||
createChatCompletion,
|
||||
createCompletion,
|
||||
backgroundCreateCompletion,
|
||||
backgroundCreateChatCompletion,
|
||||
listModels,
|
||||
createFile,
|
||||
listFiles,
|
||||
createFineTuneFile,
|
||||
createFineTune,
|
||||
listFineTunes,
|
||||
retrieveFineTune,
|
||||
cancelFineTune,
|
||||
listFineTuneEvents,
|
||||
createFineTuneFile,
|
||||
deleteFineTune,
|
||||
listFiles,
|
||||
listFineTuneEvents,
|
||||
listFineTunes,
|
||||
listModels,
|
||||
retrieveFineTune,
|
||||
retrieveModel,
|
||||
} from "./tasks";
|
||||
import { OpenAIIntegrationOptions } from "./types";
|
||||
|
||||
const tasks = {
|
||||
retrieveModel,
|
||||
listModels,
|
||||
createCompletion,
|
||||
createChatCompletion,
|
||||
backgroundCreateCompletion,
|
||||
backgroundCreateChatCompletion,
|
||||
listModels,
|
||||
createFile,
|
||||
listFiles,
|
||||
createFineTuneFile,
|
||||
|
||||
@@ -11,6 +11,59 @@ import { Prettify, fileFromString } from "@trigger.dev/integration-kit";
|
||||
|
||||
type OpenAIClientType = InstanceType<typeof OpenAIApi>;
|
||||
|
||||
type RetrieveModelRequest = {
|
||||
model: string;
|
||||
};
|
||||
|
||||
type RetrieveModelResponseData = Prettify<
|
||||
Awaited<ReturnType<OpenAIClientType["retrieveModel"]>>["data"]
|
||||
>;
|
||||
|
||||
export const retrieveModel: AuthenticatedTask<
|
||||
OpenAIClientType,
|
||||
Prettify<RetrieveModelRequest>,
|
||||
RetrieveModelResponseData
|
||||
> = {
|
||||
run: async (params, client) => {
|
||||
return client.retrieveModel(params.model).then((res) => res.data);
|
||||
},
|
||||
init: (params) => {
|
||||
return {
|
||||
name: "Retrieve model",
|
||||
params,
|
||||
icon: "openai",
|
||||
properties: [
|
||||
{
|
||||
label: "Model id",
|
||||
text: params.model,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
type ListModelsResponseData = Awaited<
|
||||
ReturnType<OpenAIClientType["listModels"]>
|
||||
>["data"]["data"];
|
||||
|
||||
export const listModels: AuthenticatedTask<
|
||||
OpenAIClientType,
|
||||
void,
|
||||
Prettify<ListModelsResponseData>
|
||||
> = {
|
||||
run: async (params, client) => {
|
||||
return client.listModels().then((res) => res.data.data);
|
||||
},
|
||||
init: (params) => {
|
||||
return {
|
||||
name: "List models",
|
||||
params,
|
||||
icon: "openai",
|
||||
properties: [],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const createCompletion: AuthenticatedTask<
|
||||
OpenAIClientType,
|
||||
Prettify<CreateCompletionRequest>,
|
||||
@@ -159,28 +212,6 @@ export const backgroundCreateChatCompletion: AuthenticatedTask<
|
||||
},
|
||||
};
|
||||
|
||||
type ListModelsResponseData = Awaited<
|
||||
ReturnType<OpenAIClientType["listModels"]>
|
||||
>["data"];
|
||||
|
||||
export const listModels: AuthenticatedTask<
|
||||
OpenAIClientType,
|
||||
void,
|
||||
Prettify<ListModelsResponseData>
|
||||
> = {
|
||||
run: async (params, client) => {
|
||||
return client.listModels().then((res) => res.data);
|
||||
},
|
||||
init: (params) => {
|
||||
return {
|
||||
name: "List models",
|
||||
params,
|
||||
icon: "openai",
|
||||
properties: [],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
type CreateFileResponseData = Awaited<
|
||||
ReturnType<OpenAIClientType["createFile"]>
|
||||
>["data"];
|
||||
|
||||
Reference in New Issue
Block a user