Skip to content

Commit

Permalink
fix(core): failed to uninstall client properly
Browse files Browse the repository at this point in the history
  • Loading branch information
dingyi222666 committed Sep 10, 2023
1 parent 49c2b0f commit 2349370
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
12 changes: 8 additions & 4 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,19 @@ export const Config: Schema<Config> = Schema.intersect([
}).description('对话选项'),

Schema.object({
defaultEmbeddings: Schema.dynamic('embeddings').description('默认使用的嵌入模型'),
defaultEmbeddings: Schema.dynamic('embeddings')
.description('默认使用的嵌入模型')
.default('无'),

defaultVectorStore: Schema.dynamic('vector-store').description('默认使用的向量数据库')
defaultVectorStore: Schema.dynamic('vector-store')
.description('默认使用的向量数据库')
.default('无')
}).description('模型选项'),

Schema.object({
defaultChatMode: Schema.dynamic('chat-mode').default('chat').description('聊天模式'),
defaultModel: Schema.dynamic('model').description('聊天模型'),
defaultPreset: Schema.dynamic('preset').description('聊天预设')
defaultModel: Schema.dynamic('model').description('聊天模型').default('无'),
defaultPreset: Schema.dynamic('preset').description('聊天预设').default('chatgpt')
}).description('模板房间选项'),

Schema.object({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/llm-core/chat/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class ChatInterface {

const [platform, modelName] = parseRawModelName(this._input.embeddings)

logger.info(`ChatHubLLMChainWrapper init embeddings 1 for ${platform}, ${modelName}`)
logger.info(`ChatHubLLMChainWrapper init embeddings for ${platform}, ${modelName}`)

const client = await service.randomClient(platform)

Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/llm-core/chat/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ function updateChatChains(ctx: Context, service: PlatformService) {
}

function updateEmbeddings(ctx: Context, service: PlatformService) {
ctx.schema.set('embedding', Schema.union(getModelNames(service, ModelType.embeddings)))
ctx.schema.set('embeddings', Schema.union(getModelNames(service, ModelType.embeddings)))
}

function updateVectorStoreRetriever(ctx: Context, service: PlatformService) {
const vectorStoreRetrieverNames = service
.getVectorStoreRetrievers()
.concat('无')
.map((name) => Schema.const(name))

ctx.schema.set('vector-store', Schema.union(vectorStoreRetrieverNames))
Expand All @@ -138,5 +139,7 @@ function getChatChainNames(service: PlatformService) {
}

function getModelNames(service: PlatformService, type: ModelType = ModelType.llm) {
return service.getAllModels(type).map((model) => Schema.const(model).description(model))
const models = service.getAllModels(type).concat('无')

return models.map((model) => Schema.const(model).description(model))
}
40 changes: 33 additions & 7 deletions packages/core/src/llm-core/platform/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,40 @@ export class PlatformService {
delete PlatformService._toolCreators[name]
}

async unregisterClient(name: PlatformClientNames) {
const clients = PlatformService._platformClients[name]
delete PlatformService._createClientFunctions[name]
delete PlatformService._configPools[name]
delete PlatformService._models[name]
delete PlatformService._platformClients[name]
async unregisterClient(platform: PlatformClientNames) {
const configPool = PlatformService._configPools[platform]

if (!configPool) {
throw new Error(`Config pool ${platform} not found`)
}

const configs = configPool.getConfigs()

delete PlatformService._models[platform]

await sleep(50)
await this.ctx.parallel('chathub/model-removed', this, name, clients)

for (const config of configs) {
const client = await this.getClient(config.value)

if (client == null) {
continue
}

if (client instanceof PlatformModelClient) {
await this.ctx.parallel('chathub/model-removed', this, platform, client)
} else if (client instanceof PlatformEmbeddingsClient) {
await this.ctx.parallel('chathub/embeddings-removed', this, platform, client)
} else if (client instanceof PlatformModelAndEmbeddingsClient) {
await this.ctx.parallel('chathub/embeddings-removed', this, platform, client)
await this.ctx.parallel('chathub/model-removed', this, platform, client)
}

delete PlatformService._platformClients[this._getClientConfigAsKey(config.value)]
}

delete PlatformService._configPools[platform]
delete PlatformService._createClientFunctions[platform]
}

async unregisterVectorStoreRetriever(name: string) {
Expand Down

0 comments on commit 2349370

Please sign in to comment.