[Install](#installation) | [License](./LICENSE) | [Code of Conduct](./CODE_OF_CONDUCT.md) | [Contributing](./CONTRIBUTING.md)
# GenAI: generative AI tooling for IPython
π¦Ύ Get GPT help with code, SQL queries, DataFrames, Exceptions and more in IPython.
π Supports all Jupyter environments, including IPython, JupyterLab, Jupyter Notebook, and Noteable.
TL;DR Get started now
```
%pip install genai
%load_ext genai
```
## Genai In Action
![Genai making a suggestion followed by running suggested code](https://user-images.githubusercontent.com/836375/225177905-17cfb526-60f8-486d-b468-60a6a01db02e.gif)
- [Blog Post](https://noteable.io/blog/introducing-genai/)
- [Example Notebook](https://app.noteable.io/f/1605d16d-f5d3-4099-8fec-2ca727075b3b/Introducing-Genai.ipynb)
<!-- --8<-- [start:intro] -->
## Introduction
We've taken the context from IPython, mixed it with OpenAI's Large Language Models, and are bringing you a more informed notebook experience that works in all Jupyter environments, including IPython, JupyterLab, Jupyter Notebook, and Noteable. π¦Ύπ
<!-- --8<-- [end:intro] -->
<!-- --8<-- [start:requirements] -->
## Requirements
Python 3.8+
<!-- --8<-- [end:requirements] -->
<!-- --8<-- [start:install] -->
## Installation
### Poetry
```shell
poetry add genai
```
### Pip
```shell
pip install genai
```
<!-- --8<-- [end:install] -->
<!-- --8<-- [start:start] -->
## Loading the IPython extension
Make sure to set the `OPENAI_API_KEY` environment variable first before using it in IPython or your [preferred notebook platform of choice](https://noteable.io/).
```
%load_ext genai
```
## Features
- `%%assist` magic command to generate code from natural language
- Custom exception suggestions
### Custom Exception Suggestions
```python
In [1]: %load_ext genai
In [2]: import pandas as pd
In [3]: df = pd.DataFrame(dict(col1=['a', 'b', 'c']), index=['first', 'second', 'third'])
In [4]: df.sort_values()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[4], line 1
----> 1 df.sort_values()
File ~/.pyenv/versions/3.9.9/lib/python3.9/site-packages/pandas/util/_decorators.py:331, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
325 if len(args) > num_allow_args:
326 warnings.warn(
327 msg.format(arguments=_format_argument_list(allow_args)),
328 FutureWarning,
329 stacklevel=find_stack_level(),
330 )
--> 331 return func(*args, **kwargs)
TypeError: sort_values() missing 1 required positional argument: 'by'
```
#### π‘ Suggestion
The error message is indicating that the `sort_values()` method of a pandas dataframe is missing a required positional argument.
The `sort_values()` method requires you to pass a column name or list of column names as the `by` argument. This is used to determine how the sorting will be performed.
Here's an example:
```python
import pandas as pd
df = pd.DataFrame({
'Name': ['Alice', 'Bob', 'Carol', 'David', 'Eva'],
'Age': [32, 24, 28, 35, 29],
'Salary': [60000, 40000, 35000, 80000, 45000]
})
# sort by Age column:
df_sorted = df.sort_values(by='Age')
print(df_sorted)
```
In this example, the `by` argument is set to `'Age'`, which sorts the dataframe by age in ascending order. Note that you can also pass a list of column names if you want to sort by multiple columns.
## Example
````python
In [1]: %load_ext genai
In [2]: %%assist
...:
...: Can you explain this query to me so I can be sure we're doing the right things?
...:
...: ```sql
...: SELECT
...: COUNT(*) AS num_downloads,
...: DATE_TRUNC(DATE(timestamp), DAY) AS day
...: FROM `bigquery-public-data.pypi.file_downloads`
...: WHERE
...: file.project = 'genai'
...: -- Only query the last 6 months of history
...: AND DATE(timestamp)
...: BETWEEN DATE_TRUNC(DATE_SUB(CURRENT_DATE(), INTERVAL 6 MONTH), MONTH)
...: AND CURRENT_DATE()
...: GROUP BY day
...: ORDER BY day DESC
````
```markdown
"This is a SQL query that counts the number of downloads for the 'genai' project on the Python Package Index (PyPI) over the last 6 months, grouped by day. The query selects the count and the date, truncating the date to the day level so that it's easier to read.
Here is a breakdown of each part of the query:
- `SELECT COUNT(*) AS num_downloads, DATE_TRUNC(DATE(timestamp), DAY) AS day`: This selects the count of the number of rows matched by the query as `num_downloads`, and the date truncated to the day level as `day`.
- `FROM `bigquery-public-data.pypi.file_downloads``: This specifies the table to query from.
- `WHERE file.project = 'genai'`: This filters the rows by only including downloads for the 'genai' project.
- `AND DATE(timestamp) BETWEEN DATE_TRUNC(DATE_SUB(CURRENT_DATE(), INTERVAL 6 MONTH), MONTH) AND CURRENT_DATE()`: This filters the rows by only including downloads from the last 6 months. The `DATE_SUB` function subtracts 6 months from the current date (`CURRENT_DATE()`), `DATE_TRUNC` truncates the result to be the start of the month and `DATE` converts the timestamp column to a date so the `BETWEEN` condition can filter rows between the start of 6 months ago and "today."
- `GROUP BY day`: This groups the rows by day so that the counts are aggregated by date.
- `ORDER BY day DESC`: This orders the rows so that the most recent date appears first in the result."
```
<!-- --8<-- [end:start] -->
Raw data
{
"_id": null,
"home_page": "",
"name": "genai",
"maintainer": "Kyle Kelley",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "rgbkrk@gmail.com",
"keywords": "notebook,api,noteable,chatgpt,gpt3,openai,ipython,traceback,assist,llm",
"author": "Kyle Kelley",
"author_email": "rgbkrk@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/be/28/ff0de84f38a579b6db12ef003fcc710d4fcc49ad6534fdb7d74d4959d751/genai-2.1.0.tar.gz",
"platform": null,
"description": "[Install](#installation) | [License](./LICENSE) | [Code of Conduct](./CODE_OF_CONDUCT.md) | [Contributing](./CONTRIBUTING.md)\n\n# GenAI: generative AI tooling for IPython\n\n\ud83e\uddbe Get GPT help with code, SQL queries, DataFrames, Exceptions and more in IPython.\n\n\ud83c\udf0d Supports all Jupyter environments, including IPython, JupyterLab, Jupyter Notebook, and Noteable.\n\nTL;DR Get started now\n\n```\n%pip install genai\n%load_ext genai\n```\n\n## Genai In Action\n\n![Genai making a suggestion followed by running suggested code](https://user-images.githubusercontent.com/836375/225177905-17cfb526-60f8-486d-b468-60a6a01db02e.gif)\n\n- [Blog Post](https://noteable.io/blog/introducing-genai/)\n- [Example Notebook](https://app.noteable.io/f/1605d16d-f5d3-4099-8fec-2ca727075b3b/Introducing-Genai.ipynb)\n\n<!-- --8<-- [start:intro] -->\n\n## Introduction\n\nWe've taken the context from IPython, mixed it with OpenAI's Large Language Models, and are bringing you a more informed notebook experience that works in all Jupyter environments, including IPython, JupyterLab, Jupyter Notebook, and Noteable. \ud83e\uddbe\ud83c\udf0f\n\n<!-- --8<-- [end:intro] -->\n\n<!-- --8<-- [start:requirements] -->\n\n## Requirements\n\nPython 3.8+\n\n<!-- --8<-- [end:requirements] -->\n\n<!-- --8<-- [start:install] -->\n\n## Installation\n\n### Poetry\n\n```shell\npoetry add genai\n```\n\n### Pip\n\n```shell\npip install genai\n```\n\n<!-- --8<-- [end:install] -->\n\n<!-- --8<-- [start:start] -->\n\n## Loading the IPython extension\n\nMake sure to set the `OPENAI_API_KEY` environment variable first before using it in IPython or your [preferred notebook platform of choice](https://noteable.io/).\n\n```\n%load_ext genai\n```\n\n## Features\n\n- `%%assist` magic command to generate code from natural language\n- Custom exception suggestions\n\n### Custom Exception Suggestions\n\n```python\nIn [1]: %load_ext genai\n\nIn [2]: import pandas as pd\n\nIn [3]: df = pd.DataFrame(dict(col1=['a', 'b', 'c']), index=['first', 'second', 'third'])\n\nIn [4]: df.sort_values()\n---------------------------------------------------------------------------\nTypeError Traceback (most recent call last)\nCell In[4], line 1\n----> 1 df.sort_values()\n\nFile ~/.pyenv/versions/3.9.9/lib/python3.9/site-packages/pandas/util/_decorators.py:331, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)\n 325 if len(args) > num_allow_args:\n 326 warnings.warn(\n 327 msg.format(arguments=_format_argument_list(allow_args)),\n 328 FutureWarning,\n 329 stacklevel=find_stack_level(),\n 330 )\n--> 331 return func(*args, **kwargs)\n\nTypeError: sort_values() missing 1 required positional argument: 'by'\n```\n\n#### \ud83d\udca1 Suggestion\n\nThe error message is indicating that the `sort_values()` method of a pandas dataframe is missing a required positional argument.\n\nThe `sort_values()` method requires you to pass a column name or list of column names as the `by` argument. This is used to determine how the sorting will be performed.\n\nHere's an example:\n\n```python\nimport pandas as pd\n\ndf = pd.DataFrame({\n 'Name': ['Alice', 'Bob', 'Carol', 'David', 'Eva'],\n 'Age': [32, 24, 28, 35, 29],\n 'Salary': [60000, 40000, 35000, 80000, 45000]\n})\n\n# sort by Age column:\ndf_sorted = df.sort_values(by='Age')\nprint(df_sorted)\n```\n\nIn this example, the `by` argument is set to `'Age'`, which sorts the dataframe by age in ascending order. Note that you can also pass a list of column names if you want to sort by multiple columns.\n\n## Example\n\n````python\nIn [1]: %load_ext genai\n\nIn [2]: %%assist\n ...:\n ...: Can you explain this query to me so I can be sure we're doing the right things?\n ...:\n ...: ```sql\n ...: SELECT\n ...: COUNT(*) AS num_downloads,\n ...: DATE_TRUNC(DATE(timestamp), DAY) AS day\n ...: FROM `bigquery-public-data.pypi.file_downloads`\n ...: WHERE\n ...: file.project = 'genai'\n ...: -- Only query the last 6 months of history\n ...: AND DATE(timestamp)\n ...: BETWEEN DATE_TRUNC(DATE_SUB(CURRENT_DATE(), INTERVAL 6 MONTH), MONTH)\n ...: AND CURRENT_DATE()\n ...: GROUP BY day\n ...: ORDER BY day DESC\n````\n\n```markdown\n\"This is a SQL query that counts the number of downloads for the 'genai' project on the Python Package Index (PyPI) over the last 6 months, grouped by day. The query selects the count and the date, truncating the date to the day level so that it's easier to read.\n\nHere is a breakdown of each part of the query:\n\n- `SELECT COUNT(*) AS num_downloads, DATE_TRUNC(DATE(timestamp), DAY) AS day`: This selects the count of the number of rows matched by the query as `num_downloads`, and the date truncated to the day level as `day`.\n- `FROM `bigquery-public-data.pypi.file_downloads``: This specifies the table to query from.\n- `WHERE file.project = 'genai'`: This filters the rows by only including downloads for the 'genai' project.\n- `AND DATE(timestamp) BETWEEN DATE_TRUNC(DATE_SUB(CURRENT_DATE(), INTERVAL 6 MONTH), MONTH) AND CURRENT_DATE()`: This filters the rows by only including downloads from the last 6 months. The `DATE_SUB` function subtracts 6 months from the current date (`CURRENT_DATE()`), `DATE_TRUNC` truncates the result to be the start of the month and `DATE` converts the timestamp column to a date so the `BETWEEN` condition can filter rows between the start of 6 months ago and \"today.\"\n- `GROUP BY day`: This groups the rows by day so that the counts are aggregated by date.\n- `ORDER BY day DESC`: This orders the rows so that the most recent date appears first in the result.\"\n```\n\n<!-- --8<-- [end:start] -->\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "Generative AI for IPython (enhance your code cells)",
"version": "2.1.0",
"project_urls": null,
"split_keywords": [
"notebook",
"api",
"noteable",
"chatgpt",
"gpt3",
"openai",
"ipython",
"traceback",
"assist",
"llm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "dec72a79b24610e15ecc6d7c421cb7a6701decc0402011099b08659a3a76196a",
"md5": "a965b678f111556ad099742f20069482",
"sha256": "9ae1fc501b0425ad583962b09c1af77b6c04328ba8fbe151954a78f1a180d37e"
},
"downloads": -1,
"filename": "genai-2.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a965b678f111556ad099742f20069482",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 16046,
"upload_time": "2023-07-21T01:56:23",
"upload_time_iso_8601": "2023-07-21T01:56:23.381452Z",
"url": "https://files.pythonhosted.org/packages/de/c7/2a79b24610e15ecc6d7c421cb7a6701decc0402011099b08659a3a76196a/genai-2.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "be28ff0de84f38a579b6db12ef003fcc710d4fcc49ad6534fdb7d74d4959d751",
"md5": "6c52365854c7890e86ab42573ef745f3",
"sha256": "71abe894703d2a097148fd08152bedd3f320598536317dc0cd9bee69e9f87314"
},
"downloads": -1,
"filename": "genai-2.1.0.tar.gz",
"has_sig": false,
"md5_digest": "6c52365854c7890e86ab42573ef745f3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 16255,
"upload_time": "2023-07-21T01:56:25",
"upload_time_iso_8601": "2023-07-21T01:56:25.021168Z",
"url": "https://files.pythonhosted.org/packages/be/28/ff0de84f38a579b6db12ef003fcc710d4fcc49ad6534fdb7d74d4959d751/genai-2.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-21 01:56:25",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "genai"
}