mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-03 12:07:36 +00:00
langchain : text_splitters Added PowerShell (#24582)
- **Description:** Added PowerShell support for text splitters language include docs relevant update - **Issue:** None - **Dependencies:** None --------- Co-authored-by: tzitman <tamir.zitman@intel.com> Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
@@ -1974,3 +1974,56 @@ def test_split_json_many_calls() -> None:
|
||||
|
||||
assert chunk0 == chunk0_output
|
||||
assert chunk1 == chunk1_output
|
||||
|
||||
|
||||
def test_powershell_code_splitter_short_code() -> None:
|
||||
splitter = RecursiveCharacterTextSplitter.from_language(
|
||||
Language.POWERSHELL, chunk_size=60, chunk_overlap=0
|
||||
)
|
||||
code = """
|
||||
# Check if a file exists
|
||||
$filePath = "C:\\temp\\file.txt"
|
||||
if (Test-Path $filePath) {
|
||||
# File exists
|
||||
} else {
|
||||
# File does not exist
|
||||
}
|
||||
"""
|
||||
|
||||
chunks = splitter.split_text(code)
|
||||
assert chunks == [
|
||||
'# Check if a file exists\n$filePath = "C:\\temp\\file.txt"',
|
||||
"if (Test-Path $filePath) {\n # File exists\n} else {",
|
||||
"# File does not exist\n}",
|
||||
]
|
||||
|
||||
|
||||
def test_powershell_code_splitter_longer_code() -> None:
|
||||
splitter = RecursiveCharacterTextSplitter.from_language(
|
||||
Language.POWERSHELL, chunk_size=60, chunk_overlap=0
|
||||
)
|
||||
code = """
|
||||
# Get a list of all processes and export to CSV
|
||||
$processes = Get-Process
|
||||
$processes | Export-Csv -Path "C:\\temp\\processes.csv" -NoTypeInformation
|
||||
|
||||
# Read the CSV file and display its content
|
||||
$csvContent = Import-Csv -Path "C:\\temp\\processes.csv"
|
||||
$csvContent | ForEach-Object {
|
||||
$_.ProcessName
|
||||
}
|
||||
|
||||
# End of script
|
||||
"""
|
||||
|
||||
chunks = splitter.split_text(code)
|
||||
assert chunks == [
|
||||
"# Get a list of all processes and export to CSV",
|
||||
"$processes = Get-Process",
|
||||
'$processes | Export-Csv -Path "C:\\temp\\processes.csv"',
|
||||
"-NoTypeInformation",
|
||||
"# Read the CSV file and display its content",
|
||||
'$csvContent = Import-Csv -Path "C:\\temp\\processes.csv"',
|
||||
"$csvContent | ForEach-Object {\n $_.ProcessName\n}",
|
||||
"# End of script",
|
||||
]
|
||||
|
Reference in New Issue
Block a user