aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/gpt
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/apis/gpt')
-rw-r--r--src/client/apis/gpt/GPT.ts33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts
index 6bde7989b..d1606e7f0 100644
--- a/src/client/apis/gpt/GPT.ts
+++ b/src/client/apis/gpt/GPT.ts
@@ -1,3 +1,5 @@
+import { config } from "dotenv";
+config();
import { Configuration, OpenAIApi } from 'openai';
enum GPTCallType {
@@ -65,4 +67,33 @@ const gptImageCall = async (prompt: string, n?: number) => {
}
};
-export { gptAPICall, gptImageCall, GPTCallType };
+const gptCSVCall = async (inputText: string, callType: GPTCallType) => {
+ const opts: GPTCallOpts = callTypeMap[callType];
+ try {
+ const configuration = new Configuration({
+ apiKey: process.env.OPENAI_KEY,
+ });
+ const openai = new OpenAIApi(configuration);
+ // const client = OpenAIApi;
+ // const response = await openai.createCompletion({
+ // model: opts.model,
+ // max_tokens: opts.maxTokens,
+ // temperature: opts.temp,
+ // prompt: `${opts.prompt}${inputText}`,
+ // });
+ // return response.data.choices[0].text;
+
+ const responseGpt = await openai.createChatCompletion({
+ model: "gpt-3.5-turbo-16k",
+ messages: [{role: "user", content: inputText}],
+ })
+ const generatedResponse = responseGpt.data.choices[0].message?.content;
+ console.log(generatedResponse);
+ return generatedResponse;
+ } catch (err) {
+ console.log(err);
+ return 'Error connecting with API.';
+ }
+};
+
+export { gptAPICall, gptImageCall, gptCSVCall, GPTCallType };