feat: init v3

This commit is contained in:
ikechan8370 2025-03-05 23:56:41 +08:00
parent d6cb085c40
commit 531986b2dc
284 changed files with 618 additions and 405179 deletions

View file

@ -0,0 +1,74 @@
import ChatGPTStorage from '../storage.js'
/**
* @returns {import('chaite').ChannelsStorage}
*/
export async function createChannelsStorage () {
return new LowDBChannelStorage(ChatGPTStorage)
}
class LowDBChannelStorage {
/**
*
* @param { LowDBStorage } storage
*/
constructor (storage) {
this.storage = storage
/**
* 集合
* @type {LowDBCollection}
*/
this.collection = this.storage.collection('channel')
}
async saveChannel (channel) {
await this.collection.insert(channel)
}
async getChannel (id) {
return this.collection.collection()
}
/**
*
* @param name
* @returns {Promise<import('chaite').Channel[]>}
*/
async getChannelByName (name) {
return this.collection.find({ name })
}
async deleteChannel (name) {
await this.collection.delete({ name })
}
/**
* 获取所有渠道
* @param {string?} model
* @returns {Promise<import('chaite').Channel[]>}
*/
async getAllChannels (model) {
if (model) {
return this.collection.find({ 'options.model': model })
}
return this.collection.findAll()
}
/**
*
* @param {import('chaite').ClientType} type
* @returns {Promise<Object[]>}
*/
async getChannelByType (type) {
return this.collection.find({ type })
}
/**
*
* @param {'enabled' | 'disabled'} status
* @returns {Promise<*>}
*/
async getChannelByStatus (status) {
return this.collection.find({ status })
}
}

View file

@ -0,0 +1,53 @@
import ChatGPTStorage from '../storage.js'
/**
* @returns {import('chaite').ChatPresetsStorage}
*/
export async function createChatPresetsStorage () {
return new LowDBChatPresetsStorage(ChatGPTStorage)
}
class LowDBChatPresetsStorage {
/**
*
* @param { LowDBStorage } storage
*/
constructor (storage) {
this.storage = storage
/**
* 集合
* @type {LowDBCollection}
*/
this.collection = this.storage.collection('chat_presets')
}
/**
*
* @param {import('chaite').ChatPreset} preset
* @returns {Promise<void>}
*/
async savePreset (preset) {
await this.collection.insert(preset)
}
/**
*
* @param { string } name
* @returns {Promise<import('chaite').ChatPreset | null>}
*/
async getPreset (name) {
return this.collection.findOne({ name })
}
/**
*
* @returns {Promise<import('chaite').ChatPreset[]>}
*/
async getAllPresets () {
return this.collection.findAll()
}
async deletePreset (name) {
await this.collection.delete({ name })
}
}

28
models/chaite/cloud.js Normal file
View file

@ -0,0 +1,28 @@
import { DefaultToolCloudService, ToolManager } from 'chaite'
import ChatGPTConfig from '../../config/config.js'
import { createToolsSettingsStorage } from './tool_settings_storage.js'
const ChatGPTToolCloudService = new DefaultToolCloudService(ChatGPTConfig.cloudBaseUrl, '', {})
/**
* @type {import('chaite').ToolManager}
*/
let ChatGPTToolManager
ToolManager.getInstance(ChatGPTConfig.toolsDirPath, createToolsSettingsStorage(), ChatGPTToolCloudService).then((manager) => {
ChatGPTToolManager = manager
})
/**
* 认证以便共享上传
* @param apiKey
* @returns {Promise<import('chaite').User>}
*/
export async function authCloud (apiKey) {
const user = await ChatGPTToolCloudService.authenticate(apiKey)
ChatGPTToolManager.setCloudService(ChatGPTToolCloudService)
return user
}
export default {
ChatGPTToolCloudService,
ChatGPTToolManager
}

View file

@ -0,0 +1,53 @@
import ChatGPTStorage from '../storage.js'
/**
* @returns {import('chaite').ToolSettingsStorage}
*/
export function createToolsSettingsStorage () {
return new LowDBToolsSettingsStorage(ChatGPTStorage)
}
class LowDBToolsSettingsStorage {
/**
*
* @param { LowDBStorage } storage
*/
constructor (storage) {
this.storage = storage
/**
* 集合
* @type {LowDBCollection}
*/
this.collection = this.storage.collection('tool_settings')
}
/**
*
* @param {import('chaite').ToolSettings} settings
* @returns {Promise<void>}
*/
async saveToolSettings (settings) {
await this.collection.insert(settings)
}
/**
*
* @param { string } name
* @returns {Promise<import('chaite').ToolSettings | null>}
*/
async getToolSettings (name) {
return this.collection.findOne({ name })
}
/**
*
* @returns {Promise<import('chaite').ToolSettings[]>}
*/
async getAllToolSettings () {
return this.collection.findAll()
}
async deleteToolSettings (name) {
await this.collection.delete({ name })
}
}

View file

@ -0,0 +1,36 @@
// todo
class FaissVectorDatabase {
constructor (index) {
this.index = index
}
async addVector (vector, text) {
}
async addVectors (vectors, texts) {
}
async search (queryVector, k) {
}
async getVector (id) {
}
async deleteVector (id) {
}
async updateVector (id, newVector, newText) {
}
async count () {
}
async clear () {
}
}
/**
* 默认向量库
* @type {import('chaite').VectorDatabase}
*/
export const ChatGPTVectorDatabase = new FaissVectorDatabase()