diff --git a/packages/app/chatbots/assistant.ts b/packages/app/chatbots/assistant.ts new file mode 100644 index 000000000..9004d9941 --- /dev/null +++ b/packages/app/chatbots/assistant.ts @@ -0,0 +1,30 @@ +import { getAuth } from 'protonode' +import { APIContext } from "protolib/bundles/apiContext" +import { API, Protofy, getLogger } from "protobase"; +import { Application } from 'express'; +import fs from 'fs' +import path from "path"; +import { createChatbot } from "protolib/bundles/chatbots/createChatbot"; + +const root = path.join(process.cwd(), '..', '..') +const logger = getLogger() + +Protofy("type", "chatGPT") + +export default Protofy("code", async (app:Application, context: typeof APIContext) => { + createChatbot(app, 'assistant', async (req, res, chatbot) => { + const {session, token} = getAuth(req) + context.chatGPT.chatGPTPrompt({ + ...req.body, + done: (response, message) => { + chatbot.end() + }, + chunk: (chunk) => { + chatbot.sendRaw(chunk) + }, + error: (error) => { + chatbot.sendError(error) + } + }) + }) +}) \ No newline at end of file diff --git a/packages/app/chatbots/index.ts b/packages/app/chatbots/index.ts index d14ca1bd7..1555f905c 100644 --- a/packages/app/chatbots/index.ts +++ b/packages/app/chatbots/index.ts @@ -1,6 +1,8 @@ import {Protofy} from 'protobase' +import assistantChatbot from "./assistant"; const chatbots = Protofy("chatbots", { + assistant: assistantChatbot }) export default (app, context) => { diff --git a/packages/protolib/src/components/chatbot/services/chatService.ts b/packages/protolib/src/components/chatbot/services/chatService.ts index c55a5f8b6..df958fe1c 100644 --- a/packages/protolib/src/components/chatbot/services/chatService.ts +++ b/packages/protolib/src/components/chatbot/services/chatService.ts @@ -1,6 +1,6 @@ import { ChatMessageType, ModalList, useSettings } from "../store/store"; -const apiUrl = "https://api.openai.com/v1/chat/completions"; +const apiUrl = "/api/v1/chatbots/assistant"; const IMAGE_GENERATION_API_URL = "https://api.openai.com/v1/images/generations"; export async function fetchResults(