Send api token properly

This commit is contained in:
David Corbitt
2023-08-07 21:04:38 -07:00
parent 0f9a83cf45
commit 8fed9730da
5 changed files with 46 additions and 33 deletions

View File

@@ -1,11 +1,7 @@
import * as openai from "openai-beta";
import {
readEnv,
type RequestOptions,
} from "openai-beta/core";
import {
CompletionCreateParams,
} from "openai-beta/resources/chat/completions";
import { readEnv, type RequestOptions } from "openai-beta/core";
import { CompletionCreateParams } from "openai-beta/resources/chat/completions";
import axios from "axios";
export * as openai from "openai-beta";
import * as openPipeClient from "../codegen";
@@ -27,10 +23,20 @@ export class OpenAI extends openai.OpenAI {
super({ ...opts });
if (openPipeApiKey) {
this.openPipeApi = new openPipeClient.DefaultApi(new openPipeClient.Configuration({
apiKey: openPipeApiKey,
basePath: openPipeBaseUrl,
}));
const axiosInstance = axios.create({
baseURL: openPipeBaseUrl,
headers: {
'x-openpipe-api-key': openPipeApiKey,
},
});
this.openPipeApi = new openPipeClient.DefaultApi(
new openPipeClient.Configuration({
apiKey: openPipeApiKey,
basePath: openPipeBaseUrl,
}),
undefined,
axiosInstance
);
}
// Override the chat property
@@ -87,8 +93,7 @@ class ExtendedCompletions extends openai.OpenAI.Chat.Completions {
params as CompletionCreateParams.CreateChatCompletionRequestNonStreaming,
options
);
console.log('result is this', result)
this.openaiInstance.openPipeApi?.externalApiReport({
await this.openaiInstance.openPipeApi?.externalApiReport({
startTime,
endTime: Date.now(),
reqPayload: params,