Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved query, print & exception handling in REPL Tool #3215

Closed
wants to merge 3 commits into from

Conversation

svdeepak99
Copy link
Contributor

The following improvements are made to the Python REPL Tool:

  1. Improved the sanitization of query (using regex), by removing python command (since gpt-3.5-turbo sometimes assumes python console as a terminal, and runs python command first which causes error). Also sometimes 1 line python codes contain single backticks.
    (i) Eg of python in query:

Entering new LLMMathChain chain...
1291.25 * 6

```python
print(1291.25 * 6)

```

(ii) Eg of 1 line query with single backtick:
Thought: I have the number of unique Account IDs, but I need to count the number of active accounts Action: python_repl_ast
Action Input: `len(df[df['Status'] == 'Active'])`

  1. Improved the capturing of print by redirecting stdout to output of Python REPL Tool (without cluttering the actual stdout). Also when the return of eval() function is None, then returning stdout (in case code contains a print or info statement).

  2. Made sure the exception format type is returned in all cases, when the exec() function throws an exception.

The following improvements are made to the Python REPL Tool:
1) Improved the sanitization of query (using regex), by removing python command (since gpt-3.5-turbo sometimes assumes python console as a terminal, and runs python command first which causes error). Also sometimes 1 line python codes contain single backticks.
(i) Eg of python in query:
> Entering new LLMMathChain chain...
1291.25 * 6
```python
print(1291.25 * 6)

```
(ii) Eg of 1 line query with single backtick:
Thought:I have the number of unique Account IDs, but I need to count the number of active accounts
Action: python_repl_ast
Action Input: `len(df[df['Status'] == 'Active'])`

2) Improved the capturing of print by redirecting stdout to output of Python REPL Tool (without cluttering the actual stdout).

3) Made sure the exception format type is returned in all cases, when the exec() function throws an exception.
Updated formatting by running the "poetry run black ." command.
@svdeepak99
Copy link
Contributor Author

I corrected the lint formatting by running the "poetry run black ." command and created a new commit.

Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great to add some test cases

@svdeepak99
Copy link
Contributor Author

@hwchase17 I have added 7 new test cases as you asked. I have also rerun the lining commands one by one and fixed the formatting issues. This is my first time adding test cases, so it took a while. If any linting issues persist (none were detected when run locally by me), I request you to fix it if possible.

@svdeepak99
Copy link
Contributor Author

@hwchase17, is there anything blocking this merge?

vowelparrot pushed a commit that referenced this pull request May 22, 2023
Update to pull request #3215

Summary:
1) Improved the sanitization of query (using regex), by removing python
command (since gpt-3.5-turbo sometimes assumes python console as a
terminal, and runs python command first which causes error). Also
sometimes 1 line python codes contain single backticks.
2) Added 7 new test cases.

For more details, view the previous pull request.

---------

Co-authored-by: Deepak S V <svdeepak99@users.noreply.github.com>
@svdeepak99
Copy link
Contributor Author

svdeepak99 commented May 23, 2023

Reopened this PR & merged in #4997

@svdeepak99 svdeepak99 closed this May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants