Skip to content

Commit

Permalink
fix: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed May 30, 2024
1 parent 1b5c0f6 commit e554f19
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ nodemon.once('start', () => {
log.info('Restarting the Cat...')
}).on('quit', () => {
log.info('Stopping the Cat...')
deleteTempFiles('./src', f => f.startsWith('tmp_') && f.endsWith('.ts'))
deleteTempFiles('./src')
process.exit()
}).on('error', (err) => {
log.error(err)
Expand All @@ -35,11 +35,11 @@ process.on('SIGINT', () => {
nodemon.emit('quit')
})

function deleteTempFiles(path: string, check: (str: string) => boolean) {
function deleteTempFiles(path: string) {
readdirSync(path).forEach((file) => {
const filePath = join(path, file)
const isDirectory = statSync(filePath).isDirectory()
if (isDirectory) deleteTempFiles(filePath, check)
else if (check(file)) unlinkSync(filePath)
if (isDirectory) deleteTempFiles(filePath)
else if (file.startsWith('tmp_') && file.endsWith('.ts')) unlinkSync(filePath)
})
}
14 changes: 8 additions & 6 deletions src/looking_glass/agent-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import { NewTokenHandler } from './callbacks.ts'
* before feeding them to the Agent. It also instantiates the Langchain Agent.
*/
export class AgentManager {
private verboseRunnable = new RunnableLambda({ func: (x) => {
if (parsedEnv.verbose) log.info(JSON.stringify(x))
return x
} })
private verboseRunnable = new RunnableLambda({
func: (x) => {
if (parsedEnv.verbose) log.info(JSON.stringify(x))
return x
},
})

async executeProceduresChain(agentInput: ContextInput, chatHistory: string, stray: StrayCat) {
let recalledProcedures = stray.workingMemory.procedural.filter((p) => {
Expand Down Expand Up @@ -66,7 +68,7 @@ export class AgentManager {
tools: allowedTools.map(p => ` - "${p.name}": ${p.description}`).join('\n'),
tool_names: Object.keys(allowedProcedures).map(p => `"${p}"`).join(', '),
chat_history: chatHistory,
agent_scratchpad: '',
scratchpad: '',
examples,
})

Expand All @@ -79,7 +81,7 @@ export class AgentManager {
}

const agent = RunnablePassthrough.assign({
agent_scratchpad: x => generatedScratchpad((x.intermediateSteps ?? []) as AgentStep[]),
scratchpad: x => generatedScratchpad((x.intermediateSteps ?? []) as AgentStep[]),
}).pipe(prompt).pipe(this.verboseRunnable).pipe(stray.currentLLM).pipe(new ProceduresOutputParser())

const agentExecutor = AgentExecutor.fromAgentAndTools({
Expand Down
2 changes: 1 addition & 1 deletion src/looking_glass/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ When you have a final answer (or no actions are relevant), use the following for
{chat_history}
## Actions sequence used until now
{agent_scratchpad}
{scratchpad}
## Next action to perform or final_answer:
`
Expand Down
1 change: 0 additions & 1 deletion src/looking_glass/stray-cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { destr } from 'destr'
import { type PluginManifest, madHatter } from '@mh'
import { log } from '@logger'
import { rabbitHole } from '@rh'
import type { ChainValues } from '@langchain/core/utils/types'
import type { MemoryMessage, MemoryRecallConfigs, Message, WSMessage, WorkingMemory } from '@dto/message.ts'
import type { AgentFastReply } from '@dto/agent.ts'
import { NewTokenHandler } from './callbacks.ts'
Expand Down

0 comments on commit e554f19

Please sign in to comment.