Package: openplayground-api
Python OpenPlayground APIThis is an unoffical API wrapper for the websiteOpenPlayground, which provides access to a wide array of AI models for free, including ChatGPT, GPT-4, and Claude.Notice:OpenPlayground 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 theX-Sessionheader. They've also recently been requiring SMS verification upon signup, but this can easily be bypassed by signing in using a Google account.Features:This library has the following abilities:Log in using OTP codeList modelsGenerate textInstallation:You can install this library by running the following command:pip3 install openplayground-apiDocumentation:An example of how to use this library can be found in/examples/example.py.TheModelClass:Theopenplayground.Modelclass describes a model that is available to the user. Valid attributes are:provider- The company that developed the model (e.g., openai, anthropic)name- The name of the model, such astext-davinci-003.version- The version of the model. This may returnNoneon some models.tag- A string that combines the provider and name, such asopenai:text-davinci-003.params- A dictionary containing possible parameters for the model.Authenticating With an OTP Code:Theopenplayground.Authclass can be used to get your token using an OTP code emailed to you. Note that the following examples assume thatauthis the name of youropenplayground.Authclass.importopenplaygroundauth=openplayground.Auth()Sending the OTP Code:Theopenplayground.Auth.send_otp_codefunction sends an email containing the OTP code to the specificed email address.auth.send_otp_code("sample@example.com")Verifiying the OTP Code:Once you have the OTP code, you can use theopenplayground.Auth.verify_otp_codefunction to get your token from that OTP code. You can then use this token to create anopenplayground.Clientinstance.otp_code=input("Enter OTP code: ")token=auth.verify_otp_code()Using the Client:Theopenplayground.Clientclass accepts two arguments, which are your account's token and its email. Your token can be obtained from the__sessionfield in your browser's cookies, or using theopenplayground.Authclass as shown above. The email field is optional, but filling it out might reduce the chances of this library being detected.importopenplaygroundclient=openplayground.Client(token,email=email)Note that the following examples assumeclientis the name of youropenplayground.Clientinstance.Downloading the Available Models:Theclient.get_modelsfunction fetches the available models fromhttps://nat.dev/api/all_models, and returns a dictionary ofopenplayground.Modelobjects. The client downloads the available models upon initialization and stores it inclient.models, so calling this function shouldn't be necessary.Some popular model tags are:OpenAI:openai:gpt-4,openai:gpt-3.5-turbo,openai:text-davinci-003Anthropic:anthropic:claude-instant-v1.0,anthropic:claude-v1.2Facebook/Stanford:textgeneration:llama-65b,textgeneration:alpaca-7bprint(client.models.keys())#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'])Generating Text:Theclient.generatefunction 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 inopenplayground.Model.params. A few common ones are:maximum_lengthtemperaturetop_ktop_pThe 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.Streamed example:forchunkinclient.generate("openai:gpt-3.5-turbo",prompt):ifchunk["event"]=="infer":print(chunk["message"],end="",flush=True)Non-streamed example:message=""forchunkinclient.generate("openai:gpt-3.5-turbo",prompt):ifchunk["event"]=="infer":message+=chunk["message"]print(message)Misc:Changing the Spoofed User-Agent:You can change the global User-Agent by settingopenplayground.user_agentright after importing the library.importopenplaygroundopenplayground.user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"Copyright:This project is licensed under theGNU GPL v3. Most of the code has been written by me,ading2210. A list of all the contributors can be foundhere.