aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/gpt/GPT.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/apis/gpt/GPT.ts')
-rw-r--r--src/client/apis/gpt/GPT.ts26
1 files changed, 1 insertions, 25 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts
index cca9d58f3..05007960d 100644
--- a/src/client/apis/gpt/GPT.ts
+++ b/src/client/apis/gpt/GPT.ts
@@ -1,5 +1,5 @@
-import { ClientOptions, OpenAI } from 'openai';
import { ChatCompletionMessageParam } from 'openai/resources';
+import { openai } from './setup';
enum GPTCallType {
SUMMARY = 'summary',
@@ -68,12 +68,7 @@ const gptAPICall = async (inputTextIn: string, callType: GPTCallType, prompt?: a
const opts: GPTCallOpts = callTypeMap[callType];
if (lastCall === inputText) return lastResp;
try {
- const configuration: ClientOptions = {
- apiKey: process.env.OPENAI_KEY,
- dangerouslyAllowBrowser: true,
- };
lastCall = inputText;
- const openai = new OpenAI(configuration);
const usePrompt = prompt ? opts.prompt + prompt : opts.prompt;
const messages: ChatCompletionMessageParam[] = [
@@ -96,12 +91,6 @@ const gptAPICall = async (inputTextIn: string, callType: GPTCallType, prompt?: a
};
const gptImageCall = async (prompt: string, n?: number) => {
try {
- const configuration: ClientOptions = {
- apiKey: process.env.OPENAI_KEY,
- dangerouslyAllowBrowser: true,
- };
-
- const openai = new OpenAI(configuration);
const response = await openai.images.generate({
prompt: prompt,
n: n ?? 1,
@@ -114,14 +103,8 @@ const gptImageCall = async (prompt: string, n?: number) => {
}
return undefined;
};
-
const gptGetEmbedding = async (src: string): Promise<number[]> => {
try {
- const configuration: ClientOptions = {
- apiKey: process.env.OPENAI_KEY,
- dangerouslyAllowBrowser: true,
- };
- const openai = new OpenAI(configuration);
const embeddingResponse = await openai.embeddings.create({
model: 'text-embedding-3-large',
input: [src],
@@ -137,15 +120,8 @@ const gptGetEmbedding = async (src: string): Promise<number[]> => {
return [];
}
};
-
const gptImageLabel = async (src: string): Promise<string> => {
try {
- const configuration: ClientOptions = {
- apiKey: process.env.OPENAI_KEY,
- dangerouslyAllowBrowser: true,
- };
-
- const openai = new OpenAI(configuration);
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [