Sanitize input to the python REPL. Remove whitespace, backtick & python (if llm mistakes python console as terminal) Args: query: The query to sanitize Returns: str: The sanitized query
(query: str)
| 75 | |
| 76 | |
| 77 | def sanitize_input(query: str) -> str: |
| 78 | """Sanitize input to the python REPL. |
| 79 | Remove whitespace, backtick & python (if llm mistakes python console as terminal) |
| 80 | |
| 81 | Args: |
| 82 | query: The query to sanitize |
| 83 | |
| 84 | Returns: |
| 85 | str: The sanitized query |
| 86 | """ |
| 87 | |
| 88 | # Removes `, whitespace & python from start |
| 89 | query = re.sub(r"^(\s|`)*(?i:python)?\s*", "", query) |
| 90 | # Removes whitespace & ` from end |
| 91 | query = re.sub(r"(\s|`)*$", "", query) |
| 92 | return query |
| 93 | |
| 94 | |
| 95 | class PythonInputs(BaseModel): |