GenAIIPython 的生成式 AI 工具
GenAI 是一個(gè) IPython 擴(kuò)展,可以幫助快速診斷錯(cuò)誤和異常。
%pip install genai
%load_ext genai
通過從IPython中提取上下文,將其與OpenAI的大型語言模型混合在一起,并賦予你在所有Jupyter環(huán)境中生成代碼單元并在發(fā)生異常后獲得建議的能力,包括 IPython、JupyterLab、Jupyter Notebook和Noteable。
在 notebook 啟動(dòng)時(shí),genai 注冊為自定義 IPython 異常處理程序。當(dāng)用戶遇到錯(cuò)誤時(shí),genai 會(huì)自動(dòng)將錯(cuò)誤發(fā)送到 OpenAI 的 GPT-3.5-turbo 模型。
通過將 OpenAI 的新 ChatCompletion 端點(diǎn)與 IPython 的執(zhí)行上下文連接起來,genai 可以推薦量身定制的建議來解鎖用戶。
在 notebook 內(nèi)部工作自然是用戶與系統(tǒng)之間的對話。交互式計(jì)算的這種對話方面非常適合邀請 GPT 加入他們的對話。
特性:
-
%%assistmagic command 從自然語言生成代碼 - 自定義異常建議
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'
示例:
In [1]: %load_ext genai In [2]: %%assist ...: ...: # Pull census data ...: 'What would a data analyst do? ??' In [3]: # generated with %%assist ...: # Pull census data ...: # To pull census data we can use the `requests` library to send a GET request to the appropriate API endpoint. ...: # First, import the requests module ...: import requests ...: ...: # Define the URL endpoint to the Census API ...: url = "https://api.census.gov/data/2019/pep/population" ...: ...: # Define the parameters needed for the API request, such as dataset and variables requested ...: params = { ...: "get": "POP", ...: "for": "state:*", ...: } ...: ...: # Send a GET request to the Census API endpoint with the parameters ...: response = requests.get(url, params=params) ...: ...: # Access the response content ...: content = response.content ...: ...: # The Census data is now stored in the `content` variable and can be processed or saved elsewhere. The user can modify the `params` variable to request different data or specify a different API endpoint. In [6]: content Out[6]: b'[["POP","state"],\n["4903185","01"],\n["731545","02"],\n["7278717","04"],\n["3017804","05"],\n["39512223","06"],\n["5758736","08"],\n["973764","10"],\n["705749","11"],\n["3565287","09"],\n["21477737","12"],\n["10617423","13"],\n["1787065","16"],\n["1415872","15"],\n["12671821","17"],\n["6732219","18"],\n["3155070","19"],\n["2913314","20"],\n["4467673","21"],\n["4648794","22"],\n["1344212","23"],\n["6045680","24"],\n["6892503","25"],\n["9986857","26"],\n["5639632","27"],\n["2976149","28"],\n["6137428","29"],\n["1068778","30"],\n["1934408","31"],\n["3080156","32"],\n["1359711","33"],\n["8882190","34"],\n["2096829","35"],\n["19453561","36"],\n["10488084","37"],\n["762062","38"],\n["11689100","39"],\n["3956971","40"],\n["4217737","41"],\n["12801989","42"],\n["1059361","44"],\n["5148714","45"],\n["884659","46"],\n["6829174","47"],\n["28995881","48"],\n["623989","50"],\n["3205958","49"],\n["8535519","51"],\n["7614893","53"],\n["1792147","54"],\n["5822434","55"],\n["578759","56"],\n["3193694","72"]]'
評論
圖片
表情
