diff options
author | Sophie Zhang <sophie_zhang@brown.edu> | 2024-01-30 23:10:31 -0500 |
---|---|---|
committer | Sophie Zhang <sophie_zhang@brown.edu> | 2024-01-30 23:10:31 -0500 |
commit | e9dddc1ddadcaf3333ce95a2009c94f42e0152d4 (patch) | |
tree | 5c39532ba7a69b002c417fc75812c7227a6bc1d3 /src | |
parent | ab5a45b75d44c4c3277854d0581a200cb1018e73 (diff) |
gpt cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/client/apis/gpt/customization.ts | 13 | ||||
-rw-r--r-- | src/client/apis/gpt/setup.ts | 12 |
2 files changed, 15 insertions, 10 deletions
diff --git a/src/client/apis/gpt/customization.ts b/src/client/apis/gpt/customization.ts index 135b83353..db91e45a7 100644 --- a/src/client/apis/gpt/customization.ts +++ b/src/client/apis/gpt/customization.ts @@ -1,5 +1,6 @@ -import { ChatCompletionRequestMessage } from 'openai'; +import { ChatCompletionMessageParam } from 'openai/resources'; import { openai } from './setup'; +import { ClientOptions, OpenAI } from 'openai'; export enum CustomizationType { PRES_TRAIL_SLIDE = 'trails', @@ -67,7 +68,7 @@ export const gptTrailSlideCustomization = async (inputText: string) => { prompt += 'If the input does not contain info a specific key, please set their value to null. Please only return the json with these keys and their values.'; try { - const response = await openai.createChatCompletion({ + const response = await openai.chat.completions.create({ model: 'gpt-3.5-turbo', messages: [ { role: 'system', content: prompt }, @@ -76,7 +77,7 @@ export const gptTrailSlideCustomization = async (inputText: string) => { temperature: 0.1, max_tokens: 1000, }); - return response.data.choices[0].message?.content; + return response.choices[0].message?.content; } catch (err) { console.log(err); return 'Error connecting with API.'; @@ -115,7 +116,7 @@ export const generatePalette = async (inputData: StyleInput, useImageData: boole // iteration - let messages: ChatCompletionRequestMessage[] = [ + let messages: ChatCompletionMessageParam[] = [ { role: 'system', content: prompt }, { role: 'user', content: JSON.stringify(inputData) }, ]; @@ -131,13 +132,13 @@ export const generatePalette = async (inputData: StyleInput, useImageData: boole console.log('Messages: ', messages); try { - const response = await openai.createChatCompletion({ + const response = await openai.chat.completions.create({ model: 'gpt-4', messages: messages, temperature: 0.1, max_tokens: 2000, }); - const content = response.data.choices[0].message?.content; + const content = response.choices[0].message?.content; console.log(content); if (content) { return content; diff --git a/src/client/apis/gpt/setup.ts b/src/client/apis/gpt/setup.ts index d1db6968a..831c97eaa 100644 --- a/src/client/apis/gpt/setup.ts +++ b/src/client/apis/gpt/setup.ts @@ -1,4 +1,5 @@ -import { Configuration, OpenAIApi } from 'openai'; +// import { Configuration, OpenAIApi } from 'openai'; +import { ClientOptions, OpenAI } from 'openai'; export enum GPTCallType { SUMMARY = 'summary', @@ -19,8 +20,11 @@ export const callTypeMap: { [type: string]: GPTCallOpts } = { completion: { model: 'text-davinci-003', maxTokens: 256, temp: 0.5, prompt: '' }, }; -const configuration = new Configuration({ +const configuration: ClientOptions = { apiKey: process.env.OPENAI_KEY, -}); + dangerouslyAllowBrowser: true, +}; + +export const openai = new OpenAI(configuration); -export const openai = new OpenAIApi(configuration); +// export const openai = new OpenAIApi(configuration); |