Skip to content

Commit

Permalink
Merge pull request #4 from janhq/fix/import-web
Browse files Browse the repository at this point in the history
fix: import on web
  • Loading branch information
namchuai committed Jun 27, 2024
2 parents d6a4c87 + 3b90d14 commit 8c15c44
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/_shims/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
const shims = require('./registry');
const auto = require('openai/_shims/auto/runtime');
const auto = require('../_shims/auto/runtime');
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
for (const property of Object.keys(shims)) {
Object.defineProperty(exports, property, {
Expand Down
2 changes: 1 addition & 1 deletion src/_shims/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
*/
import * as shims from './registry.mjs';
import * as auto from 'openai/_shims/auto/runtime';
import * as auto from '../_shims/auto/runtime';
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
export * from './registry.mjs';
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export namespace OpenAI {
export import Model = API.Model;
export import ModelDeleted = API.ModelDeleted;
export import ModelsPage = API.ModelsPage;
export import ThreadsPage = API.Beta.ThreadsPage;

export import FineTuning = API.FineTuning;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/AbstractAssistantStreamRunner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Core from 'openai/core';
import { APIUserAbortError, OpenAIError } from 'openai/error';
import * as Core from '../core';
import { APIUserAbortError, OpenAIError } from '../error';
import { Run, RunSubmitToolOutputsParamsBase } from 'openai/resources/beta/threads/runs/runs';
import { RunCreateParamsBase, Runs } from 'openai/resources/beta/threads/runs/runs';
import { ThreadCreateAndRunParamsBase, Threads } from 'openai/resources/beta/threads/threads';
Expand Down
4 changes: 2 additions & 2 deletions src/lib/AbstractChatCompletionRunner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Core from 'openai/core';
import * as Core from '../core';
import { type CompletionUsage } from 'openai/resources/completions';
import {
type Completions,
Expand All @@ -8,7 +8,7 @@ import {
type ChatCompletionCreateParams,
type ChatCompletionTool,
} from 'openai/resources/chat/completions';
import { APIUserAbortError, OpenAIError } from 'openai/error';
import { APIUserAbortError, OpenAIError } from '../error';
import {
type RunnableFunction,
isRunnableFunctionWithParse,
Expand Down
8 changes: 4 additions & 4 deletions src/lib/AssistantStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
Messages,
MessageContent,
} from 'openai/resources/beta/threads/messages';
import * as Core from 'openai/core';
import { RequestOptions } from 'openai/core';
import * as Core from '../core';
import { RequestOptions } from '../core';
import {
Run,
RunCreateParamsBase,
Expand All @@ -24,8 +24,8 @@ import {
AbstractAssistantStreamRunner,
} from './AbstractAssistantStreamRunner';
import { type ReadableStream } from 'openai/_shims/index';
import { Stream } from 'openai/streaming';
import { APIUserAbortError, OpenAIError } from 'openai/error';
import { Stream } from '../streaming';
import { APIUserAbortError, OpenAIError } from '../error';
import {
AssistantStreamEvent,
MessageStreamEvent,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ChatCompletionRunFunctions.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import OpenAI from 'openai';
import { OpenAIError, APIConnectionError } from 'openai/error';
import { OpenAIError, APIConnectionError } from '../error';
import { PassThrough } from 'stream';
import {
ParsingToolFunction,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/ChatCompletionStream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Core from 'openai/core';
import { OpenAIError, APIUserAbortError } from 'openai/error';
import * as Core from '../core';
import { OpenAIError, APIUserAbortError } from '../error';
import {
Completions,
type ChatCompletion,
Expand All @@ -12,7 +12,7 @@ import {
type AbstractChatCompletionRunnerEvents,
} from './AbstractChatCompletionRunner';
import { type ReadableStream } from 'openai/_shims/index';
import { Stream } from 'openai/streaming';
import { Stream } from '../streaming';

export interface ChatCompletionStreamEvents extends AbstractChatCompletionRunnerEvents {
content: (contentDelta: string, contentSnapshot: string) => void;
Expand Down
1 change: 1 addition & 0 deletions src/resources/beta/beta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export namespace Beta {
export import AssistantUpdateParams = AssistantsAPI.AssistantUpdateParams;
export import AssistantListParams = AssistantsAPI.AssistantListParams;
export import Threads = ThreadsAPI.Threads;
export import ThreadsPage = ThreadsAPI.ThreadsPage;
export import AssistantResponseFormat = ThreadsAPI.AssistantResponseFormat;
export import AssistantResponseFormatOption = ThreadsAPI.AssistantResponseFormatOption;
export import AssistantToolChoice = ThreadsAPI.AssistantToolChoice;
Expand Down
1 change: 1 addition & 0 deletions src/resources/beta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export {
ThreadCreateAndRunPollParams,
ThreadCreateAndRunStreamParams,
Threads,
ThreadsPage,
} from './threads/index';
export { Beta } from './beta';
export { Chat } from './chat/index';
Expand Down
1 change: 1 addition & 0 deletions src/resources/beta/threads/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export {
ThreadCreateAndRunPollParams,
ThreadCreateAndRunStreamParams,
Threads,
ThreadsPage,
} from './threads';
export {
RequiredActionFunctionToolCall,
Expand Down
10 changes: 9 additions & 1 deletion src/resources/beta/threads/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as AssistantsAPI from '../assistants';
import * as MessagesAPI from './messages';
import * as RunsAPI from './runs/runs';
import { Stream } from '../../../streaming';
import { Page } from 'openai/pagination';
import { Page } from '../../../pagination';

/**
* Note: no pagination actually occurs yet, this is for forwards-compatibility.
Expand Down Expand Up @@ -68,6 +68,13 @@ export class Threads extends APIResource {
});
}

/**
* Clean up a thread.
*/
clean(threadId: string, options?: Core.RequestOptions): Core.APIPromise<Thread> {
return this._client.post(`/threads/${threadId}/clean`);
}

/**
* Delete a thread.
*/
Expand Down Expand Up @@ -1489,6 +1496,7 @@ export namespace Threads {
export import AssistantToolChoiceFunction = ThreadsAPI.AssistantToolChoiceFunction;
export import AssistantToolChoiceOption = ThreadsAPI.AssistantToolChoiceOption;
export import Thread = ThreadsAPI.Thread;
export import ThreadsPage = ThreadsAPI.ThreadsPage;
export import ThreadDeleted = ThreadsAPI.ThreadDeleted;
export import ThreadCreateParams = ThreadsAPI.ThreadCreateParams;
export import ThreadUpdateParams = ThreadsAPI.ThreadUpdateParams;
Expand Down
18 changes: 18 additions & 0 deletions src/resources/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ export class Models extends APIResource {
stop(model: string, options?: Core.RequestOptions): Core.APIPromise<Model> {
return this._client.post(`/models/${model}/stop`, options);
}

/**
* Download a model.
*/
download(model: string) {
return this._client.get(`/models/download/${model}`);
}

/**
* Abort a model download.
*/
abortDownload(downloadId: string) {
return this._client.get(`/models/abort-download/${downloadId}`);
}

update(model: string, body: Record<string, unknown>, options?: Core.RequestOptions) {
return this._client.post(`/models/${model}/config`, { body, ...options });
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/streaming.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReadableStream, type Response } from './_shims/index';
import { OpenAIError } from './error';

import { APIError } from 'openai/error';
import { APIError } from './error';

type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined;

Expand Down

0 comments on commit 8c15c44

Please sign in to comment.