{"id":13594511,"url":"https://github.com/shreyashankar/gpt3-sandbox","last_synced_at":"2025-04-13T18:34:36.158Z","repository":{"id":37853322,"uuid":"280807273","full_name":"shreyashankar/gpt3-sandbox","owner":"shreyashankar","description":"The goal of this project is to enable users to create cool web demos using the newly released OpenAI GPT-3 API with just a few lines of Python.","archived":false,"fork":false,"pushed_at":"2023-10-04T09:33:54.000Z","size":5804,"stargazers_count":2893,"open_issues_count":23,"forks_count":873,"subscribers_count":106,"default_branch":"master","last_synced_at":"2025-04-06T15:07:16.944Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shreyashankar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-07-19T06:33:49.000Z","updated_at":"2025-04-03T23:19:22.000Z","dependencies_parsed_at":"2023-02-04T21:15:30.549Z","dependency_job_id":"382c42e6-fc20-46bf-b796-40b3b6dfe8a3","html_url":"https://github.com/shreyashankar/gpt3-sandbox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shreyashankar%2Fgpt3-sandbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shreyashankar%2Fgpt3-sandbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shreyashankar%2Fgpt3-sandbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shreyashankar%2Fgpt3-sandbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shreyashankar","download_url":"https://codeload.github.com/shreyashankar/gpt3-sandbox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248761074,"owners_count":21157483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:34.817Z","updated_at":"2025-04-13T18:34:36.136Z","avatar_url":"https://github.com/shreyashankar.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","A01_文本生成_文本对话","📦 Legacy \u0026 Inactive Projects"],"sub_categories":["大语言对话模型及数据"],"readme":"# GPT-3 Sandbox: Turn your ideas into demos in a matter of minutes\n\nInitial release date: 19 July 2020\n\nNote that this repository is not under any active development; just basic maintenance.\n\n## Description\n\nThe goal of this project is to enable users to create cool web demos using the newly released OpenAI GPT-3 API **with just a few lines of Python.** \n\nThis project addresses the following issues:\n\n1. Automatically formatting a user's inputs and outputs so that the model can effectively pattern-match\n2. Creating a web app for a user to deploy locally and showcase their idea\n\nHere's a quick example of priming GPT to convert English to LaTeX:\n\n```\n# Construct GPT object and show some examples\ngpt = GPT(engine=\"davinci\",\n          temperature=0.5,\n          max_tokens=100)\ngpt.add_example(Example('Two plus two equals four', '2 + 2 = 4'))\ngpt.add_example(Example('The integral from zero to infinity', '\\\\int_0^{\\\\infty}'))\ngpt.add_example(Example('The gradient of x squared plus two times x with respect to x', '\\\\nabla_x x^2 + 2x'))\ngpt.add_example(Example('The log of two times x', '\\\\log{2x}'))\ngpt.add_example(Example('x squared plus y squared plus equals z squared', 'x^2 + y^2 = z^2'))\n\n# Define UI configuration\nconfig = UIConfig(description=\"Text to equation\",\n                  button_text=\"Translate\",\n                  placeholder=\"x squared plus 2 times x\")\n\ndemo_web_app(gpt, config)\n```\n\nRunning this code as a python script would automatically launch a web app for you to test new inputs and outputs with. There are already 3 example scripts in the `examples` directory.\n\nYou can also prime GPT from the UI. for that, pass `show_example_form=True` to `UIConfig` along with other parameters.\n\nTechnical details: the backend is in Flask, and the frontend is in React. Note that this repository is currently not intended for production use.\n\n## Background\n\nGPT-3 ([Brown et al.](https://arxiv.org/abs/2005.14165)) is OpenAI's latest language model. It incrementally builds on model architectures designed in [previous](https://arxiv.org/abs/1706.03762) [research](https://arxiv.org/abs/1810.04805) studies, but its key advance is that it's extremely good at \"few-shot\" learning. There's a [lot](https://twitter.com/sharifshameem/status/1282676454690451457) [it](https://twitter.com/jsngr/status/1284511080715362304?s=20) [can](https://twitter.com/paraschopra/status/1284801028676653060?s=20) [do](https://www.gwern.net/GPT-3), but one of the biggest pain points is in \"priming,\" or seeding, the model with some inputs such that the model can intelligently create new outputs. Many people have ideas for GPT-3 but struggle to make them work, since priming is a new paradigm of machine learning. Additionally, it takes a nontrivial amount of web development to spin up a demo to showcase a cool idea. We built this project to make our own idea generation easier to experiment with.\n\nThis [developer toolkit](https://www.notion.so/API-Developer-Toolkit-49595ed6ffcd413e93ebff10d7e70fe7) has some great resources for those experimenting with the API, including sample prompts.\n\n## Requirements\n\nCoding-wise, you only need Python. But for the app to run, you will need:\n\n* API key from the OpenAI API beta invite\n* Python 3\n* `yarn`\n* Node 16\n\nInstructions to install Python 3 are [here](https://realpython.com/installing-python/), instructions to install `yarn` are [here](https://classic.yarnpkg.com/en/docs/install/#mac-stable) and we recommend using nvm to install (and manage) Node (instructions are [here](https://github.com/nvm-sh/nvm)).\n\n## Setup\n\nFirst, clone or fork this repository. Then to set up your virtual environment, do the following:\n\n1. Create a virtual environment in the root directory: `python -m venv $ENV_NAME`\n2. Activate the virtual environment: ` source $ENV_NAME/bin/activate` (for MacOS, Unix, or Linux users) or ` .\\ENV_NAME\\Scripts\\activate` (for Windows users)\n3. Install requirements: `pip install -r api/requirements.txt`\n4. To add your secret key: create a file anywhere on your computer called `openai.cfg` with the contents `OPENAI_KEY=$YOUR_SECRET_KEY`, where `$YOUR_SECRET_KEY` looks something like `'sk-somerandomcharacters'` (including quotes). If you are unsure what your secret key is, navigate to the [API Keys page](https://beta.openai.com/account/api-keys) and click \"Copy\" next to a token displayed under \"Secret Key\". If there is none, click on \"Create new secret key\" and then copy it.\n5. Set your environment variable to read the secret key: run `export OPENAI_CONFIG=/path/to/config/openai.cfg` (for MacOS, Unix, or Linux users) or `set OPENAI_CONFIG=/path/to/config/openai.cfg` (for Windows users)\n6. Run `yarn install` in the root directory\n\nIf you are a Windows user, to run the demos, you will need to modify the following line inside `api/demo_web_app.py`:\n`subprocess.Popen([\"yarn\", \"start\"])` to `subprocess.Popen([\"yarn\", \"start\"], shell=True)`.\n\nTo verify that your environment is set up properly, run one of the 3 scripts in the `examples` directory:\n`python examples/run_latex_app.py`.\n\nA new tab should pop up in your browser, and you should be able to interact with the UI! To stop this app, run ctrl-c or command-c in your terminal.\n\nTo create your own example, check out the [\"getting started\" docs](https://github.com/shreyashankar/gpt3-sandbox/blob/master/docs/getting-started.md).\n\n## Interactive Priming\n\nThe real power of GPT-3 is in its ability to learn to specialize to tasks given a few examples. However, priming can at times be more of an art than a science. Using the GPT and Example classes, you can easily experiment with different priming examples and immediately see their GPT on GPT-3's performance. Below is an example showing it improve incrementally at translating English to LaTeX as we feed it more examples in the python interpreter: \n\n```\n\u003e\u003e\u003e from api import GPT, Example, set_openai_key\n\u003e\u003e\u003e gpt = GPT()\n\u003e\u003e\u003e set_openai_key(key)\n\u003e\u003e\u003e prompt = \"integral from a to b of f of x\"\n\u003e\u003e\u003e print(gpt.get_top_reply(prompt))\noutput: integral from a to be of f of x\n\n\u003e\u003e\u003e gpt.add_example(Example(\"Two plus two equals four\", \"2 + 2 = 4\"))\n\u003e\u003e\u003e print(gpt.get_top_reply(prompt))\noutput:\n\n\u003e\u003e\u003e gpt.add_example(Example('The integral from zero to infinity', '\\\\int_0^{\\\\infty}'))\n\u003e\u003e\u003e print(gpt.get_top_reply(prompt))\noutput: \\int_a^b f(x) dx\n\n``` \n\n## Contributions\n\nWe actively encourage people to contribute by adding their own examples or even adding functionalities to the modules. Please make a pull request if you would like to add something, or create an issue if you have a question. We will update the contributors list on a regular basis.\n\nPlease *do not* leave your secret key in plaintext in your pull request!\n\n## Authors\n\nThe following authors have committed 20 lines or more (ordered according to the Github contributors page):\n\n* Shreya Shankar\n* Bora Uyumazturk\n* Devin Stein\n* Gulan\n* Michael Lavelle\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshreyashankar%2Fgpt3-sandbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshreyashankar%2Fgpt3-sandbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshreyashankar%2Fgpt3-sandbox/lists"}