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

Encode code as a list of strings to help GPT and improve human readability #6

Open
rgbkrk opened this issue Apr 10, 2023 · 0 comments

Comments

@rgbkrk
Copy link
Owner

rgbkrk commented Apr 10, 2023

53% of the time* ChatGPT will try to pass the code as a plaintext body (which FastAPI will obviously bomb on):

# First, let's check if we are in a Git repository by running the `git rev-parse --is-inside-work-tree` command.
# If the output is "true", then we are inside a Git repository, and we can proceed with generating the plot.
# If the output is not "true", then we are not in a Git repository, and we cannot generate the plot.

import subprocess

def is_inside_git_repo():
    try:
        output = subprocess.check_output(["git", "rev-parse", "--is-inside-work-tree"], universal_newlines=True)
        return output.strip() == "true"
    except subprocess.CalledProcessError:
        return False

is_inside_git_repo()

rather than the expected payload format

{
  "code": "# First, let's check if we are in a Git repository by running the `git rev-parse --is-inside-work-tree` command.\n# If the output is \"true\", then we are inside a Git repository, and we can proceed with generating the plot.\n# If the output is not \"true\", then we are not in a Git repository, and we cannot generate the plot.\n\nimport subprocess\n\ndef is_inside_git_repo():\n    try:\n        output = subprocess.check_output([\"git\", \"rev-parse\", \"--is-inside-work-tree\"], universal_newlines=True)\n        return output.strip() == \"true\"\n    except subprocess.CalledProcessError:\n        return False\n\nis_inside_git_repo()"
}

This made me think that maybe we should make the format more "notebook-like" by encoding it as a list of strings:

{
    "code": [
        "# First, let's check if we are in a Git repository by running the `git rev-parse --is-inside-work-tree` command.",
        "# If the output is \"true\", then we are inside a Git repository, and we can proceed with generating the plot.",
        "# If the output is not \"true\", then we are not in a Git repository, and we cannot generate the plot.",
        "",
        "import subprocess",
        "",
        "def is_inside_git_repo():",
        "    try:",
        "        output = subprocess.check_output([\"git\", \"rev-parse\", \"--is-inside-work-tree\"], universal_newlines=True)",
        "        return output.strip() == \"true\"",
        "    except subprocess.CalledProcessError:",
        "        return False",
        "",
        "is_inside_git_repo()"
    ]
}

That would also make it easier to read inside of the plugin UI:

image

* I hallucinated this statistic just like GPT-3

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

No branches or pull requests

1 participant