Skip to content

Codex model uses example by jupyter notebook or Google Colab. #120

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions examples/codex/Codex_Model_OpenAI.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/imostafizur/Artificial-intelligence/blob/master/Codex_Model_Openai.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "N37PG0nwlkxq"
},
"source": [
"# Install OpenAI Package"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "6iRtOREej7Mx",
"outputId": "ebaab23f-64dc-41d7-8057-47907b621259"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
"Collecting openai\n",
" Downloading openai-0.20.0.tar.gz (42 kB)\n",
"\u001b[K |████████████████████████████████| 42 kB 691 kB/s \n",
"\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
" Preparing wheel metadata ... \u001b[?25l\u001b[?25hdone\n",
"Requirement already satisfied: pandas>=1.2.3 in /usr/local/lib/python3.7/dist-packages (from openai) (1.3.5)\n",
"Collecting pandas-stubs>=1.1.0.11\n",
" Downloading pandas_stubs-1.2.0.62-py3-none-any.whl (163 kB)\n",
"\u001b[K |████████████████████████████████| 163 kB 8.4 MB/s \n",
"\u001b[?25hRequirement already satisfied: requests>=2.20 in /usr/local/lib/python3.7/dist-packages (from openai) (2.23.0)\n",
"Requirement already satisfied: openpyxl>=3.0.7 in /usr/local/lib/python3.7/dist-packages (from openai) (3.0.10)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from openai) (4.64.0)\n",
"Requirement already satisfied: et-xmlfile in /usr/local/lib/python3.7/dist-packages (from openpyxl>=3.0.7->openai) (1.1.0)\n",
"Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.2.3->openai) (2022.1)\n",
"Requirement already satisfied: numpy>=1.17.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.2.3->openai) (1.21.6)\n",
"Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.2.3->openai) (2.8.2)\n",
"Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.7/dist-packages (from pandas-stubs>=1.1.0.11->openai) (4.1.1)\n",
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas>=1.2.3->openai) (1.15.0)\n",
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->openai) (1.24.3)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->openai) (2022.6.15)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->openai) (2.10)\n",
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->openai) (3.0.4)\n",
"Building wheels for collected packages: openai\n",
" Building wheel for openai (PEP 517) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for openai: filename=openai-0.20.0-py3-none-any.whl size=54118 sha256=8fadf9ff82960e0b69fe2bd5e20dce2e3d1037800f098343126781a3d92416b4\n",
" Stored in directory: /root/.cache/pip/wheels/71/8d/9b/e28529ec53123e0279208f99148d4661232120d78cb866839b\n",
"Successfully built openai\n",
"Installing collected packages: pandas-stubs, openai\n",
"Successfully installed openai-0.20.0 pandas-stubs-1.2.0.62\n"
]
}
],
"source": [
"pip install openai"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "oGJHObfulYC0"
},
"source": [
"# The main Program using Codex model of openAI."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hiy700MTkV8K",
"outputId": "6f5c77d4-5776-4355-ded2-29ff55f0329f"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ask me a question: cat\n",
"Mostafizur\n",
"package com.example.demo.controller;\n",
"\n",
"import com.example.demo.model.User;\n",
"import com.example.demo.service.UserService;\n",
"import org.springframework.beans.factory.annotation.Autowired;\n",
"import org.springframework.web.bind.annotation.RequestMapping;\n",
"import org.springframework.web.bind.annotation.RestController;\n",
"\n",
"import java.util.List;\n",
"\n",
"@RestController\n",
"public class UserController {\n",
"\n",
" @Autowired\n",
" private UserService userService;\n",
"\n",
" @RequestMapping(\"/getUser\")\n",
" public List<User> getUser(){\n",
" return userService.getUser();\n",
" }\n",
"}\n"
]
}
],
"source": [
"import os\n",
"import openai\n",
"\n",
"Query = input('Ask me a question: ')\n",
"print('Mostafizur')\n",
"\n",
"openai.api_key = (\"Give your API-key here.\")\n",
"\n",
"response = openai.Completion.create(\n",
" model=\"code-davinci-002\",\n",
" prompt=\"\",\n",
" temperature=0,\n",
" max_tokens=256,\n",
" top_p=1,\n",
" frequency_penalty=0,\n",
" presence_penalty=0\n",
")\n",
"content = response.choices[0].text\n",
"print(content)\n",
"Query = content"
]
}
],
"metadata": {
"colab": {
"authorship_tag": "ABX9TyPlPtzH2ehaaPvQLNrPhKZO",
"include_colab_link": true,
"name": "Codex_Model_Openai.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}