Skip to content

Commit 90813a8

Browse files
authored
Merge pull request #275 from Portkey-AI/feat/oai6.3.0
Vendoring OAI 6.3.0
2 parents 844c504 + be25af5 commit 90813a8

7 files changed

Lines changed: 387 additions & 7 deletions

File tree

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"dependencies": {
4646
"agentkeepalive": "^4.6.0",
4747
"dotenv": "^16.5.0",
48-
"openai": "5.20.2",
48+
"openai": "6.3.0",
4949
"ws": "^8.18.2"
5050
}
5151
}

src/apis/chatkit.ts

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import { ApiResource } from '../apiResource';
2+
import { createHeaders } from './createHeaders';
3+
import { finalResponse, initOpenAIClient, overrideConfig } from '../utils';
4+
import { ApiClientInterface } from '../_types/generalTypes';
5+
import { APIPromise, RequestOptions } from '../baseClient';
6+
import {
7+
ChatKitUploadFileParams,
8+
ChatKitUploadFileResponse,
9+
} from 'openai/resources/beta/chatkit/chatkit';
10+
import { SessionCreateParams } from 'openai/resources/beta/chatkit/sessions';
11+
import {
12+
ChatKitThread,
13+
ChatSession,
14+
ThreadDeleteResponse,
15+
ThreadListItemsParams,
16+
ThreadListParams,
17+
} from 'openai/resources/beta/chatkit/threads';
18+
19+
export class ChatKit extends ApiResource {
20+
sessions: ChatKitSessions;
21+
threads: ChatKitThreads;
22+
constructor(client: any) {
23+
super(client);
24+
this.sessions = new ChatKitSessions(client);
25+
this.threads = new ChatKitThreads(client);
26+
}
27+
28+
uploadFile(
29+
body: ChatKitUploadFileParams,
30+
params?: ApiClientInterface,
31+
opts?: RequestOptions
32+
): APIPromise<ChatKitUploadFileResponse> {
33+
if (params) {
34+
const config = overrideConfig(this.client.config, params.config);
35+
this.client.customHeaders = {
36+
...this.client.customHeaders,
37+
...createHeaders({ ...params, config }),
38+
};
39+
}
40+
const OAIclient = initOpenAIClient(this.client);
41+
const result = OAIclient.beta.chatkit.uploadFile(body, opts);
42+
return result as any;
43+
}
44+
}
45+
46+
export class ChatKitSessions extends ApiResource {
47+
create(
48+
body: SessionCreateParams,
49+
params?: ApiClientInterface,
50+
opts?: RequestOptions
51+
): APIPromise<ChatSession> {
52+
if (params) {
53+
const config = overrideConfig(this.client.config, params.config);
54+
this.client.customHeaders = {
55+
...this.client.customHeaders,
56+
...createHeaders({ ...params, config }),
57+
};
58+
}
59+
const OAIclient = initOpenAIClient(this.client);
60+
const result = OAIclient.beta.chatkit.sessions
61+
.create(body, opts)
62+
.withResponse();
63+
return finalResponse(result);
64+
}
65+
66+
cancel(
67+
sessionID: string,
68+
params?: ApiClientInterface,
69+
opts?: RequestOptions
70+
): APIPromise<void> {
71+
if (params) {
72+
const config = overrideConfig(this.client.config, params.config);
73+
this.client.customHeaders = {
74+
...this.client.customHeaders,
75+
...createHeaders({ ...params, config }),
76+
};
77+
}
78+
79+
const OAIclient = initOpenAIClient(this.client);
80+
const result = OAIclient.beta.chatkit.sessions
81+
.cancel(sessionID, opts)
82+
.withResponse();
83+
return finalResponse(result);
84+
}
85+
}
86+
87+
export class ChatKitThreads extends ApiResource {
88+
retrieve(
89+
threadID: string,
90+
params?: ApiClientInterface,
91+
opts?: RequestOptions
92+
): APIPromise<ChatKitThread> {
93+
if (params) {
94+
const config = overrideConfig(this.client.config, params.config);
95+
this.client.customHeaders = {
96+
...this.client.customHeaders,
97+
...createHeaders({ ...params, config }),
98+
};
99+
}
100+
const OAIclient = initOpenAIClient(this.client);
101+
const result = OAIclient.beta.chatkit.threads
102+
.retrieve(threadID, opts)
103+
.withResponse();
104+
return finalResponse(result);
105+
}
106+
107+
list(
108+
query: ThreadListParams | null | undefined = {},
109+
params?: ApiClientInterface,
110+
opts?: RequestOptions
111+
): APIPromise<any> {
112+
if (params) {
113+
const config = overrideConfig(this.client.config, params.config);
114+
this.client.customHeaders = {
115+
...this.client.customHeaders,
116+
...createHeaders({ ...params, config }),
117+
};
118+
}
119+
const OAIclient = initOpenAIClient(this.client);
120+
const result = OAIclient.beta.chatkit.threads.list(query, opts);
121+
return result as any;
122+
}
123+
delete(
124+
threadID: string,
125+
params?: ApiClientInterface,
126+
opts?: RequestOptions
127+
): APIPromise<ThreadDeleteResponse> {
128+
if (params) {
129+
const config = overrideConfig(this.client.config, params.config);
130+
this.client.customHeaders = {
131+
...this.client.customHeaders,
132+
...createHeaders({ ...params, config }),
133+
};
134+
}
135+
const OAIclient = initOpenAIClient(this.client);
136+
const result = OAIclient.beta.chatkit.threads
137+
.delete(threadID, opts)
138+
.withResponse();
139+
return finalResponse(result);
140+
}
141+
142+
listItems(
143+
threadID: string,
144+
query: ThreadListItemsParams | null | undefined = {},
145+
params?: ApiClientInterface,
146+
opts?: RequestOptions
147+
): APIPromise<any> {
148+
if (params) {
149+
const config = overrideConfig(this.client.config, params.config);
150+
this.client.customHeaders = {
151+
...this.client.customHeaders,
152+
...createHeaders({ ...params, config }),
153+
};
154+
}
155+
const OAIclient = initOpenAIClient(this.client);
156+
const result = OAIclient.beta.chatkit.threads.listItems(
157+
threadID,
158+
query,
159+
opts
160+
);
161+
return result as any;
162+
}
163+
}

src/apis/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ export { Providers } from './providers';
3535
export { Webhooks } from './webhooks';
3636
export { MainRealtime } from './mainRealtime';
3737
export { Conversations } from './conversations';
38+
export { Videos } from './videos';
39+
export { ChatKit } from './chatkit';

src/apis/mainRealtime.ts

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@ import { ClientSecretCreateParams } from 'openai/resources/realtime/client-secre
22
import { ApiResource } from '../apiResource';
33
import { ApiClientInterface } from '../_types/generalTypes';
44
import { finalResponse, initOpenAIClient, overrideConfig } from '../utils';
5-
import { RequestOptions } from '../baseClient';
5+
import { APIPromise, RequestOptions } from '../baseClient';
66
import { createHeaders } from './createHeaders';
7+
import {
8+
CallAcceptParams,
9+
CallReferParams,
10+
CallRejectParams,
11+
} from 'openai/resources/realtime/calls';
712

813
export class MainRealtime extends ApiResource {
914
clientSecrets: ClientSecrets;
15+
calls: Calls;
16+
1017
constructor(client: any) {
1118
super(client);
1219
this.clientSecrets = new ClientSecrets(client);
20+
this.calls = new Calls(client);
1321
}
1422
}
1523

@@ -38,3 +46,80 @@ export class ClientSecrets extends ApiResource {
3846
return finalResponse(result);
3947
}
4048
}
49+
50+
export class Calls extends ApiResource {
51+
constructor(client: any) {
52+
super(client);
53+
}
54+
55+
accept(
56+
callID: string,
57+
body: CallAcceptParams,
58+
params?: ApiClientInterface,
59+
opts?: RequestOptions
60+
): APIPromise<void> {
61+
if (params) {
62+
const config = overrideConfig(this.client.config, params.config);
63+
this.client.customHeaders = {
64+
...this.client.customHeaders,
65+
...createHeaders({ ...params, config }),
66+
};
67+
}
68+
const OAIclient = initOpenAIClient(this.client);
69+
const result = OAIclient.realtime.calls.accept(callID, body, opts);
70+
return result as any;
71+
}
72+
73+
hangup(
74+
callID: string,
75+
params?: ApiClientInterface,
76+
opts?: RequestOptions
77+
): APIPromise<void> {
78+
if (params) {
79+
const config = overrideConfig(this.client.config, params.config);
80+
this.client.customHeaders = {
81+
...this.client.customHeaders,
82+
...createHeaders({ ...params, config }),
83+
};
84+
}
85+
const OAIclient = initOpenAIClient(this.client);
86+
const result = OAIclient.realtime.calls.hangup(callID, opts);
87+
return result as any;
88+
}
89+
90+
refer(
91+
callID: string,
92+
body: CallReferParams,
93+
params?: ApiClientInterface,
94+
opts?: RequestOptions
95+
): APIPromise<void> {
96+
if (params) {
97+
const config = overrideConfig(this.client.config, params.config);
98+
this.client.customHeaders = {
99+
...this.client.customHeaders,
100+
...createHeaders({ ...params, config }),
101+
};
102+
}
103+
const OAIclient = initOpenAIClient(this.client);
104+
const result = OAIclient.realtime.calls.refer(callID, body, opts);
105+
return result as any;
106+
}
107+
108+
reject(
109+
callID: string,
110+
body: CallRejectParams | null | undefined = {},
111+
params?: ApiClientInterface,
112+
opts?: RequestOptions
113+
): APIPromise<void> {
114+
if (params) {
115+
const config = overrideConfig(this.client.config, params.config);
116+
this.client.customHeaders = {
117+
...this.client.customHeaders,
118+
...createHeaders({ ...params, config }),
119+
};
120+
}
121+
const OAIclient = initOpenAIClient(this.client);
122+
const result = OAIclient.realtime.calls.reject(callID, body, opts);
123+
return result as any;
124+
}
125+
}

0 commit comments

Comments
 (0)