diff options
Diffstat (limited to 'src/client/apis/gpt')
-rw-r--r-- | src/client/apis/gpt/GPT.ts | 26 | ||||
-rw-r--r-- | src/client/apis/gpt/PresCustomization.ts (renamed from src/client/apis/gpt/customization.ts) | 0 | ||||
-rw-r--r-- | src/client/apis/gpt/setup.ts | 23 |
3 files changed, 1 insertions, 48 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: [ diff --git a/src/client/apis/gpt/customization.ts b/src/client/apis/gpt/PresCustomization.ts index 2262886a2..2262886a2 100644 --- a/src/client/apis/gpt/customization.ts +++ b/src/client/apis/gpt/PresCustomization.ts diff --git a/src/client/apis/gpt/setup.ts b/src/client/apis/gpt/setup.ts index 7084f38bf..f648542f2 100644 --- a/src/client/apis/gpt/setup.ts +++ b/src/client/apis/gpt/setup.ts @@ -1,31 +1,8 @@ -// import { Configuration, OpenAIApi } from 'openai'; import { ClientOptions, OpenAI } from 'openai'; -export enum GPTCallType { - SUMMARY = 'summary', - COMPLETION = 'completion', - EDIT = 'edit', - FLASHCARD = 'flashcard', -} - -export type GPTCallOpts = { - model: string; - maxTokens: number; - temp: number; - prompt: string; -}; - -export const callTypeMap: { [type: string]: GPTCallOpts } = { - summary: { model: 'text-davinci-003', maxTokens: 256, temp: 0.5, prompt: 'Summarize this text in simpler terms: ' }, - edit: { model: 'text-davinci-003', maxTokens: 256, temp: 0.5, prompt: 'Reword this: ' }, - completion: { model: 'text-davinci-003', maxTokens: 256, temp: 0.5, prompt: '' }, -}; - const configuration: ClientOptions = { apiKey: process.env.OPENAI_KEY, dangerouslyAllowBrowser: true, }; export const openai = new OpenAI(configuration); - -// export const openai = new OpenAIApi(configuration); |