Skip to content

Commit

Permalink
Swiches chatui to use the assistant instead of the openai api
Browse files Browse the repository at this point in the history
  • Loading branch information
ap0k4 committed Nov 7, 2024
1 parent ec4734b commit 269aad2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/app/chatbots/assistant.ts
Original file line number Diff line number Diff line change
@@ -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)
}
})
})
})
2 changes: 2 additions & 0 deletions packages/app/chatbots/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Protofy} from 'protobase'
import assistantChatbot from "./assistant";

const chatbots = Protofy("chatbots", {
assistant: assistantChatbot
})

export default (app, context) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit 269aad2

Please sign in to comment.