change latext splitter to code splitter
This commit is contained in:
parent
07fb71d716
commit
1c4880f665
|
|
@ -0,0 +1,128 @@
|
||||||
|
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||||
|
import { getBaseClasses } from '../../../src/utils'
|
||||||
|
import {
|
||||||
|
RecursiveCharacterTextSplitter,
|
||||||
|
RecursiveCharacterTextSplitterParams,
|
||||||
|
SupportedTextSplitterLanguage
|
||||||
|
} from 'langchain/text_splitter'
|
||||||
|
|
||||||
|
class CodeTextSplitter_TextSplitters implements INode {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
description: string
|
||||||
|
type: string
|
||||||
|
icon: string
|
||||||
|
category: string
|
||||||
|
baseClasses: string[]
|
||||||
|
inputs: INodeParams[]
|
||||||
|
constructor() {
|
||||||
|
this.label = 'Code Text Splitter'
|
||||||
|
this.name = 'codeTextSplitter'
|
||||||
|
this.type = 'CodeTextSplitter'
|
||||||
|
this.icon = 'codeTextSplitter.svg'
|
||||||
|
this.category = 'Text Splitters'
|
||||||
|
this.description = `Split documents based on language-specific syntax`
|
||||||
|
this.baseClasses = [this.type, ...getBaseClasses(RecursiveCharacterTextSplitter)]
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'Language',
|
||||||
|
name: 'language',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'cpp',
|
||||||
|
name: 'cpp'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'go',
|
||||||
|
name: 'go'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'java',
|
||||||
|
name: 'java'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'js',
|
||||||
|
name: 'js'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'php',
|
||||||
|
name: 'php'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'proto',
|
||||||
|
name: 'proto'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'python',
|
||||||
|
name: 'python'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'rst',
|
||||||
|
name: 'rst'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'ruby',
|
||||||
|
name: 'ruby'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'rust',
|
||||||
|
name: 'rust'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'scala',
|
||||||
|
name: 'scala'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'swift',
|
||||||
|
name: 'swift'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'markdown',
|
||||||
|
name: 'markdown'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'latex',
|
||||||
|
name: 'latex'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'html',
|
||||||
|
name: 'html'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'sol',
|
||||||
|
name: 'sol'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Chunk Size',
|
||||||
|
name: 'chunkSize',
|
||||||
|
type: 'number',
|
||||||
|
default: 1000,
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Chunk Overlap',
|
||||||
|
name: 'chunkOverlap',
|
||||||
|
type: 'number',
|
||||||
|
optional: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
async init(nodeData: INodeData): Promise<any> {
|
||||||
|
const chunkSize = nodeData.inputs?.chunkSize as string
|
||||||
|
const chunkOverlap = nodeData.inputs?.chunkOverlap as string
|
||||||
|
const language = nodeData.inputs?.language as SupportedTextSplitterLanguage
|
||||||
|
|
||||||
|
const obj = {} as RecursiveCharacterTextSplitterParams
|
||||||
|
|
||||||
|
if (chunkSize) obj.chunkSize = parseInt(chunkSize, 10)
|
||||||
|
if (chunkOverlap) obj.chunkOverlap = parseInt(chunkOverlap, 10)
|
||||||
|
|
||||||
|
const splitter = RecursiveCharacterTextSplitter.fromLanguage(language, obj)
|
||||||
|
|
||||||
|
return splitter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports = { nodeClass: CodeTextSplitter_TextSplitters }
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-code-dots" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||||
|
<path d="M15 12h.01"></path>
|
||||||
|
<path d="M12 12h.01"></path>
|
||||||
|
<path d="M9 12h.01"></path>
|
||||||
|
<path d="M6 19a2 2 0 0 1 -2 -2v-4l-1 -1l1 -1v-4a2 2 0 0 1 2 -2"></path>
|
||||||
|
<path d="M18 19a2 2 0 0 0 2 -2v-4l1 -1l-1 -1v-4a2 2 0 0 0 -2 -2"></path>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 542 B |
|
|
@ -1,52 +0,0 @@
|
||||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
|
||||||
import { getBaseClasses } from '../../../src/utils'
|
|
||||||
import { RecursiveCharacterTextSplitter, RecursiveCharacterTextSplitterParams } from 'langchain/text_splitter'
|
|
||||||
|
|
||||||
class LatexTextSplitter_TextSplitters implements INode {
|
|
||||||
label: string
|
|
||||||
name: string
|
|
||||||
description: string
|
|
||||||
type: string
|
|
||||||
icon: string
|
|
||||||
category: string
|
|
||||||
baseClasses: string[]
|
|
||||||
inputs: INodeParams[]
|
|
||||||
constructor() {
|
|
||||||
this.label = 'Latex Text Splitter'
|
|
||||||
this.name = 'latexTextSplitter'
|
|
||||||
this.type = 'LatexTextSplitter'
|
|
||||||
this.icon = 'latexTextSplitter.svg'
|
|
||||||
this.category = 'Text Splitters'
|
|
||||||
this.description = `Split documents along Latex headings, headlines, enumerations and more.`
|
|
||||||
this.baseClasses = [this.type, ...getBaseClasses(RecursiveCharacterTextSplitter)]
|
|
||||||
this.inputs = [
|
|
||||||
{
|
|
||||||
label: 'Chunk Size',
|
|
||||||
name: 'chunkSize',
|
|
||||||
type: 'number',
|
|
||||||
default: 1000,
|
|
||||||
optional: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Chunk Overlap',
|
|
||||||
name: 'chunkOverlap',
|
|
||||||
type: 'number',
|
|
||||||
optional: true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
async init(nodeData: INodeData): Promise<any> {
|
|
||||||
const chunkSize = nodeData.inputs?.chunkSize as string
|
|
||||||
const chunkOverlap = nodeData.inputs?.chunkOverlap as string
|
|
||||||
|
|
||||||
const obj = {} as RecursiveCharacterTextSplitterParams
|
|
||||||
|
|
||||||
if (chunkSize) obj.chunkSize = parseInt(chunkSize, 10)
|
|
||||||
if (chunkOverlap) obj.chunkOverlap = parseInt(chunkOverlap, 10)
|
|
||||||
|
|
||||||
const splitter = RecursiveCharacterTextSplitter.fromLanguage('latex', obj)
|
|
||||||
|
|
||||||
return splitter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
module.exports = { nodeClass: LatexTextSplitter_TextSplitters }
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-markdown" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
|
||||||
<path d="M3 5m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z"></path>
|
|
||||||
<path d="M7 15v-6l2 2l2 -2v6"></path>
|
|
||||||
<path d="M14 13l2 2l2 -2m-2 2v-6"></path>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 483 B |
Loading…
Reference in New Issue