Skip to content

yjg30737/pyqt-openai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyqt-openai



PyQt/PySide(Python cross-platform GUI toolkit) OpenAI Chatbot which supports more than 8 languages (you can see the list below)

This supports Windows, MacOS, Linux.

You can use OpenAI models(GPT4o, GPT4-turbo, DALL-E, etc.) with PyQt as a chatbot.

The major advantage of this package is that you don't need to know other language aside from Python.

If you want to study openai with Python-only good old desktop software, this is for you.

This is using sqlite as a database.

You can select the model and change each parameters of openai from the right side bar.

Also you can combine openai with llama-index feature to make gpt model answer your question based on information you had provided!

An internet connection is required.

If you have any questions or you want to make AI related software with PyQt or PySide, feel free to join Discord server of pyqt-openai.

And if you would like to support this project, you can click the button below to make a donation. Your contribution will greatly assist various projects, including this one!

Buy Me A Coffee Donate with PayPal

This officially supports openai>=1.0.0 and llama-index>=0.9.2.

Table of Contents

Feature

  • Basically this is desktop application version of ChatGPT with image generation tool.
    • Text streaming (enable by default, you can disable it)
    • AI remembers past conversation
    • Support copy button
    • Able to stop response in the middle of text generation
  • Conversation management
    • Add & delete conversations
    • Save conversations - SQlite db, text files compressed file, html files compressed file (both are zip)
    • Rename conversation
    • everything above is saved in an SQLite database file named conv.db.
  • Support controlling parameters(temperature, top_p, etc) just like openai playground
  • Able to see the reason why stream is finished
  • Support token count (only for non-streaming response)
  • Support prompt generator (manageable, autosaved in database)
  • Support slash commands
  • Support beginning and ending part of the prompt
  • You can run this in background application
    • notification will pop up when response is generated
  • You can make window stack on top or control its transparency
  • Image generation (DALL-E3)
    • Support saving generated image to local
    • Support continue generation
    • Notification when task completes
  • You can copy and download the image directly as well. just hover the mouse cursor over the image.
  • You can fine-tune openai with llama-index.
  • Support text(.txt), image(.png, *.jpg) file uploading
  • Support searching title and content in the conversation
  • Support "find text" feature (match word, case-sensitive, regex, etc.)
  • Support customizing feature (homepage, user and AI profile image)

Supported Languages

  • English
  • Spanish
  • Chinese
  • Russian
  • Korean
  • French
  • German
  • Italian
  • Hindi
  • Arabic
  • Japanese

If you have any additional languages you would like to add, please feel free to make a request by mail, issue, discord, etc at any time.

Requirements

  • qtpy - the package allowing you to write code that works with both PyQt and PySide
  • PyQt5 >= 5.14 or PySide6
  • openai
  • aiohttp - for openai dependency
  • pyperclip - to copy prompt text from prompt generator
  • jinja2 - for saving the conversation with html file
  • llama-index - to fine-tune gpt with llamaindex
  • requests - for getting response from web
  • langchain - for connecting llama-index with gpt
  • pillow - for preventing ModuleNotFoundError from llama-index

You can install these requirements with only one line command "pip install -r requirements.txt". Just see "How to Install" section below.

It is not listed in requirements.txt, but you can use PyQt6 if you want.

Preview and Usage

Note: A lot of previews below are not from latest version. It is slightly different with current GUI. So if you want to really know what this looks like, see it by yourself :) But i will definitely change any image(s) which should be changed.

Overview

image You have to write your openai api key inside the red box. see How to install

You can change screen between text chatbot and image generating tool screen.

image

Using LlamaIndex

image

If you want to use this with your personal chatbot based on data you've given, then you can check the llamaindex checkbox and go to the tab, select the directory which includes .txt files containing the data.

Conversation

Preview 1

I recorded this preview long time ago so GUI is different from the current version, but way of operating it is pretty much the same.

PyQt.OpenAI.Chatbot.2023-05-06.08-16-48.mp4

Preview 2 (using prompt feature)

chat.mp4

Conversation Save Feature

image

You can save checked conversation units to SQlite db file or compressed file (zip) which contains each conversation as text/html file.

Prompt Generator

How to Generate

This application has two types of prompts. One is "Properties" and the other one is "Template". Properties are sets of attributes that are useful for forming the premises of a question. Templates are sentences that correspond to a single command. You can input a command to generate a sentence. This can be used as a question in itself.

Both types can be managed as groups. After cloning or installing, if you run the program immediately, you will be able to see the default group and the items included in the group, just like the screen.

For properties, there is a group named "Default" that provides a set of attributes referenced here.

For templates, there are the "awesome_chatGPT_prompt" and "alex_brogan" (example prompt for Alex Brogan) groups provided. Any custom template items created prior to version 0.1.6 will be moved to the Miscellaneous group.

prompt_list_image

With using these prompts you can pretty much get any response you want.

You can use the additional prompt feature by "prompt menu" right next to "prompt input" field.

image

Since v0.1.6, awesome-chatgpt-prompt is included as template group by default.

Prompt Generator Preview

Generating the prompt (Properties)

v0.1.6_propmt_generate.mp4

I recorded using the Windows recording feature. As a result, the "Add Dialog" that prompts for entering a group name does not appear in the preview. When you add a group, you will see the Add Dialog as expected.

Then, how to generate template type prompt? Click any item in the group, it will be shown in the preview.

You can copy that generated text with clicking "copy" button and include it to your prompt input.

If you add a property group or template group with items, you can use it as a command by typing its name to the prompt input.

Use prompt as a command

v0.1.6_command_generate.mp4

In this preview, i pressed the keyboard shortcut of each actions(show beginning, show ending, support prompt command) to use it rather than clicking them with mouse.

I made the command suggestion GUI resemble the Discord command autocomplete popup, with which a lot of people have become accustomed.

Use GPT Vision

How to Use it

  1. Select "gpt-4-vision-preview"

image

  1. Select image files from local with clicking "Upload Files"

image

  1. Ask something about images

image

Image Generation

image

How to Install

  1. git clone ~
  2. cd pyqt-openai
  3. pip install -r requirements.txt --upgrade
  4. cd pyqt_openai
  5. You should put your api key in the line edit. You can get it in official site of openai. Sign up and log in before you get it.

Be sure, this is a very important API key that belongs to you only, so you should remember it and keep it secure.

  1. python main.py

If installation doesn't work, you can contact me with bring up new issue in issue tab or check the troubleshooting below even it is only about very specific error.

Note

If you use Linux and see this error:

qt.qpa.plugin: could not load the qt platform plugin "xcb" in "" even though it was found

this application failed to start because no qt platform plugin could be initialized, reinstalling the application may fix this problem

run this command:

sudo apt-get install libxcb-xinerama0

Troubleshooting

subprocess-exited-with-error

If you see this error while installing the openai package

subprocess-exited-with-error

download the package itself from pypi.

Unzip it, access the package directory, type

python setup.py install

That will install the openai.

Note: I don't know this can happen in newer version of openai as well, so tell me if you know about something

qtpy.QtBindingsNotFoundError: No Qt bindings could be found

first, do this:

pip uninstall -r requirements.txt

second, do this:

pip install -r requirements.txt --upgrade

then it will work :)

Contact

You can join pyqt-openai's Discord Server to have a conversation about it or AI-related stuff 🙂

Note

I recommend to install sqlite management software. It's not necessary to run this app (obviously), but it's good practice to manage database about conversation history with AI and to know how this works.

LICENSE

MIT License

Copyright (c) 2023 Jung Gyu Yoon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Disclaimer

Please do not distribute this commercially without my permission, by claiming it as your own creation.