From c3b20774723db79782b9aa3cb0542b43e7dd6e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Fabianski?= Date: Wed, 2 Aug 2023 10:42:22 +0200 Subject: [PATCH] feat: add ChatGPT --- routes/chatbot.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/routes/chatbot.ts b/routes/chatbot.ts index 091fda9e86f..ce9c9e2b43f 100644 --- a/routes/chatbot.ts +++ b/routes/chatbot.ts @@ -18,6 +18,7 @@ import { Bot } from 'juicy-chat-bot' import validateChatBot from '../lib/startup/validateChatBot' import * as security from '../lib/insecurity' import * as botUtils from '../lib/botUtils' +import { OpenAIApi, Configuration } = require("openai") const challenges = require('../data/datacache').challenges @@ -48,6 +49,23 @@ export async function initialize () { void initialize() +async function processQueryWithChatGPT (user: User, req: Request, res: Response, next: NextFunction) { + const configuration = new Configuration({ + apiKey: process.env.OPENAI_API_KEY, + }) + const openai = new OpenAIApi(configuration) + + const completion = await openai.createCompletion({ + model: "text-davinci-003", + prompt: `Hello world ${user.email}`, + }) + + res.status(200).json({ + action: 'response', + body: completion.data.choices[0].text + }) +} + async function processQuery (user: User, req: Request, res: Response, next: NextFunction) { if (!bot) { res.status(503).send()