mirror of
https://github.com/Mintplex-Labs/abitat.git
synced 2026-07-01 10:05:27 -04:00
file history plugin
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'aibitat': patch
|
||||
---
|
||||
|
||||
`fileHistory` plugin
|
||||
@@ -1,3 +1,5 @@
|
||||
history
|
||||
|
||||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
# Logs
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {AIbitat} from '../src'
|
||||
import {cli, experimental_webBrowsing} from '../src/plugins'
|
||||
import {cli, experimental_webBrowsing, fileHistory} from '../src/plugins'
|
||||
|
||||
const aibitat = new AIbitat({
|
||||
nodes: {},
|
||||
@@ -20,9 +20,10 @@ const aibitat = new AIbitat({
|
||||
})
|
||||
.use(cli())
|
||||
.use(experimental_webBrowsing())
|
||||
.use(fileHistory())
|
||||
|
||||
await aibitat.start({
|
||||
from: 'client',
|
||||
to: '#content-creators',
|
||||
to: 'the-researcher',
|
||||
content: `Write a blog post about in Brazilian Portuguese to be posted on Medium.`,
|
||||
})
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
import {AIbitatPlugin} from '..'
|
||||
|
||||
export function fileHistory({
|
||||
filename = `history/chat-history-${new Date().toISOString()}.json`,
|
||||
}: {
|
||||
/**
|
||||
* The location of the file to save the chat history
|
||||
* @default `history/chat-history-${new Date().toISOString()}.json`
|
||||
*/
|
||||
filename?: string
|
||||
} = {}) {
|
||||
return {
|
||||
name: 'file-history-plugin',
|
||||
setup(aibitat) {
|
||||
const folderPath = path.dirname(filename)
|
||||
// get path from filename
|
||||
if (folderPath) {
|
||||
fs.mkdirSync(folderPath, {recursive: true})
|
||||
}
|
||||
|
||||
aibitat.onMessage(() => {
|
||||
const content = JSON.stringify(aibitat.chats, null, 2)
|
||||
if (typeof Bun !== 'undefined') {
|
||||
return Bun.write(filename, content)
|
||||
}
|
||||
|
||||
fs.writeFile(filename, content, err => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
} as AIbitatPlugin
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './cli.ts'
|
||||
export * from './web-browsing.ts'
|
||||
export * from './file-history.ts'
|
||||
|
||||
Reference in New Issue
Block a user