Skip to content

Commit

Permalink
fix: correct natural language loading
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Oct 12, 2024
1 parent 815d420 commit 2977a71
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
24 changes: 12 additions & 12 deletions src/looking_glass/cheshire-cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type ProcedureHash = Record<string, {

export class CheshireCat {
private static instance: CheshireCat
private llm: BaseChatModel
private embedder: Embeddings
private llm!: BaseChatModel
private embedder!: Embeddings
private memory!: VectorMemory
private manager: AgentManager
private strays = new Map<string, StrayCat>()
Expand All @@ -30,8 +30,7 @@ export class CheshireCat {
private constructor() {
log.silent('Initializing the Cheshire Cat...')
db.update(db => madHatter.executeHook('beforeBootstrap', db))
this.llm = this.loadLanguageModel()
this.embedder = this.loadLanguageEmbedder()
this.loadNaturalLanguage()
madHatter.onPluginsSyncCallback = () => this.embedProcedures()
this.manager = new AgentManager()
}
Expand Down Expand Up @@ -107,10 +106,15 @@ export class CheshireCat {
}

/**
* Get the Large Language Model (LLM) settings at bootstrap time.
* @returns The found LLM settings from db or the default LLM settings
* Load the Large Language Model (LLM) and the Embedder from the database.
* If the selected LLM or Embedder is not found, it falls back to the default one.
*/
loadLanguageModel() {
loadNaturalLanguage() {
this.llm = this.loadLanguageModel()
this.embedder = this.loadLanguageEmbedder()
}

private loadLanguageModel() {
const selected = db.data.selectedLLM
try {
const llm = getLLM(selected)
Expand All @@ -126,11 +130,7 @@ export class CheshireCat {
}
}

/**
* Get the Embedder settings at bootstrap time.
* @returns The found Embedder settings from db or the default LLM settings
*/
loadLanguageEmbedder() {
private loadLanguageEmbedder() {
const selected = db.data.selectedEmbedder
try {
const embedder = getEmbedder(selected)
Expand Down
3 changes: 1 addition & 2 deletions src/routes/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export const embedderRoutes = new Elysia({
if (!emb) throw HttpError.NotFound(`The passed embedder id '${id}' doesn't exist in the list of available embedders.`)
const parsed = emb.config.safeParse(body)
if (!parsed.success) throw HttpError.InternalServer(parsed.error.errors.map(e => e.message).join())
cat.loadLanguageModel()
cat.loadLanguageEmbedder()
cat.loadNaturalLanguage()
try {
await cat.loadMemory()
await mh.findPlugins()
Expand Down
3 changes: 1 addition & 2 deletions src/routes/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export const llmRoutes = new Elysia({
if (!llm) throw HttpError.NotFound(`The passed embedder id '${id}' doesn't exist in the list of available embedders.`)
const parsed = llm.config.safeParse(body)
if (!parsed.success) throw HttpError.InternalServer(parsed.error.errors.map(e => e.message).join())
cat.loadLanguageModel()
cat.loadLanguageEmbedder()
cat.loadNaturalLanguage()
try {
await cat.loadMemory()
await mh.findPlugins()
Expand Down

0 comments on commit 2977a71

Please sign in to comment.