Skip to content

Commit

Permalink
remove unused methods and types
Browse files Browse the repository at this point in the history
  • Loading branch information
fegloff committed Oct 2, 2024
1 parent 91be87d commit 6a18b63
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 69 deletions.
55 changes: 1 addition & 54 deletions src/modules/llms/utils/llmModelsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,25 @@ import {
type Provider,
type LLMData,
type LLMModel,
type ImageModel,
type ModelCommandMap,
type ModelPrefixMap
type ImageModel
} from './types'

export class LLMModelsManager {
private readonly models = new Map<string, LLMModel>()
private readonly modelsEnum: Record<string, string>
private readonly commandsEnum: Record<string, string>
private readonly commandMap: ModelCommandMap
private readonly prefixMap: ModelPrefixMap

constructor (llmData: LLMData) {
this.loadModels(llmData)
this.modelsEnum = this.createModelsEnum()
this.commandsEnum = this.createCommandsEnum()
this.commandMap = this.buildCommandMap()
this.prefixMap = this.buildPrefixMap()
}

private loadModels (data: LLMData): void {
Object.values(data.chatModels).forEach(model => { this.addModel(model) })
Object.values(data.imageModels).forEach(model => { this.addModel(model) })
}

private buildCommandMap (): ModelCommandMap {
const commandMap: ModelCommandMap = {}
this.models.forEach((model, version) => {
model.commands.forEach(command => {
commandMap[command] = {
model: version,
useTools: command === 'ctool' || command === 'stool',
stream: 'stream' in model ? model.stream : true
}
})
})
return commandMap
}

private buildPrefixMap (): ModelPrefixMap {
const prefixMap: ModelPrefixMap = {}
this.models.forEach((model, version) => {
if (model.prefix) {
model.prefix.forEach(prefix => {
prefixMap[prefix] = {
model: version,
stream: 'stream' in model ? model.stream : true
}
})
}
})
return prefixMap
}

getCommandMap (): ModelCommandMap {
return this.commandMap
}

getPrefixMap (): ModelPrefixMap {
return this.prefixMap
}

addModel (model: LLMModel): void {
this.models.set(model.version, model)
}
Expand All @@ -89,16 +46,6 @@ export class LLMModelsManager {
return commandsEnum
}

getModelByCommand (command: string): LLMModel | undefined {
const modelInfo = this.commandMap[command]
return modelInfo ? this.getModel(modelInfo.model) : undefined
}

getModelByPrefix (prefix: string): LLMModel | undefined {
const modelInfo = this.prefixMap[prefix]
return modelInfo ? this.getModel(modelInfo.model) : undefined
}

getModel (version: string): LLMModel | undefined {
return this.models.get(version)
}
Expand Down
15 changes: 0 additions & 15 deletions src/modules/llms/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,3 @@ export interface LLMData {
chatModels: Record<string, ChatModel>
imageModels: Record<string, ImageModel>
}

interface ModelCommandConfig {
model: string
useTools: boolean
stream: boolean
}

export interface ModelCommandMap extends Record<string, ModelCommandConfig> {}

interface ModelPrefixConfig {
model: string
stream: boolean
}

export interface ModelPrefixMap extends Record<string, ModelPrefixConfig> {}

0 comments on commit 6a18b63

Please sign in to comment.