Skip to content

Commit

Permalink
Bugfix/add regex to csv and airtable agent (FlowiseAI#2983)
Browse files Browse the repository at this point in the history
add regex to csv and airtable agent
  • Loading branch information
HenryHengZJ authored and patrickalvesexperian committed Sep 3, 2024
1 parent 1107c17 commit 0694131
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,16 @@ json.dumps(my_dict)`
}
const res = await chain.call(inputs, [loggerHandler, ...callbacks])
pythonCode = res?.text
// Regex to get rid of markdown code blocks syntax
pythonCode = pythonCode.replace(/^```[a-z]+\n|\n```$/gm, '')
}

// Then run the code using Pyodide
let finalResult = ''
if (pythonCode) {
try {
const code = `import pandas as pd\n${pythonCode}`
// TODO: get print console output
finalResult = await pyodide.runPythonAsync(code)
} catch (error) {
throw new Error(`Sorry, I'm unable to find answer for question: "${input}" using follwoing code: "${pythonCode}"`)
Expand Down
3 changes: 3 additions & 0 deletions packages/components/nodes/agents/CSVAgent/CSVAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,16 @@ json.dumps(my_dict)`
}
const res = await chain.call(inputs, [loggerHandler, ...callbacks])
pythonCode = res?.text
// Regex to get rid of markdown code blocks syntax
pythonCode = pythonCode.replace(/^```[a-z]+\n|\n```$/gm, '')
}

// Then run the code using Pyodide
let finalResult = ''
if (pythonCode) {
try {
const code = `import pandas as pd\n${pythonCode}`
// TODO: get print console output
finalResult = await pyodide.runPythonAsync(code)
} catch (error) {
throw new Error(`Sorry, I'm unable to find answer for question: "${input}" using following code: "${pythonCode}"`)
Expand Down

0 comments on commit 0694131

Please sign in to comment.