mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: chaite
This commit is contained in:
parent
fbcf4e6c08
commit
a16538f322
12 changed files with 60 additions and 50 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +1,4 @@
|
|||
node_modules/
|
||||
data/
|
||||
utils/processors
|
||||
utils/tools
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import ChatGPTStorage from '../storage.js'
|
||||
import { ChaiteStorage } from 'chaite'
|
||||
|
||||
class LowDBChannelStorage extends ChaiteStorage {
|
||||
export class LowDBChannelStorage extends ChaiteStorage {
|
||||
/**
|
||||
*
|
||||
* @param { LowDBStorage } storage
|
||||
*/
|
||||
constructor (storage = ChatGPTStorage) {
|
||||
constructor (storage) {
|
||||
super()
|
||||
this.storage = storage
|
||||
/**
|
||||
|
|
@ -61,5 +60,3 @@ class LowDBChannelStorage extends ChaiteStorage {
|
|||
await this.collection.deleteAll()
|
||||
}
|
||||
}
|
||||
|
||||
export default new LowDBChannelStorage()
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
import ChatGPTStorage from '../storage.js'
|
||||
import { ChaiteStorage } from 'chaite'
|
||||
|
||||
/**
|
||||
* @extends {ChaiteStorage<import('chaite').ChatPreset>}
|
||||
*/
|
||||
class LowDBChatPresetsStorage extends ChaiteStorage {
|
||||
export class LowDBChatPresetsStorage extends ChaiteStorage {
|
||||
/**
|
||||
*
|
||||
* @param { LowDBStorage } storage
|
||||
*/
|
||||
constructor (storage = ChatGPTStorage) {
|
||||
constructor (storage) {
|
||||
super()
|
||||
this.storage = storage
|
||||
/**
|
||||
|
|
@ -64,5 +63,3 @@ class LowDBChatPresetsStorage extends ChaiteStorage {
|
|||
await this.collection.deleteAll()
|
||||
}
|
||||
}
|
||||
|
||||
export default new LowDBChatPresetsStorage()
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
import { Chaite, ChannelsManager, ChatPresetManager, DefaultChannelLoadBalancer, GeminiClient, OpenAIClient, ProcessorsManager, RAGManager, ToolManager } from 'chaite'
|
||||
import ChatGPTConfig from '../../config/config.js'
|
||||
import ChatGPTChannelStorage from './channel_storage.js'
|
||||
import ChatPresetStorage from './chat_preset_storage.js'
|
||||
import ChatGPTToolStorage from './tools_storage.js'
|
||||
import ChatGPTProcessorsStorage from './processors_storage.js'
|
||||
import { LowDBChannelStorage } from './channel_storage.js'
|
||||
import { LowDBChatPresetsStorage } from './chat_preset_storage.js'
|
||||
import { LowDBToolsStorage } from './tools_storage.js'
|
||||
import { LowDBProcessorsStorage } from './processors_storage.js'
|
||||
import { ChatGPTUserModeSelector } from './user_mode_selector.js'
|
||||
import { LowDBUserStateStorage } from './user_state_storage.js'
|
||||
import { LowDBHistoryManager } from './history_manager.js'
|
||||
import { ChatGPTVectorDatabase } from './vector_database.js'
|
||||
import { VectraVectorDatabase } from './vector_database.js'
|
||||
import ChatGPTStorage from '../storage.js'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
/**
|
||||
* 认证,以便共享上传
|
||||
|
|
@ -87,18 +90,33 @@ export async function initRagManager (model, dimensions) {
|
|||
return results
|
||||
}
|
||||
}()
|
||||
const ragManager = new RAGManager(ChatGPTVectorDatabase, vectorizer)
|
||||
const vectorDBPath = path.resolve('./plugins/chatgpt-plugin', ChatGPTConfig.dataDir, 'vector_index')
|
||||
if (!fs.existsSync(vectorDBPath)) {
|
||||
fs.mkdirSync(vectorDBPath, { recursive: true })
|
||||
}
|
||||
const vectorDB = new VectraVectorDatabase(vectorDBPath)
|
||||
await vectorDB.init()
|
||||
const ragManager = new RAGManager(vectorDB, vectorizer)
|
||||
return Chaite.getInstance().setRAGManager(ragManager)
|
||||
}
|
||||
|
||||
export async function initChaite () {
|
||||
const channelsManager = await ChannelsManager.init(ChatGPTChannelStorage, new DefaultChannelLoadBalancer())
|
||||
const toolsManager = await ToolManager.init(ChatGPTConfig.toolsDirPath, ChatGPTToolStorage)
|
||||
const processorsManager = await ProcessorsManager.init(ChatGPTConfig.processorsDirPath, ChatGPTProcessorsStorage)
|
||||
const chatPresetManager = await ChatPresetManager.init(ChatPresetStorage)
|
||||
await ChatGPTStorage.init()
|
||||
const channelsManager = await ChannelsManager.init(new LowDBChannelStorage(ChatGPTStorage), new DefaultChannelLoadBalancer())
|
||||
const toolsDir = path.resolve('./plugins/chatgpt-plugin', ChatGPTConfig.toolsDirPath)
|
||||
if (!fs.existsSync(toolsDir)) {
|
||||
fs.mkdirSync(toolsDir, { recursive: true })
|
||||
}
|
||||
const toolsManager = await ToolManager.init(toolsDir, new LowDBToolsStorage(ChatGPTStorage))
|
||||
const processorsDir = path.resolve('./plugins/chatgpt-plugin', ChatGPTConfig.processorsDirPath)
|
||||
if (!fs.existsSync(processorsDir)) {
|
||||
fs.mkdirSync(processorsDir, { recursive: true })
|
||||
}
|
||||
const processorsManager = await ProcessorsManager.init(processorsDir, new LowDBProcessorsStorage(ChatGPTStorage))
|
||||
const chatPresetManager = await ChatPresetManager.init(new LowDBChatPresetsStorage(ChatGPTStorage))
|
||||
const userModeSelector = new ChatGPTUserModeSelector()
|
||||
const userStateStorage = new LowDBUserStateStorage()
|
||||
const historyManager = new LowDBHistoryManager()
|
||||
const userStateStorage = new LowDBUserStateStorage(ChatGPTStorage)
|
||||
const historyManager = new LowDBHistoryManager(ChatGPTStorage)
|
||||
let chaite = Chaite.init(channelsManager, toolsManager, processorsManager, chatPresetManager,
|
||||
userModeSelector, userStateStorage, historyManager, logger)
|
||||
logger.info('Chaite 初始化完成')
|
||||
|
|
@ -130,4 +148,7 @@ export async function initChaite () {
|
|||
return ChatGPTConfig
|
||||
})
|
||||
logger.info('Chaite.RAGManager 初始化完成')
|
||||
const token = chaite.getFrontendAuthHandler().generateToken()
|
||||
logger.info(token)
|
||||
chaite.runApiServer()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import { AbstractHistoryManager } from 'chaite'
|
||||
import ChatGPTStorage from '../storage.js'
|
||||
|
||||
export class LowDBHistoryManager extends AbstractHistoryManager {
|
||||
/**
|
||||
*
|
||||
* @param { LowDBStorage } storage
|
||||
*/
|
||||
constructor (storage = ChatGPTStorage) {
|
||||
constructor (storage) {
|
||||
super()
|
||||
this.storage = storage
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
import ChatGPTStorage from '../storage.js'
|
||||
import { ChaiteStorage } from 'chaite'
|
||||
|
||||
/**
|
||||
* @extends {ChaiteStorage<import('chaite').Processor>}
|
||||
*/
|
||||
class LowDBProcessorsStorage extends ChaiteStorage {
|
||||
export class LowDBProcessorsStorage extends ChaiteStorage {
|
||||
/**
|
||||
*
|
||||
* @param { LowDBStorage } storage
|
||||
*/
|
||||
constructor (storage = ChatGPTStorage) {
|
||||
constructor (storage) {
|
||||
super()
|
||||
this.storage = storage
|
||||
/**
|
||||
|
|
@ -64,5 +63,3 @@ class LowDBProcessorsStorage extends ChaiteStorage {
|
|||
await this.collection.deleteAll()
|
||||
}
|
||||
}
|
||||
|
||||
export default new LowDBProcessorsStorage()
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
import ChatGPTStorage from '../storage.js'
|
||||
import { ChaiteStorage } from 'chaite'
|
||||
|
||||
/**
|
||||
* @extends {ChaiteStorage<import('chaite').ToolDTO>}
|
||||
*/
|
||||
class LowDBToolSettingsStorage extends ChaiteStorage {
|
||||
export class LowDBToolsStorage extends ChaiteStorage {
|
||||
/**
|
||||
*
|
||||
* @param { LowDBStorage } storage
|
||||
*/
|
||||
constructor (storage = ChatGPTStorage) {
|
||||
constructor (storage) {
|
||||
super()
|
||||
this.storage = storage
|
||||
/**
|
||||
|
|
@ -64,5 +63,3 @@ class LowDBToolSettingsStorage extends ChaiteStorage {
|
|||
await this.collection.deleteAll()
|
||||
}
|
||||
}
|
||||
|
||||
export default new LowDBToolSettingsStorage()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { AbstractUserModeSelector } from '../../../../../../../WebstormProjects/node-chaite/src/types/external.js'
|
||||
import { AbstractUserModeSelector } from 'chaite'
|
||||
|
||||
export class ChatGPTUserModeSelector extends AbstractUserModeSelector {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import ChatGPTStorage from '../storage.js'
|
||||
import { ChaiteStorage } from 'chaite'
|
||||
|
||||
/**
|
||||
|
|
@ -9,7 +8,7 @@ export class LowDBUserStateStorage extends ChaiteStorage {
|
|||
*
|
||||
* @param {LowDBStorage} storage
|
||||
*/
|
||||
constructor (storage = ChatGPTStorage) {
|
||||
constructor (storage) {
|
||||
super()
|
||||
this.storage = storage
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ import { md5 } from '../../utils/common.js'
|
|||
|
||||
/**
|
||||
* 基于Vectra实现的简单向量数据库,作为默认实现
|
||||
* @implements { import('chaite').VectorDatabase }
|
||||
*/
|
||||
class VectraVectorDatabase {
|
||||
export class VectraVectorDatabase {
|
||||
constructor (indexFile) {
|
||||
this.index = new LocalIndex(indexFile)
|
||||
this.init()
|
||||
}
|
||||
|
||||
async init () {
|
||||
|
|
@ -82,9 +82,3 @@ class VectraVectorDatabase {
|
|||
await this.index.deleteIndex()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认向量库 todo
|
||||
* @type {import('chaite').VectorDatabase}
|
||||
*/
|
||||
export const ChatGPTVectorDatabase = new VectraVectorDatabase()
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export class LowDBStorage {
|
|||
|
||||
this.filePath = path.join(directory, filename)
|
||||
this.adapter = new JSONFile(this.filePath)
|
||||
this.db = new Low(this.adapter)
|
||||
this.db = new Low(this.adapter, { collections: {} })
|
||||
this.initialized = false
|
||||
}
|
||||
|
||||
|
|
@ -348,11 +348,18 @@ export class LowDBCollection {
|
|||
}
|
||||
}
|
||||
|
||||
const dataDir = path.resolve('./plugins/chatgpt-plugin', ChatGPTConfig.dataDir)
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
fs.mkdirSync(dataDir, { recursive: true })
|
||||
}
|
||||
const storageLocation = path.resolve(dataDir, 'storage.json')
|
||||
if (!fs.existsSync(storageLocation)) {
|
||||
fs.writeFileSync(storageLocation, JSON.stringify({ collections: {} }))
|
||||
}
|
||||
|
||||
const ChatGPTStorage = new LowDBStorage({
|
||||
filename: 'storage.json',
|
||||
directory: ChatGPTConfig.dataDir
|
||||
directory: dataDir
|
||||
})
|
||||
|
||||
ChatGPTStorage.init()
|
||||
|
||||
export default ChatGPTStorage
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"type": "module",
|
||||
"author": "ikechan8370",
|
||||
"dependencies": {
|
||||
"chaite": "^1.1.1",
|
||||
"chaite": "/Users/geyinchi/WebstormProjects/node-chaite",
|
||||
"keyv": "^5.3.1",
|
||||
"keyv-file": "^5.1.2",
|
||||
"lowdb": "^7.0.1",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue