rgbkrk / genai

What if GPT could help you notebook?
BSD 3-Clause "New" or "Revised" License
351 stars 36 forks source link

[Prompt] Suggest how to install when ModuleNotFound #46

Open rgbkrk opened 1 year ago

rgbkrk commented 1 year ago

When a user hits a ModuleNotFound Error, we should send a different kind of prompt and context. Sometimes the user makes a typo, and sometimes they don't have the package installed. genai should be able to figure out between the two.

Missing Package

image

Typo

image

Context

Bonus Context / Optimization As a bonus, if the `pip freeze` output is too big maybe we can use something like levenshtein distance to pull the closest string matches. ```python packages = !pip list --format=freeze packages = [pkg.split('==')[0] for pkg in packages] import Levenshtein def find_closest_strings(target, string_list, n=20): """ Finds the n closest strings in string_list to the target string. """ # Compute the Levenshtein distance between the target string and each string in the list similarity_scores = [(string, Levenshtein.distance(target, string)) for string in string_list] # Sort the list based on the similarity scores similarity_scores.sort(key=lambda x: x[1]) # Return the n closest strings return [x[0] for x in similarity_scores[:n]] find_closest_strings("pndas", packages) ``` Outputs ```python ['pandas', 'conda', 'dask', 'anyio', 'appdirs', 'attrs', 'dx', 'fqdn', 'fs', 'genai', 'geopandas', 'idna', 'jedi', 'Jinja2', 'openai', 'parso', 'partd', 'patsy', 'pip', 'py'] ```

Prompt suggestion