Bugfix/add regex to csv and airtable agent (#2983)

add regex to csv and airtable agent
This commit is contained in:
Henry Heng 2024-08-09 13:03:07 +01:00 committed by GitHub
parent b833fd8f7d
commit 9da05acc30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View File

@ -166,6 +166,8 @@ json.dumps(my_dict)`
} }
const res = await chain.call(inputs, [loggerHandler, ...callbacks]) const res = await chain.call(inputs, [loggerHandler, ...callbacks])
pythonCode = res?.text 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 // Then run the code using Pyodide
@ -173,6 +175,7 @@ json.dumps(my_dict)`
if (pythonCode) { if (pythonCode) {
try { try {
const code = `import pandas as pd\n${pythonCode}` const code = `import pandas as pd\n${pythonCode}`
// TODO: get print console output
finalResult = await pyodide.runPythonAsync(code) finalResult = await pyodide.runPythonAsync(code)
} catch (error) { } catch (error) {
throw new Error(`Sorry, I'm unable to find answer for question: "${input}" using follwoing code: "${pythonCode}"`) throw new Error(`Sorry, I'm unable to find answer for question: "${input}" using follwoing code: "${pythonCode}"`)

View File

@ -171,6 +171,8 @@ json.dumps(my_dict)`
} }
const res = await chain.call(inputs, [loggerHandler, ...callbacks]) const res = await chain.call(inputs, [loggerHandler, ...callbacks])
pythonCode = res?.text 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 // Then run the code using Pyodide
@ -178,6 +180,7 @@ json.dumps(my_dict)`
if (pythonCode) { if (pythonCode) {
try { try {
const code = `import pandas as pd\n${pythonCode}` const code = `import pandas as pd\n${pythonCode}`
// TODO: get print console output
finalResult = await pyodide.runPythonAsync(code) finalResult = await pyodide.runPythonAsync(code)
} catch (error) { } catch (error) {
throw new Error(`Sorry, I'm unable to find answer for question: "${input}" using following code: "${pythonCode}"`) throw new Error(`Sorry, I'm unable to find answer for question: "${input}" using following code: "${pythonCode}"`)