mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-25 13:01:00 +03:00
upgrade langchain version 0.1.0
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
import { z } from 'zod'
|
||||
import { StructuredTool, ToolParams } from '@langchain/core/tools'
|
||||
import { Serializable } from '@langchain/core/load/serializable'
|
||||
import { NodeFileStore } from 'langchain/stores/file/node'
|
||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses } from '../../../src/utils'
|
||||
import { WriteFileTool } from 'langchain/tools'
|
||||
import { NodeFileStore } from 'langchain/stores/file/node'
|
||||
|
||||
abstract class BaseFileStore extends Serializable {
|
||||
abstract readFile(path: string): Promise<string>
|
||||
abstract writeFile(path: string, contents: string): Promise<void>
|
||||
}
|
||||
|
||||
class WriteFile_Tools implements INode {
|
||||
label: string
|
||||
@@ -41,4 +48,40 @@ class WriteFile_Tools implements INode {
|
||||
}
|
||||
}
|
||||
|
||||
interface WriteFileParams extends ToolParams {
|
||||
store: BaseFileStore
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for writing data to files on the disk. Extends the StructuredTool
|
||||
* class.
|
||||
*/
|
||||
export class WriteFileTool extends StructuredTool {
|
||||
static lc_name() {
|
||||
return 'WriteFileTool'
|
||||
}
|
||||
|
||||
schema = z.object({
|
||||
file_path: z.string().describe('name of file'),
|
||||
text: z.string().describe('text to write to file')
|
||||
})
|
||||
|
||||
name = 'write_file'
|
||||
|
||||
description = 'Write file from disk'
|
||||
|
||||
store: BaseFileStore
|
||||
|
||||
constructor({ store, ...rest }: WriteFileParams) {
|
||||
super(rest)
|
||||
|
||||
this.store = store
|
||||
}
|
||||
|
||||
async _call({ file_path, text }: z.infer<typeof this.schema>) {
|
||||
await this.store.writeFile(file_path, text)
|
||||
return 'File written to successfully.'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: WriteFile_Tools }
|
||||
|
||||
Reference in New Issue
Block a user