|
| 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 | +} |
0 commit comments