Posted: . At: 9:33 AM. This was 1 year ago. Post ID: 17711
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Use the powerful ChatGPT bot in your Python scripts with a nice wrapper.


This interesting tool is a Python wrapper that will allow the leveraging of ChatGPT in your Python scripts. This would make a very powerful script indeed.

Download the source code.

┌──[jason@11000000.10101000.00000001.00000010][~]
└──╼  ╼ $ git clone https://github.com/mmabrouk/chatgpt-wrapper.git
Cloning into 'chatgpt-wrapper'...
remote: Enumerating objects: 1453, done.
remote: Counting objects: 100% (975/975), done.
remote: Compressing objects: 100% (273/273), done.
remote: Total 1453 (delta 777), reused 876 (delta 698), pack-reused 478
Receiving objects: 100% (1453/1453), 2.36 MiB | 651.00 KiB/s, done.
Resolving deltas: 100% (922/922), done.

Then install the requirements for Python.

┌──[jason@11000000.10101000.00000001.00000010][~]
└──╼  ╼ $ pip install setuptools
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (59.6.0)

┌──[jason@11000000.10101000.00000001.00000010][~]
└──╼  ╼ $ sudo apt install moreutils

You may install this wrapper directly if you wish. Instead of using git clone.

┌──[jason@11000000.10101000.00000001.00000010][~]
└──╼  ╼ $ pip install git+https://github.com/mmabrouk/chatgpt-wrapper
Defaulting to user installation because normal site-packages is not writeable
Collecting git+https://github.com/mmabrouk/chatgpt-wrapper
  Cloning https://github.com/mmabrouk/chatgpt-wrapper to /tmp/pip-req-build-lgzxmmr5
  Running command git clone --filter=blob:none --quiet https://github.com/mmabrouk/chatgpt-wrapper /tmp/pip-req-build-lgzxmmr5
  Resolved https://github.com/mmabrouk/chatgpt-wrapper to commit 0cd8aa1e58e66bd2167aff8349859810308c61ed
  Preparing metadata (setup.py) ... done

Once this is done, you are almost there. Run the command below to install a web browser, to when logging into ChatGPT.

┌──[jason@11000000.10101000.00000001.00000010][~]
└──╼  ╼ $ playwright install firefox
Downloading Firefox 109.0 (playwright build v1378) from https://playwright.azureedge.net/builds/firefox/1378/firefox-ubuntu-22.04.zip
78.3 Mb [====================] 100% 0.0s
Firefox 109.0 (playwright build v1378) downloaded to /home/jason/.cache/ms-playwright/firefox-1378

Once it is installed, run the chatgpt install command to load the browser, log in as usual and then close the browser. You should be presented with a ChatGPT prompt on the terminal.

┌──[jason@11000000.10101000.00000001.00000010][~]
└──╼  ╼ $ chatgpt install
Install mode: Log in to ChatGPT in the browser that pops up, and click
through all the dialogs, etc. Once that is achieved, exit and restart
this program without the 'install' parameter.
 
 
                                                               Provide a prompt for ChatGPT, or type /help or ? to list commands.                                                                
 
1>

Below are all of the available commands you may use in the chat prompt.

    /ask: Ask a question to ChatGPT
    /chat: Retrieve chat content
    /config: Show the current configuration
    /context: Load an old context from the log
    /delete: Delete one or more conversations
    /editor: Open an editor for entering a command
    /exit: Exit the ChatGPT shell
    /file: Send a prompt read from the named file
    /history: Show recent conversation history
    /log: Enable/disable logging to a file
    /nav: Navigate to a past point in the conversation
    /new: Start a new conversation
    /quit: Exit the ChatGPT shell
    /read: Begin reading multi-line input
    /stream: Toggle streaming mode
    /switch: Switch to chat
    /title: Show or set title
    /ask: Ask a question to ChatGPT
    /chat: Retrieve chat content
    /config: Show the current configuration
    /context: Load an old context from the log
    /delete: Delete one or more conversations
    /editor: Open an editor for entering a command
    /exit: Exit the ChatGPT shell
    /file: Send a prompt read from the named file
    /history: Show recent conversation history
    /log: Enable/disable logging to a file
    /nav: Navigate to a past point in the conversation
    /new: Start a new conversation
    /quit: Exit the ChatGPT shell
    /read: Begin reading multi-line input
    /session: Refresh session information
    /stream: Toggle streaming mode
    /switch: Switch to chat
    /title: Show or set title

This should be a lot of fun to play with and there should be many uses for this tool.

There is also a very useful ChatGPT API to allow developers to leverage the AI chatbot in their own applications.

https://openai.com/blog/introducing-chatgpt-and-whisper-apis

Give this a try today and see what you can develop.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.