| 18 | |
| 19 | export type ClientOptions = openai.ClientOptions & { openpipe?: OpenPipeConfig | OpenPipe }; |
| 20 | export default class OpenAI extends openai.OpenAI { |
| 21 | constructor({ openpipe, ...options }: ClientOptions = {}) { |
| 22 | super({ ...options }); |
| 23 | |
| 24 | const openpipeClient = openpipe instanceof OpenPipe ? openpipe : new OpenPipe(openpipe); |
| 25 | const openPipeApiKey = openpipeClient.baseClient.request.config.TOKEN; |
| 26 | |
| 27 | if (typeof openPipeApiKey === "string" && openPipeApiKey.length > 0) { |
| 28 | this.chat.setClients( |
| 29 | openpipeClient, |
| 30 | new openai.OpenAI({ |
| 31 | baseURL: openpipeClient.baseClient.request.config.BASE, |
| 32 | apiKey: openPipeApiKey, |
| 33 | }), |
| 34 | ); |
| 35 | } else { |
| 36 | console.warn( |
| 37 | "You're using the OpenPipe client without an API key. No completion requests will be logged.", |
| 38 | ); |
| 39 | } |
| 40 | } |
| 41 | chat: WrappedChat = new WrappedChat(this); |
| 42 | } |
| 43 | |
| 44 | class WrappedChat extends openai.OpenAI.Chat { |
| 45 | setClients(opClient: OpenPipe, opCompletionClient: openai.OpenAI) { |
no outgoing calls