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

Version 2.0 #32

Merged
merged 32 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f445a81
Switch to @dexaai eslint config
rileytomasek Oct 21, 2023
f9c8082
Upgrade dev dependencies
rileytomasek Oct 21, 2023
b0ea006
Reformat files with new Prettier version
rileytomasek Oct 21, 2023
fd2d413
Require Node version 18 or higher
rileytomasek Oct 21, 2023
77012e3
Switch to ECMAScript modules + TypeScript build
rileytomasek Oct 21, 2023
8abdb12
Upgrade dependencies
rileytomasek Oct 21, 2023
dba3876
Remove barely used or unused dependencies
rileytomasek Oct 21, 2023
3ed2f47
Clean up client initialization args for Ky
rileytomasek Oct 21, 2023
795690e
Remove deprecated edit endpoint
rileytomasek Oct 21, 2023
9d61726
Remove Zod dependency & use OpenAI types
rileytomasek Oct 21, 2023
2d2f693
Move closer to raw OpenAI API endpoints/shapes
rileytomasek Oct 22, 2023
7251318
Use Error class from OpenAI Node package
rileytomasek Oct 22, 2023
caa4a24
Add jitter to failed request retries
rileytomasek Oct 22, 2023
b9e2abe
Bump version to 2.0.0-beta.1
rileytomasek Oct 22, 2023
de6c343
Standardize param/response types and export
rileytomasek Oct 22, 2023
0362174
Export error classes for instanceof checks
rileytomasek Oct 22, 2023
debbe5d
Bump to 2.0.0-beta.2
rileytomasek Oct 22, 2023
a3503a3
Support passing custom headers to a single request
rileytomasek Oct 22, 2023
d7c0620
Include OpenAI library types
rileytomasek Oct 23, 2023
a699bc2
Update readme
rileytomasek Oct 23, 2023
37eeec0
Update package sizes in readme
rileytomasek Oct 23, 2023
193ec64
Export type for chat stream chunk response
rileytomasek Oct 24, 2023
8bb9276
Add streaming fix from v1 branch
rileytomasek Oct 30, 2023
fc73480
Bump version to beta v5
rileytomasek Oct 30, 2023
9e93ad0
Bump to beta 6
rileytomasek Nov 1, 2023
ffa29ed
Fix absolute import in openai-types (#33)
transitive-bullshit Nov 3, 2023
861a725
Bump to beta.7
rileytomasek Nov 3, 2023
0be310c
feat: Update openai to latest after dev day 2023
transitive-bullshit Nov 7, 2023
9802b23
Clean up ky imports
transitive-bullshit Nov 7, 2023
079184a
feat: bump to beta 8
transitive-bullshit Nov 7, 2023
1adb936
Merge branch 'master' into v2
transitive-bullshit Nov 7, 2023
bae240a
v2 remove all absolute imports from openai-types and package.json scr…
transitive-bullshit Nov 7, 2023
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
8 changes: 6 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"root": true,
"extends": ["hckrs"]
"extends": ["@dexaai/eslint-config", "@dexaai/eslint-config/node"],
"ignorePatterns": ["node_modules/", "dist/", "openai-types/"],
"rules": {
"no-console": "off",
"no-process-env": "off"
}
}
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn lint
Expand All @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn typecheck
29 changes: 0 additions & 29 deletions build.js

This file was deleted.

39 changes: 39 additions & 0 deletions extract-types.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import fs from 'fs';
import path from 'path';

/**
* This is used to extract the type declarations from the openai Node.js
* package. Doing this allows it to be a devDependency instead of a dependency,
* which greatly reduces the size of the final bundle.
*/
function extractTypes(srcDir, destDir, root = false) {
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}

const entries = fs.readdirSync(srcDir, { withFileTypes: true });

for (const entry of entries) {
const srcPath = path.join(srcDir, entry.name);
const destPath = path.join(destDir, entry.name);

if (entry.isDirectory()) {
extractTypes(srcPath, destPath);
} else if (entry.isFile() && entry.name.endsWith('.d.ts')) {
console.log(destPath);

if (root && entry.name === 'index.d.ts') {
// OpenAI has one line with an absolute package import, so switch it to
// be a relative import.
const content = fs
.readFileSync(srcPath, 'utf8')
.replaceAll("'openai/resources/index'", "'./resources/index.js'");
fs.writeFileSync(destPath, content);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
}

extractTypes('node_modules/openai', 'openai-types', true);
9 changes: 9 additions & 0 deletions openai-types/_shims/MultipartBody.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
export declare class MultipartBody {
body: any;
constructor(body: any);
get [Symbol.toStringTag](): string;
}
//# sourceMappingURL=MultipartBody.d.ts.map
5 changes: 5 additions & 0 deletions openai-types/_shims/auto/runtime-bun.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
export * from "../bun-runtime.js";
//# sourceMappingURL=runtime-bun.d.ts.map
5 changes: 5 additions & 0 deletions openai-types/_shims/auto/runtime-node.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
export * from "../node-runtime.js";
//# sourceMappingURL=runtime-node.d.ts.map
5 changes: 5 additions & 0 deletions openai-types/_shims/auto/runtime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
export * from "../web-runtime.js";
//# sourceMappingURL=runtime.d.ts.map
5 changes: 5 additions & 0 deletions openai-types/_shims/auto/types-node.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
export * from "../node-types.js";
//# sourceMappingURL=types-node.d.ts.map
101 changes: 101 additions & 0 deletions openai-types/_shims/auto/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
export type Agent = any;

// @ts-ignore
declare const _fetch: unknown extends typeof fetch ? never : typeof fetch;
export { _fetch as fetch };

// @ts-ignore
type _Request = unknown extends Request ? never : Request;
export { _Request as Request };

// @ts-ignore
type _RequestInfo = unknown extends RequestInfo ? never : RequestInfo;
export { type _RequestInfo as RequestInfo };

// @ts-ignore
type _RequestInit = unknown extends RequestInit ? never : RequestInit;
export { type _RequestInit as RequestInit };

// @ts-ignore
type _Response = unknown extends Response ? never : Response;
export { _Response as Response };

// @ts-ignore
type _ResponseInit = unknown extends ResponseInit ? never : ResponseInit;
export { type _ResponseInit as ResponseInit };

// @ts-ignore
type _ResponseType = unknown extends ResponseType ? never : ResponseType;
export { type _ResponseType as ResponseType };

// @ts-ignore
type _BodyInit = unknown extends BodyInit ? never : BodyInit;
export { type _BodyInit as BodyInit };

// @ts-ignore
type _Headers = unknown extends Headers ? never : Headers;
export { _Headers as Headers };

// @ts-ignore
type _HeadersInit = unknown extends HeadersInit ? never : HeadersInit;
export { type _HeadersInit as HeadersInit };

type EndingType = 'native' | 'transparent';

export interface BlobPropertyBag {
endings?: EndingType;
type?: string;
}

export interface FilePropertyBag extends BlobPropertyBag {
lastModified?: number;
}

export type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;

// @ts-ignore
type _FormData = unknown extends FormData ? never : FormData;
// @ts-ignore
declare const _FormData: unknown extends typeof FormData ? never : typeof FormData;
export { _FormData as FormData };

// @ts-ignore
type _File = unknown extends File ? never : File;
// @ts-ignore
declare const _File: unknown extends typeof File ? never : typeof File;
export { _File as File };

// @ts-ignore
type _Blob = unknown extends Blob ? never : Blob;
// @ts-ignore
declare const _Blob: unknown extends typeof Blob ? never : typeof Blob;
export { _Blob as Blob };

export declare class Readable {
readable: boolean;
readonly readableEnded: boolean;
readonly readableFlowing: boolean | null;
readonly readableHighWaterMark: number;
readonly readableLength: number;
readonly readableObjectMode: boolean;
destroyed: boolean;
read(size?: number): any;
pause(): this;
resume(): this;
isPaused(): boolean;
destroy(error?: Error): this;
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
}

export declare class FsReadStream extends Readable {
path: {}; // node type is string | Buffer
}

// @ts-ignore
type _ReadableStream<R = any> = unknown extends ReadableStream<R> ? never : ReadableStream<R>;
// @ts-ignore
declare const _ReadableStream: unknown extends typeof ReadableStream ? never : typeof ReadableStream;
export { _ReadableStream as ReadableStream };
6 changes: 6 additions & 0 deletions openai-types/_shims/bun-runtime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
import { type Shims } from "./registry.js";
export declare function getRuntime(): Shims;
//# sourceMappingURL=bun-runtime.d.ts.map
81 changes: 81 additions & 0 deletions openai-types/_shims/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
import { manual } from "./manual-types.js";
import * as auto from 'openai/_shims/auto/types';
import { type RequestOptions } from "../core.js";

type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;

export const kind: string;

// @ts-ignore
export type Agent = SelectType<manual.Agent, auto.Agent>;

// @ts-ignore
export const fetch: SelectType<typeof manual.fetch, typeof auto.fetch>;

// @ts-ignore
export type Request = SelectType<manual.Request, auto.Request>;
// @ts-ignore
export type RequestInfo = SelectType<manual.RequestInfo, auto.RequestInfo>;
// @ts-ignore
export type RequestInit = SelectType<manual.RequestInit, auto.RequestInit>;

// @ts-ignore
export type Response = SelectType<manual.Response, auto.Response>;
// @ts-ignore
export type ResponseInit = SelectType<manual.ResponseInit, auto.ResponseInit>;
// @ts-ignore
export type ResponseType = SelectType<manual.ResponseType, auto.ResponseType>;
// @ts-ignore
export type BodyInit = SelectType<manual.BodyInit, auto.BodyInit>;
// @ts-ignore
export type Headers = SelectType<manual.Headers, auto.Headers>;
// @ts-ignore
export const Headers: SelectType<typeof manual.Headers, typeof auto.Headers>;
// @ts-ignore
export type HeadersInit = SelectType<manual.HeadersInit, auto.HeadersInit>;

// @ts-ignore
export type BlobPropertyBag = SelectType<manual.BlobPropertyBag, auto.BlobPropertyBag>;
// @ts-ignore
export type FilePropertyBag = SelectType<manual.FilePropertyBag, auto.FilePropertyBag>;
// @ts-ignore
export type FileFromPathOptions = SelectType<manual.FileFromPathOptions, auto.FileFromPathOptions>;
// @ts-ignore
export type FormData = SelectType<manual.FormData, auto.FormData>;
// @ts-ignore
export const FormData: SelectType<typeof manual.FormData, typeof auto.FormData>;
// @ts-ignore
export type File = SelectType<manual.File, auto.File>;
// @ts-ignore
export const File: SelectType<typeof manual.File, typeof auto.File>;
// @ts-ignore
export type Blob = SelectType<manual.Blob, auto.Blob>;
// @ts-ignore
export const Blob: SelectType<typeof manual.Blob, typeof auto.Blob>;

// @ts-ignore
export type Readable = SelectType<manual.Readable, auto.Readable>;
// @ts-ignore
export type FsReadStream = SelectType<manual.FsReadStream, auto.FsReadStream>;
// @ts-ignore
export type ReadableStream = SelectType<manual.ReadableStream, auto.ReadableStream>;
// @ts-ignore
export const ReadableStream: SelectType<typeof manual.ReadableStream, typeof auto.ReadableStream>;

export function getMultipartRequestOptions<T extends {} = Record<string, unknown>>(
form: FormData,
opts: RequestOptions<T>,
): Promise<RequestOptions<T>>;

export function getDefaultAgent(url: string): any;

// @ts-ignore
export type FileFromPathOptions = SelectType<manual.FileFromPathOptions, auto.FileFromPathOptions>;

export function fileFromPath(path: string, options?: FileFromPathOptions): Promise<File>;
export function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise<File>;

export function isFsReadStream(value: any): value is FsReadStream;
12 changes: 12 additions & 0 deletions openai-types/_shims/manual-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
/**
* Types will get added to this namespace when you import one of the following:
*
* import 'openai/shims/node'
* import 'openai/shims/web'
*
* Importing more than one will cause type and runtime errors.
*/
export namespace manual {}
3 changes: 3 additions & 0 deletions openai-types/_shims/node-runtime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { type Shims } from "./registry.js";
export declare function getRuntime(): Shims;
//# sourceMappingURL=node-runtime.d.ts.map
42 changes: 42 additions & 0 deletions openai-types/_shims/node-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
import * as nf from 'node-fetch';
import * as fd from 'formdata-node';

export { type Agent } from 'node:http';
export { type Readable } from 'node:stream';
export { type ReadStream as FsReadStream } from 'node:fs';
export { ReadableStream } from 'web-streams-polyfill';

export const fetch: typeof nf.default;

export type Request = nf.Request;
export type RequestInfo = nf.RequestInfo;
export type RequestInit = nf.RequestInit;

export type Response = nf.Response;
export type ResponseInit = nf.ResponseInit;
export type ResponseType = nf.ResponseType;
export type BodyInit = nf.BodyInit;
export type Headers = nf.Headers;
export type HeadersInit = nf.HeadersInit;

type EndingType = 'native' | 'transparent';
export interface BlobPropertyBag {
endings?: EndingType;
type?: string;
}

export interface FilePropertyBag extends BlobPropertyBag {
lastModified?: number;
}

export type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;

export type FormData = fd.FormData;
export const FormData: typeof fd.FormData;
export type File = fd.File;
export const File: typeof fd.File;
export type Blob = fd.Blob;
export const Blob: typeof fd.Blob;
Loading