{"id":13455900,"url":"https://github.com/ading2210/openplayground-api","last_synced_at":"2025-03-24T09:30:59.674Z","repository":{"id":143275430,"uuid":"615282874","full_name":"ading2210/openplayground-api","owner":"ading2210","description":"A reverse engineered Python API wrapper for OpenPlayground (nat.dev)","archived":true,"fork":false,"pushed_at":"2023-03-28T08:34:43.000Z","size":37,"stargazers_count":77,"open_issues_count":0,"forks_count":15,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-10-01T11:17:28.504Z","etag":null,"topics":["chatgpt","library","openplayground","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ading2210.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-17T10:54:30.000Z","updated_at":"2024-08-12T20:30:18.000Z","dependencies_parsed_at":"2023-04-11T13:44:24.007Z","dependency_job_id":null,"html_url":"https://github.com/ading2210/openplayground-api","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/ading2210%2Fopenplayground-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Fopenplayground-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Fopenplayground-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Fopenplayground-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ading2210","download_url":"https://codeload.github.com/ading2210/openplayground-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221956013,"owners_count":16907476,"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":["chatgpt","library","openplayground","python"],"created_at":"2024-07-31T08:01:13.189Z","updated_at":"2024-10-28T23:30:48.775Z","avatar_url":"https://github.com/ading2210.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Python OpenPlayground API\n[![PyPi Version](https://img.shields.io/pypi/v/openplayground-api.svg)](https://pypi.org/project/openplayground-api/)\n\nThis is an unoffical API wrapper for the website [OpenPlayground](https://nat.dev), which provides access to a wide array of AI models for free, including ChatGPT, GPT-4, and Claude.\n\n## Notice:\nOpenPlayground has recently announced that they are going to starting deleting accounts that access their API via automated means (probably as as a direct response to this library). You should be fine as long as you don't send to many requests, since this library is able to bypass their bot detection by spoofing the `X-Session` header. They've also recently been requiring SMS verification upon signup, but this can easily be bypassed by signing in using a Google account. \n\n![screenshot from their discord server](https://media.discordapp.net/attachments/1072352756481929316/1088019955322196048/image.png)\n\n## Features:\nThis library has the following abilities:\n - Log in using OTP code\n - List models\n - Generate text\n\n## Installation:\nYou can install this library by running the following command:\n```\npip3 install openplayground-api\n```\n\n## Documentation:\nAn example of how to use this library can be found in `/examples/example.py`.\n\n### The `Model` Class:\nThe `openplayground.Model` class describes a model that is available to the user. Valid attributes are:\n - `provider` - The company that developed the model (e.g., openai, anthropic)\n - `name` - The name of the model, such as `text-davinci-003`.\n - `version` - The version of the model. This may return `None` on some models.\n - `tag` - A string that combines the provider and name, such as `openai:text-davinci-003`.\n - `params` - A dictionary containing possible parameters for the model.\n\n### Authenticating With an OTP Code:\nThe `openplayground.Auth` class can be used to get your token using an OTP code emailed to you. Note that the following examples assume that `auth` is the name of your `openplayground.Auth` class.\n\n```python\nimport openplayground\nauth = openplayground.Auth()\n```\n\n#### Sending the OTP Code:\nThe `openplayground.Auth.send_otp_code` function sends an email containing the OTP code to the specificed email address. \n\n```python\nauth.send_otp_code(\"sample@example.com\")\n```\n\n#### Verifiying the OTP Code:\nOnce you have the OTP code, you can use the `openplayground.Auth.verify_otp_code` function to get your token from that OTP code. You can then use this token to create an `openplayground.Client` instance.\n\n```python\notp_code = input(\"Enter OTP code: \")\ntoken = auth.verify_otp_code()\n```\n\n### Using the Client:\nThe `openplayground.Client` class accepts two arguments, which are your account's token and its email. Your token can be obtained from the `__session` field in your browser's cookies, or using the `openplayground.Auth` class as shown above. The email field is optional, but filling it out might reduce the chances of this library being detected.\n\n```python\nimport openplayground\nclient = openplayground.Client(token, email=email)\n```\n\nNote that the following examples assume `client` is the name of your `openplayground.Client` instance.\n\n#### Downloading the Available Models:\nThe `client.get_models` function fetches the available models from `https://nat.dev/api/all_models`, and returns a dictionary of `openplayground.Model` objects. The client downloads the available models upon initialization and stores it in `client.models`, so calling this function shouldn't be necessary. \n\nSome popular model tags are:\n - OpenAI: `openai:gpt-4`, `openai:gpt-3.5-turbo`, `openai:text-davinci-003`\n - Anthropic: `anthropic:claude-instant-v1.0`, `anthropic:claude-v1.2`\n - Facebook/Stanford: `textgeneration:llama-65b`, `textgeneration:alpaca-7b`\n\n```python\nprint(client.models.keys())\n#dict_keys(['forefront:EleutherAI/GPT-J', 'forefront:EleutherAI/GPT-NeoX', 'forefront:pythia-12b', 'forefront:pythia-20b', 'forefront:pythia-6.9b', 'anthropic:claude-instant-v1.0', 'anthropic:claude-v1.2', 'textgeneration:alpaca-7b', 'textgeneration:llama-65b', 'huggingface:bigscience/bloomz', 'huggingface:google/flan-t5-xxl', 'huggingface:google/flan-ul2', 'cohere:command-medium-nightly', 'cohere:command-xlarge-nightly', 'cohere:medium', 'cohere:xlarge', 'openai:gpt-4', 'openai:code-cushman-001', 'openai:code-davinci-002', 'openai:gpt-3.5-turbo', 'openai:text-ada-001', 'openai:text-babbage-001', 'openai:text-curie-001', 'openai:text-davinci-002', 'openai:text-davinci-003'])\n```\n\n#### Generating Text:\nThe `client.generate` function generates some text given a model and a prompt. Optionally, you can also specify arguments such as the maximum length in the kwargs. You can find a list of valid arguments and their defaults in `openplayground.Model.params`. A few common ones are:\n - `maximum_length`\n - `temperature`\n - `top_k`\n - `top_p`\n\nThe values returned from this function are streamed and expressed in a dictionary. Note that GPT-4 access currently has a daily limit of around 10 requests/day, and may become paid in the future. \n\nStreamed example:\n```python\nfor chunk in client.generate(\"openai:gpt-3.5-turbo\", prompt):\n  if chunk[\"event\"] == \"infer\":\n    print(chunk[\"message\"], end=\"\", flush=True)\n```\n\nNon-streamed example:\n```python\nmessage = \"\"\nfor chunk in client.generate(\"openai:gpt-3.5-turbo\", prompt):\n  if chunk[\"event\"] == \"infer\":\n    message += chunk[\"message\"]\nprint(message)\n```\n\n### Misc:\n#### Changing the Spoofed User-Agent:\nYou can change the global User-Agent by setting `openplayground.user_agent` right after importing the library.\n\n```python\nimport openplayground\nopenplayground.user_agent = \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36\"\n```\n\n## Copyright:\nThis project is licensed under the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.txt). Most of the code has been written by me, [ading2210](https://github.com/ading2210). A list of all the contributors can be found [here](https://github.com/ading2210/openplayground-api/graphs/contributors).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fading2210%2Fopenplayground-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fading2210%2Fopenplayground-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fading2210%2Fopenplayground-api/lists"}