mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 03:00:47 +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 { ReadFileTool } 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 ReadFile_Tools implements INode {
|
||||
label: string
|
||||
@@ -41,4 +48,38 @@ class ReadFile_Tools implements INode {
|
||||
}
|
||||
}
|
||||
|
||||
interface ReadFileParams extends ToolParams {
|
||||
store: BaseFileStore
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for reading files from the disk. Extends the StructuredTool
|
||||
* class.
|
||||
*/
|
||||
export class ReadFileTool extends StructuredTool {
|
||||
static lc_name() {
|
||||
return 'ReadFileTool'
|
||||
}
|
||||
|
||||
schema = z.object({
|
||||
file_path: z.string().describe('name of file')
|
||||
})
|
||||
|
||||
name = 'read_file'
|
||||
|
||||
description = 'Read file from disk'
|
||||
|
||||
store: BaseFileStore
|
||||
|
||||
constructor({ store }: ReadFileParams) {
|
||||
super(...arguments)
|
||||
|
||||
this.store = store
|
||||
}
|
||||
|
||||
async _call({ file_path }: z.infer<typeof this.schema>) {
|
||||
return await this.store.readFile(file_path)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: ReadFile_Tools }
|
||||
|
||||
Reference in New Issue
Block a user