8000 Merge pull request #57 from yjg30737/feature/llamaindex · ag-python-qt/pyqt-openai@81d55b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 81d55b5

Browse files
authored
Merge pull request yjg30737#57 from yjg30737/feature/llamaindex
Feature/llamaindex
2 parents c373a95 + 0cd26cc commit 81d55b5

File tree

17 files changed

+690
-735
lines changed

17 files changed

+690
-735
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,5 @@ dmypy.json
130130

131131
# pyqt_openai
132132
pyqt_openai/pyqt_openai.ini
133-
pyqt_openai/conv.json
134-
pyqt_openai/conv_history.json
135133
pyqt_openai/conv.db
136-
pyqt_openai/a.py
137134
pyqt_openai/test/

pyqt_openai/image_gen_widget/imageListWidget.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def __initUi(self, text):
2525
lay.addWidget(self.__topicLbl)
2626
lay.setContentsMargins(0, 0, 0, 0)
2727

28-
leftWidget = QWidget()
29-
leftWidget.setLayout(lay)
28+
bottomWidget = QWidget()
29+
bottomWidget.setLayout(lay)
3030

3131
editButton = SvgButton()
3232
editButton.setIcon('ico/edit.svg')
@@ -45,12 +45,12 @@ def __initUi(self, text):
4545
lay.setAlignment(Qt.AlignCenter | Qt.AlignRight)
4646
lay.setContentsMargins(0, 0, 0, 0)
4747

48-
rightWidget = QWidget()
49-
rightWidget.setLayout(lay)
48+
topWidget = QWidget()
49+
topWidget.setLayout(lay)
5050

51-
lay = QHBoxLayout()
52-
lay.addWidget(leftWidget)
53-
lay.addWidget(rightWidget)
51+
lay = QVBoxLayout()
52+
lay.addWidget(topWidget)
53+
lay.addWidget(bottomWidget)
5454

5555
self.setLayout(lay)
5656

pyqt_openai/llama_example/__init__.py

Whitespace-only changes.
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# pyqt-openai
2+
<p align="center">
3+
<img src="https://user-images.githubusercontent.com/55078043/229002952-9afe57de-b0b6-400f-9628-b8e0044d3f7b.png">
4+
</p>
5+
6+
Example of using OpenAI with PyQt (Python cross-platform GUI toolkit)
7+
8+
This shows an example of using OpenAI with PyQt as a chatbot and using DALL-E or Stable Diffusion as a image generation tool.
9+
10+
Even though this project has become too huge to be called an 'example'.
11+
12+
The major advantage of this package is that you don't need to know other language aside from Python.
13+
14+
If you want to study openai with Python-only good old desktop software, this is for you.
15+
16+
The OpenAI model this package uses is the <a href="https://platform.openai.com/docs/models/gpt-3-5">gpt-3.5-turbo</a> model(which is nearly as functional as <b>ChatGPT</b>) by default. You can use gpt-4 as well.
17+
18+
Image generation feature(DALL-E and Stable Diffusion) available since v0.1.4.
19+
20+
<b>Stable Diffusion</b> used [DreamStudio API](https://dreamstudio.ai/). This is not entirely free like stable-diffusion-webgui.
21+
22+
But this is very lightweight and more accessible. don't need CUDA, torch, expansive PC, anything.
23+
24+
This is using <b>sqlite</b> as a database.
25+
26+
You can select the model at the right side bar.
27+
28+
An internet connection is required.
29+
30+
## Table of Contents
31+
* [Feature](#feature)
32+
* [Requirements](#requirements)
33+
* [Preview & Usage](#preview-usage)
34+
* [How to Install](#how-to-install)
35+
* [Troubleshooting](#troubleshooting)
36+
* [Contact](#contact)
37+
* [Note](#note)
38+
* [See Also](#see-also)
39+
40+
## Feature
41+
* basically this is <b>desktop application version of ChatGPT</b> with image generation tool.
42+
* text streaming (enable by default, you can disable it)
43+
* AI remembers past conversation
44+
* conversation management
45+
* add & delete conversations
46+
* save conversations
47+
* rename conversation
48+
* everything above is saved in an SQLite database file named conv.db.
49+
* support GPT-4 and every other models below GPT3
50+
* support prompt generator (manageable, autosaved in database)
51+
* support slash commands
52+
* support beginning and ending part of the prompt
53+
* you can run this in background application
54+
* notification will pop up when response is generated
55+
* you can make window stack on top or control its transparency
56+
* image generation (DALL-E, Stable Diffusion with DreamStudio API)
57+
* you can copy and download the image if you want. just hover the mouse cursor over the image.
58+
59+
## Requirements
60+
* qtpy - the package allowing you to write code that works with both PyQt and PySide
61+
* PyQt5 >= 5.14 or PySide6
62+
* openai
63+
* aiohttp - for openai dependency
64+
* pyperclip - to copy prompt text from prompt generator
65+
* stability_sdk - for Stable Diffusion
66+
67+
## Preview & Usage
68+
### Overview
69+
#### Windows
70+
![image](https://github.com/yjg30737/pyqt-openai/assets/55078043/51667298-2c3f-4846-a8c9-ec56331b8361)
71+
<b>You have to write your openai api key inside the red box.</b> see [How to install](#how-to-install)
72+
73+
You can change screen between text chatbot and image generating tool screen.
74+
75+
![image](https://github.com/yjg30737/pyqt-openai/assets/55078043/78260aaf-2626-4267-9309-07655cab2061)
76+
77+
#### Linux (Ubuntu)
78+
![image](https://github.com/yjg30737/pyqt-openai/assets/55078043/4005c085-53f4-406f-adb0-4fb4d87d88ba)
79+
80+
If you use MacOS, please give me the pyqt-openai screen image from it.
81+
82+
### Conversation
83+
#### Preview 1
84+
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.
85+
86+
https://user-images.githubusercontent.com/55078043/236583883-8e9732a3-1223-4b28-85f1-f60d8b2d6ced.mp4
87+
#### Preview 2 (using prompt feature)
88+
89+
https://github.com/yjg30737/pyqt-openai/assets/55078043/841a1505-f1cc-452e-99ab-0a9c661e6ead
90+
91+
### Prompt Generator
92+
#### How to Generate
93+
This application has two types of prompts. One is <b>"Properties"</b> and the other one is <b>"Template"</b>. 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.
94+
95+
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.
96+
97+
For properties, there is a group named "Default" that provides a set of attributes referenced <a href="https://gptforwork.com/tools/prompt-generator">here</a>.
98+
99+
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.
100+
101+
![prompt_list_image](https://github.com/yjg30737/pyqt-openai/assets/55078043/ce40139a-c03f-42ef-abd8-4a610d762394)
102+
103+
With using these prompts you can pretty much get any response you want.
104+
105+
You can use the additional prompt feature by "prompt menu" right next to "prompt input" field.
106+
107+
![image](https://github.com/yjg30737/pyqt-openai/assets/55078043/c9ca84af-0088-4435-854d-7feca9e2e663)
108+
109+
Since v0.1.6, awesome-chatgpt-prompt is included as template group by default.
110+
111+
#### Prompt Generator Preview
112+
Generating the prompt (Properties)
113+
114+
https://github.com/yjg30737/pyqt-openai/assets/55078043/e168c0e6-41b4-4ad5-95e6-3c42c9c23602
115+
116+
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.
117+
118+
Then, how to generate template type prompt? Click any item in the group, it will be shown in the preview.
119+
120+
You can copy that generated text with clicking "copy" button and include it to your prompt input.
121+
122+
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.
123+
124+
<b>Use prompt as a command</b>
125+
126+
https://github.com/yjg30737/pyqt-openai/assets/55078043/df0d3923-1fbe-4dda-af6f-4e4d1e572553
127+
128+
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.
129+
130+
I made the command suggestion GUI resemble the Discord command autocomplete popup, with which a lot of people have become accustomed.
131+
132+
### Image Generation
133+
![image](https://github.com/yjg30737/pyqt-openai/assets/55078043/d0903a76-bf4f-4900-bfea-89da6f072c9d)
134+
135+
## How to Install
136+
1. git clone ~
137+
2. cd pyqt-openai
138+
3. pip install -r requirements.txt
139+
4. cd pyqt_openai
140+
5. You should put your api key in the line edit. You can get it in <a href="https://platform.openai.com/account/api-keys">official site</a> of openai. Sign up and log in before you get it.
141+
142+
Be sure, this is a very important API key that belongs to you only, so you should remember it and keep it secure.
143+
144+
6. python main.py
145+
146+
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.
147+
148+
### Note
149+
If you use Linux and see this error:
150+
```
151+
qt.qpa.plugin: could not load the qt platform plugin "xcb" in "" even though it was found
152+
153+
this application failed to start because no qt platform plugin could be initialized, reinstalling the application may fix this problem
154+
```
155+
156+
run this command:
157+
```
158+
sudo apt-get install libxcb-xinerama0
159+
```
160+
161+
## Troubleshooting
162+
If you see this error while installing the openai package
163+
```
164+
subprocess-exited-with-error
165+
```
166+
download the package itself from <a href="https://pypi.org/project/openai/#files">pypi</a>.
167+
168+
Unzip it, access the package directory, type
169+
```
170+
python setup.py install
171+
```
172+
173+
That will install the openai.
174+
175+
Note: I don't know this can happen in newer version of openai as well, so tell me if you know about something
176+
177+
## Contact
178+
You can join pyqt-openai's <a href="https://discord.gg/cHekprskVE">Discord Server</a> to have a conversation about it or AI-related stuff 🙂
179+
180+
## Note
181+
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.
182+
183+
## TODO list
184+
* DB for images (to further experiement of both DALL-E and Stable Diffusion or other image generation engine)
185+
* show the explanation of every model and terms related to AI (e.g. temperature, topp..)
186+
* save conversation history with other format (xlsx, csv, etc.)
187+
* tokenizer
188+
* highlight the source (optional, eventually)
189+
* support multiple language
190+
* use SQLAlchemy (maybe not)
191+
* show reason when the chat input is disabled for some reasons
192+
* add the basic example sources of making deep learning model with PyTorch (eventually)
193+
194+
## See Also
195+
* <a href="https://learn.microsoft.com/en-us/azure/cognitive-services/openai/overview">Azure OpenAI service</a>
196+
* <a href="https://openai.com/waitlist/gpt-4-api">join gpt4 waitlist</a> - i took 1 month to get access from it
197+
* <a href="https://https://openai.com/waitlist/plugins">join chatgpt plugins waitlist</a>
198+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yjg30737 is Python, AI enthusiast.

pyqt_openai/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,6 @@ def __setApi(self):
239239
self.__setApiKey(api_key)
240240
self.__settings_struct.setValue('API_KEY', api_key)
241241

242-
self.__openAiChatBotWidget.setModelInfoByModel(True)
243-
244242
self.__apiCheckPreviewLbl.setStyleSheet("color: {}".format(QColor(0, 200, 0).name()))
245243
self.__apiCheckPreviewLbl.setText('API key is valid')
246244
else:

0 commit comments

Comments
 (0)
0