Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/openai4.41.0 #70

Merged
merged 8 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
"dependencies": {
"agentkeepalive": "^4.5.0",
"dotenv": "^16.3.1",
"openai": "4.36.0"
"openai": "4.41.0"
}
}
121 changes: 5 additions & 116 deletions src/apis/assistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import OpenAI from "openai";
export interface AssistantCreateParams {
model: string;
description?: string | null;
file_ids?: Array<string>;
instructions?: string | null;
metadata?: unknown | null;
name?: string | null;
tools?: Array<any>;
response_format?: any | null;
temperature?: number | null;
tool_resources?: any | null;
top_p?: number | null;

}

export interface FileCreateParams {
Expand Down Expand Up @@ -47,13 +51,6 @@ export interface AssistantUpdateParams {


export class Assistants extends ApiResource {

files: Files;

constructor(client:any) {
super(client);
this.files = new Files(client);
}

async create(
_body: AssistantCreateParams,
Expand Down Expand Up @@ -181,111 +178,3 @@ export class Assistants extends ApiResource {
}

}

export class Files extends ApiResource{

async create(
assistantId: string,
_body: FileCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body: FileCreateParams = _body;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}


const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.beta.assistants.files.create(assistantId, body, opts).withResponse();

return finalResponse(result);
}

async list(
assistantId: string,
_query?: FileListParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const query: FileListParams | undefined = _query;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const result = await OAIclient.beta.assistants.files.list(assistantId, query, opts).withResponse();

return finalResponse(result);
}

async retrieve(
assistantId: string,
fileId: string,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.beta.assistants.files.retrieve(assistantId, fileId, opts).withResponse();

return finalResponse(result);
}

async del(
assistantId: string,
fileId: string,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.beta.assistants.files.del(assistantId, fileId, opts).withResponse();

return finalResponse(result);
}

}
97 changes: 97 additions & 0 deletions src/apis/audio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { TranscriptionCreateParams } from "openai/resources/audio/transcriptions";
import { ApiClientInterface } from "../_types/generalTypes";
import { ApiResource } from "../apiResource";
import { RequestOptions } from "../baseClient";
import { OPEN_AI_API_KEY } from "../constants";
import { defaultHeadersBuilder, finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";
import { TranslationCreateParams } from "openai/resources/audio/translations";
import { SpeechCreateParams } from "openai/resources/audio/speech";

export class Audio extends ApiResource {
transcriptions: transcriptions;
translations: translations;
speech: speech;

constructor(client: any) {
super(client);
this.transcriptions = new transcriptions(client);
this.translations = new translations(client);
this.speech = new speech(client);
}
}

export class transcriptions extends ApiResource{
async create(
_body: TranscriptionCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body: TranscriptionCreateParams = _body;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});
const response = await OAIclient.audio.transcriptions.create(body, opts).withResponse();
return finalResponse(response);
}
}


export class translations extends ApiResource{
async create(
_body: TranslationCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body: TranslationCreateParams = _body;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});
const response = await OAIclient.audio.translations.create(body, opts).withResponse();
return finalResponse(response);
}
}


export class speech extends ApiResource{
async create(
_body: SpeechCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body: SpeechCreateParams = _body;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});
const response = await OAIclient.audio.speech.create(body, opts);
return response;
}
}
106 changes: 106 additions & 0 deletions src/apis/batches.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { BatchCreateParams, BatchListParams } from "openai/resources/batches";
import { ApiClientInterface } from "../_types/generalTypes";
import { ApiResource } from "../apiResource";
import { RequestOptions } from "../baseClient";
import { OPEN_AI_API_KEY } from "../constants";
import { defaultHeadersBuilder, finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";

export class Batches extends ApiResource{

async create(
_body: BatchCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body: BatchCreateParams = _body;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.batches.create(body, opts).withResponse();
return finalResponse(result);
}

async retrieve(
batchId: string,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.batches.retrieve(batchId, opts).withResponse();
return finalResponse(result);
}

async list(
_query?: BatchListParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const query: BatchListParams | undefined = _query;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.batches.list(query, opts).withResponse();
return finalResponse(result);
}

async cancel(
batchId: string,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.batches.cancel(batchId, opts).withResponse();
return finalResponse(result);
}
}

Loading
Loading