mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 05:17:10 +00:00
fix: cloud wip
This commit is contained in:
parent
f521e0ede8
commit
5c1b74bfb1
7 changed files with 226 additions and 7 deletions
|
|
@ -61,6 +61,43 @@ export class LowDBChannelStorage extends ChaiteStorage {
|
|||
return list.map(item => new Channel({}).fromString(JSON.stringify(item)))
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Record<string, unknown>} filter
|
||||
* @returns {Promise<import('chaite').Channel[]>}
|
||||
*/
|
||||
async listItemsByEqFilter (filter) {
|
||||
const allList = await this.listItems()
|
||||
return allList.filter(item => {
|
||||
for (const key in filter) {
|
||||
if (item[key] !== filter[key]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array<{
|
||||
* field: string;
|
||||
* values: unknown[];
|
||||
* }>} query
|
||||
* @returns {Promise<import('chaite').Channel[]>}
|
||||
*/
|
||||
async listItemsByInQuery (query) {
|
||||
const allList = await this.listItems()
|
||||
return allList.filter(item => {
|
||||
for (const { field, values } of query) {
|
||||
if (!values.includes(item[field])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
async clear () {
|
||||
await this.collection.deleteAll()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,43 @@ export class LowDBChatPresetsStorage extends ChaiteStorage {
|
|||
return list.map(item => new ChatPreset({}).fromString(JSON.stringify(item)))
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Record<string, unknown>} filter
|
||||
* @returns {Promise<import('chaite').ChatPreset[]>}
|
||||
*/
|
||||
async listItemsByEqFilter (filter) {
|
||||
const allList = await this.listItems()
|
||||
return allList.filter(item => {
|
||||
for (const key in filter) {
|
||||
if (item[key] !== filter[key]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array<{
|
||||
* field: string;
|
||||
* values: unknown[];
|
||||
* }>} query
|
||||
* @returns {Promise<import('chaite').ChatPreset[]>}
|
||||
*/
|
||||
async listItemsByInQuery (query) {
|
||||
const allList = await this.listItems()
|
||||
return allList.filter(item => {
|
||||
for (const { field, values } of query) {
|
||||
if (!values.includes(item[field])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
async clear () {
|
||||
await this.collection.deleteAll()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import { ChatGPTUserModeSelector } from './user_mode_selector.js'
|
|||
import { LowDBUserStateStorage } from './user_state_storage.js'
|
||||
import { LowDBHistoryManager } from './history_manager.js'
|
||||
import { VectraVectorDatabase } from './vector_database.js'
|
||||
import ChatGPTStorage, {ChatGPTHistoryStorage} from '../storage.js'
|
||||
import ChatGPTStorage, { ChatGPTHistoryStorage } from '../storage.js'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { migrateDatabase } from '../../utils/initDB.js'
|
||||
|
|
@ -28,11 +28,15 @@ import { LowDBToolsGroupDTOsStorage } from './tool_groups_storage.js'
|
|||
/**
|
||||
* 认证,以便共享上传
|
||||
* @param apiKey
|
||||
* @returns {Promise<import('chaite').User> | null}
|
||||
* @returns {Promise<import('chaite').User | null>}
|
||||
*/
|
||||
export async function authCloud (apiKey = ChatGPTConfig.chaite.cloudApiKey) {
|
||||
await Chaite.getInstance().auth(apiKey)
|
||||
return Chaite.getInstance().getToolsManager().cloudService.getUser()
|
||||
try {
|
||||
await Chaite.getInstance().auth(apiKey)
|
||||
return Chaite.getInstance().getToolsManager().cloudService.getUser()
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -141,7 +145,10 @@ export async function initChaite () {
|
|||
chaite.setCloudService(ChatGPTConfig.chaite.cloudBaseUrl)
|
||||
logger.info('Chaite.Cloud 初始化完成')
|
||||
await migrateDatabase()
|
||||
ChatGPTConfig.chaite.cloudApiKey && await chaite.auth(ChatGPTConfig.chaite.cloudApiKey)
|
||||
if (ChatGPTConfig.chaite.cloudApiKey) {
|
||||
const user = await authCloud(ChatGPTConfig.chaite.cloudApiKey)
|
||||
logger.info(`Chaite.Cloud 认证成功, 当前用户${user.username || user.email} (${user.user_id})`)
|
||||
}
|
||||
await initRagManager(ChatGPTConfig.llm.embeddingModel, ChatGPTConfig.llm.dimensions)
|
||||
if (!ChatGPTConfig.chaite.authKey) {
|
||||
ChatGPTConfig.chaite.authKey = Chaite.getInstance().getFrontendAuthHandler().generateToken(0, true)
|
||||
|
|
|
|||
|
|
@ -64,6 +64,43 @@ export class LowDBProcessorsStorage extends ChaiteStorage {
|
|||
return list.map(item => new ProcessorDTO({}).fromString(JSON.stringify(item)))
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Record<string, unknown>} filter
|
||||
* @returns {Promise<import('chaite').Processor[]>}
|
||||
*/
|
||||
async listItemsByEqFilter (filter) {
|
||||
const allList = await this.listItems()
|
||||
return allList.filter(item => {
|
||||
for (const key in filter) {
|
||||
if (item[key] !== filter[key]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array<{
|
||||
* field: string;
|
||||
* values: unknown[];
|
||||
* }>} query
|
||||
* @returns {Promise<import('chaite').Processor[]>}
|
||||
*/
|
||||
async listItemsByInQuery (query) {
|
||||
const allList = await this.listItems()
|
||||
return allList.filter(item => {
|
||||
for (const { field, values } of query) {
|
||||
if (!values.includes(item[field])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
async clear () {
|
||||
await this.collection.deleteAll()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,43 @@ export class LowDBToolsStorage extends ChaiteStorage {
|
|||
return list.map(item => new ToolDTO({}).fromString(JSON.stringify(item)))
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Record<string, unknown>} filter
|
||||
* @returns {Promise<import('chaite').ToolDTO[]>}
|
||||
*/
|
||||
async listItemsByEqFilter (filter) {
|
||||
const allList = await this.listItems()
|
||||
return allList.filter(item => {
|
||||
for (const key in filter) {
|
||||
if (item[key] !== filter[key]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array<{
|
||||
* field: string;
|
||||
* values: unknown[];
|
||||
* }>} query
|
||||
* @returns {Promise<import('chaite').ToolDTO[]>}
|
||||
*/
|
||||
async listItemsByInQuery (query) {
|
||||
const allList = await this.listItems()
|
||||
return allList.filter(item => {
|
||||
for (const { field, values } of query) {
|
||||
if (!values.includes(item[field])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
async clear () {
|
||||
await this.collection.deleteAll()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue