Package: ezgpt
ezgptezgptis a Python library designed to simplify the interaction with OpenAI's GPT (Generative Pre-trained Transformer) models. It provides a convenient interface for sending prompts to the model and receiving responses, with optional logging for debugging purposes.InstallationYou can installezgptvia pip:pipinstallezgptUsageTo useezgpt, you need to have an API key from OpenAI. This key must either be set as an environment variableOPENAI_API_KEYor be passed with the static functionezgpt.set_api_key(api_key)before using the library. Since these are async functions, you either have to useawait, orimport asyncioand useasyncio.run().InitializationFirst, import theezgptmodule and initialize thegptclass:importezgptgpt=ezgpt.gpt()Thegptclass constructor accepts the following parameters:model: The identifier of the GPT model to use (default:'gpt-3.5-turbo').system: An optional system-level prompt that provides instructions or context for the GPT model.temperature: Controls randomness in the response generation (default:0).top_p: Controls diversity of the response generation (default:0).max_tokens: The maximum number of tokens to generate in the response (default:2048).frequency_penalty: Decreases the likelihood of repetition in the response (default:0).presence_penalty: Encourages the model to talk about new topics (default:0).logs: Enables or disables logging of the interaction (default:False).Sending PromptsTo send a prompt to the GPT model, use thegetmethod of thegptinstance:response=awaitgpt.get(user="Your prompt here")Thegetmethod accepts the following parameters:system: Overrides the system-level prompt for this request.user: The user-level prompt to send to the model.messages: A list of previous message exchanges to maintain context.temperature: Overrides the default temperature for this request.top_p: Overrides the default top_p for this request.max_tokens: Overrides the default max_tokens for this request.frequency_penalty: Overrides the default frequency_penalty for this request.presence_penalty: Overrides the default presence_penalty for this request.Since your last request is stored underself.previous, you can append a message to your conversation like that:response=awaitgpt.get(messages=gpt.previous,user="Another message")LoggingIf logging is enabled,ezgptwill print the interaction with the GPT model to the console. This includes the prompts sent by the user and system, as well as the responses from the assistant.Simpler usageIf you don't care about any classes or instances, you can also just use the staticgetandresetfunctions:awaitezgpt.get('Hello!')# 'Hello! How can I assist you today?'Aside the normal GPT arguments, there's another booleanuse_previousto use the previous conversation:awaitezgpt.get('What was my previous message?',True)# 'Your previous message was "Hello".'You can use thereset()function to clear the previous messages, and optionally also change the model:ezgpt.reset('gpt-4')ConversationAn even simpler way to use GPT is using theconversation()static function. Here you can use the normal GPT arguments, and when you use it, you'll be able to have a conversation with GPT.There are special commands you can use:?: View the list of commands??: Print some general useful information!: Exit the conversation:[command]: Run Python command: This will execute everything after the:as a line of Python.Example::print('hello')will printhello#[property] [value]: Set GPT's property, such asmodel. Use just#to list all properties. Use##to reset all properties. Use?#for help.Example:#model gpt-4will set the model togpt-4$[message]: Set the system message. Leave message empty to remove. Use_as message for multiline+<index> [message]: Insert message before index (double+for assistant instead of user). Index defaults to last message (append). Use_asmessagefor multilineExample:++0 Hello!will insert a message at the start by the assistant with contentHello!-<index>: Remove message at index (double-to clear every message, triple-to completely restart ezgpt.conversation). Index defaults to last messageExample:-0will remove the first message~[index] [message]: Change message at index (double~for reverse role). If you use~~you don't need a message argument. Use_asmessagefor multilineExample:~~0 Hello!will change the first message toHello!and switch its role&: Re-generates the last message GPT sent.@<index>: Copy message at index (defaults to last message) to clipboard (requirespyperclipmodule)@~<index>: Copy codeblock. Index starts and defaults to1(first codeblock).@@: Copy conversation JSON to clipboard (requirespyperclipmodule)^<name>: Save the conversation. Gets cleared after restart and is only valid for the current session.argdefaults to the current conversation%<name>: Load the conversationname. Use just%without arguments to list all saved conversations. Use%%<name>to use from local filesystem (~/.ezgpt_conversations.json)%+<name>: Save the conversation asname. Use%%+<name>to save to local filesystem.%-<name>: Remove the conversationname. Use%%%%<name>Same as%<name>but will get the conversation from~/.ezgpt_conversations.jsonFlows: Similar syntax to conversation saving/loading, but using^instead of%. To run a flow, use^[name] [message]. Use_as[message]for multi-line. To save, use^+[name] [conversations], whereconversationsis a list of saved conversations to step through, seperated by spaces. Also allows for local filesystem (~/.ezgpt_flows.json)=: Switch between full view and shortened view. Shortened view will only contain the first line up to 100 characters for easy readability.empty: Sending an empty message will reload the conversation to only include the actual messages.\[message]: This will let you type messages with special characters at the beginning without having them act as commands.Example:\- Hellowill add message- Hello_: Start multiline. This lets you write and paste in multi-line text.Ctrl+XwithEnterto stop multiline,Ctrl+Cto cancel,Ctrl+UwithEnterto remove previous line.If you put a number before your prompt, it will execute the prompt n times.Example:10-0will remove the first 10 messagesA shorthand to startconversationis using theezgpt.c()static function. While generating, you can useCtrl+Cto cancel or resend.NotesTheezgptlibrary assumes that the OpenAI API key is set in the environment variableOPENAI_API_KEYor has been passed usingezgpt.set_api_key(api_key).Thegptclass maintains a history of the conversation in thepreviousattribute, which can be used to provide context for subsequent requests.