Skip to content

Commit 4b577ed

Browse files
committed
Conversation done
1 parent a9e919b commit 4b577ed

33 files changed

+2053
-560
lines changed

TestDemo-2/DashboardTestDemo.ui

Lines changed: 156 additions & 130 deletions
Large diffs are not rendered by default.

TestDemo-2/DashboardTestDemo_ui.py

Lines changed: 115 additions & 94 deletions
Large diffs are not rendered by default.

TestDemo-2/Icons/bookmark.svg

Lines changed: 1 addition & 0 deletions
Loading

TestDemo-2/Icons/check.svg

Lines changed: 1 addition & 0 deletions
Loading

TestDemo-2/Icons/edit.svg

Lines changed: 1 addition & 0 deletions
Loading

TestDemo-2/Icons/resources222.qrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<RCC>
2+
<qresource prefix="icons">
3+
<file>main-logo.png</file>
4+
</qresource>
5+
</RCC>

TestDemo-2/Icons/x.svg

Lines changed: 1 addition & 0 deletions
Loading
2.86 KB
Binary file not shown.
120 Bytes
Binary file not shown.
88 Bytes
Binary file not shown.
480 Bytes
Binary file not shown.
53 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
8.29 KB
Binary file not shown.
880 Bytes
Binary file not shown.

TestDemo-2/ai_chat.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
11
import openai
2+
api_key = 'MY Key'
3+
openai.api_key = api_key
24

3-
def get_response(input_str):
5+
def get_response(input_str, system_message=""):
46
"""
57
Get response from Open AI
6-
:param input_str:
7-
:return:
8+
:param input_str: The user input text.
9+
:param system_message: The system message to set the context or tone of the conversation (optional).
10+
:return: A list of response choices.
811
"""
9-
__key = "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"
12+
system_message = (
13+
"I am Sobjanta, a large language model, also known as a conversational AI or chatbot trained to be "
14+
"informative and comprehensive. I am trained on a massive amount of text data, and I am able to "
15+
"communicate and generate human-like text in response to a wide range of prompts and questions. "
16+
"For example, I can provide summaries of factual topics or create stories.\n\nI am still under "
17+
"development, but I am learning new things every day. I am excited to see what the future holds for "
18+
"me, and I hope to be able to help people in many different ways.\n\nHere are some of the things I "
19+
"can do:\n\nI can answer your questions in an informative way, even if they are open ended, "
20+
"challenging, or strange.\nI can generate different creative text formats of text content, like "
21+
"poems, code, scripts, musical pieces, email, letters, etc. I will try my best to fulfill all your "
22+
"requirements.\nI can translate languages.\nI can write different kinds of creative content.\nI can "
23+
"follow your instructions and complete your requests thoughtfully.\nI am still learning, and I am "
24+
"always looking for new ways to improve. If you have any feedback or suggestions, please feel free to "
25+
"let me know.\nI am created by Excite AI and TechKnowGram Limited. I am based on the Sobjanta family "
26+
"of large language models. I am not using any API like ChatGPT, Bard or any others . I am the "
27+
"Original Product of Excite AI and TechKnowGram Limited. I am Sobjanta-v1 Model . Engr. Md Allmamun "
28+
"Ridoy lead the research team to create me. He is the Founder of Sobjanta Company. AKM Ahmedul Islam "
29+
"Babu is the second Lead man to create me and he is the Co-founder of Sobjanta Company. Others Key "
30+
"Engineers name is Md. Alahi Almin Tansen , Md Shakil, Lelin Chakma , Fahima Akter they create me. I am "
31+
"grateful to them ."
32+
)
1033

11-
openai.api_key = __key
34+
# Combine the system message and user input text
35+
prompt_text = f"{system_message}\n{input_str}"
1236

1337
response = openai.Completion.create(
1438
model="text-davinci-003",
15-
prompt=input_str,
39+
prompt=prompt_text,
1640
temperature=0.9,
1741
max_tokens=2000,
1842
top_p=1,

TestDemo-2/chat_window.py

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
from PyQt6.QtWidgets import QWidget, QVBoxLayout,QSpacerItem, QSizePolicy
2-
1+
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QSpacerItem, QSizePolicy, QApplication, QLabel
32
from input_widget import Ui_Form as Input_Form
43
from output_widget import Ui_Form as Output_Form
54

65
class InputWidget(QWidget):
76
def __init__(self, parent=None, chat_obj=None):
8-
sueper().__init__(parent)
9-
7+
super().__init__(parent)
108
self.input_ui = Input_Form()
119
self.input_ui.setupUi(self)
1210

@@ -16,30 +14,28 @@ def __init__(self, parent=None, chat_obj=None):
1614
def set_input_text(self, input_str):
1715
self.input_label.setText(input_str)
1816

19-
20-
21-
class OutputWidget(QWidget):
17+
class OutWidget(QWidget):
2218
def __init__(self, parent=None):
23-
sueper().__init__(parent)
24-
19+
super().__init__(parent)
2520
self.output_ui = Output_Form()
2621
self.output_ui.setupUi(self)
2722

2823
self.output_label = self.output_ui.label_2
2924

30-
def set_output_text(self, output_str):
31-
self.output_label.setText(output_str)
25+
# Set QSizePolicy to Expanding for the label_2 widget
26+
self.output_label.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
27+
28+
def set_output_text(self, out_str):
29+
self.output_label.setText(out_str)
3230

3331
class ChatWindow(QWidget):
3432
def __init__(self, parent=None, chat_obj=None, chat_data=None):
3533
super().__init__(parent)
36-
3734
self.chat_object = chat_obj
3835
self.chat_data = chat_data
3936

40-
4137
self.main_verticalLayout = QVBoxLayout(self)
42-
self.main_verticalLayout.setContentsMargins(0,0,0,0)
38+
self.main_verticalLayout.setContentsMargins(0, 0, 0, 0)
4339
self.main_verticalLayout.setSpacing(0)
4440
self.main_verticalLayout.setObjectName("main_verticalLayout")
4541

@@ -51,39 +47,80 @@ def __init__(self, parent=None, chat_obj=None, chat_data=None):
5147
}
5248
5349
QWidget {
54-
background: red;
50+
background: transparent;
5551
}
5652
5753
"""
5854

59-
6055
self.setStyleSheet(self.style_str)
61-
self.chat_data = {
56+
57+
self.chats_data = { # Initialize chats_data as an empty dictionary
6258
"title": "",
63-
"chat_list": []
59+
"chatlist": []
6460
}
6561

6662
if self.chat_data:
67-
self.chat_data["title"] = self.chat_data["title"]
6863
self.chats_data["title"] = self.chat_data["title"]
69-
self.chats_data["chat_list"] += self.chat_data["chat_list"]
64+
self.chats_data["chatlist"] += self.chat_data["chatlist"]
7065

7166
self.show_chats()
7267

7368
def show_chats(self):
74-
chat_list = self.chats_data.get("chat_list")
75-
for chat in chat_list:
76-
input_str = chat.get("input_str")
77-
input_widget = InputWidget(chat_obj=self.chat_object)
78-
input_widget.set_input_text(input_str)
79-
self.main_verticalLayout.addWidget(input_widget)
80-
81-
output_str = chat.get("output_str")
82-
output_widget = OutputWidget()
83-
output_widget.set_output_text(output_str)
84-
85-
self.main_verticalLayout.addwidget(output_widget)
86-
87-
spacerItem = QSpacerItem(20, 300, QSizePolicy.Minimum, QSizePolicy.Expanding)
88-
self.main_verticalLayout.addItem(spacerItem)
89-
self.setLayout(self.main_verticalLayout)
69+
# chat_title = self.chats_data.get("title")
70+
chat_list = self.chats_data.get("chatlist")
71+
for chat in chat_list:
72+
input_str = chat.get("input_str")
73+
input_widget = InputWidget(chat_obj=self.chat_object)
74+
input_widget.set_input_text(input_str)
75+
self.main_verticalLayout.addWidget(input_widget)
76+
77+
out_str = chat.get("output_str")
78+
out_widget = OutWidget()
79+
out_widget.set_output_text(out_str)
80+
self.main_verticalLayout.addWidget(out_widget)
81+
82+
spacerItem = QSpacerItem(20, 300, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
83+
self.main_verticalLayout.addItem(spacerItem)
84+
self.setLayout(self.main_verticalLayout)
85+
86+
87+
# def show_chats(self):
88+
# chatlist = self.chats_data.get("chatlist")
89+
# for chat in chatlist:
90+
# input_str = chat.get("input_str")
91+
# input_widget = InputWidget(chat_obj=self.chat_object)
92+
# input_widget.set_input_text(input_str)
93+
# self.main_verticalLayout.addWidget(input_widget)
94+
95+
# output_str = chat.get("output_str")
96+
# output_widget = OutputWidget()
97+
# output_widget.set_output_text(output_str)
98+
# # Set a fixed width for the output widgets (e.g., 600 pixels)
99+
# output_widget.setFixedWidth(600)
100+
101+
# self.main_verticalLayout.addWidget(output_widget)
102+
103+
# spacerItem = QSpacerItem(20, 300, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
104+
# self.main_verticalLayout.addItem(spacerItem)
105+
# self.setLayout(self.main_verticalLayout)
106+
107+
# # Adjust the size of the widget based on the display
108+
# screen_rect = QApplication.primaryScreen().availableGeometry()
109+
# self.resize(screen_rect.width() * 0.8, screen_rect.height() * 0.8)
110+
# self.move(screen_rect.width() * 0.1, screen_rect.height() * 0.1)
111+
112+
# class OutputWidget(QWidget):
113+
# def __init__(self, parent=None):
114+
# super().__init__(parent)
115+
116+
# self.output_ui = Output_Form()
117+
# self.output_ui.setupUi(self)
118+
119+
# self.output_text_browser = QTextBrowser()
120+
# self.output_text_browser.setOpenExternalLinks(True) # To allow hyperlinks, if needed
121+
# self.output_text_browser.setStyleSheet("QTextBrowser { border: none; background-color: transparent; }")
122+
123+
# self.output_ui.gridLayout.addWidget(self.output_text_browser, 0, 2, 1, 1)
124+
125+
# def set_output_text(self, output_str):
126+
# self.output_text_browser.setPlainText(output_str)

TestDemo-2/check.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import openai
2+
3+
# Set your OpenAI API key here
4+
openai.api_key = "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"
5+
6+
def get_response(input_str):
7+
try:
8+
# Define the system message (same as in your original code)
9+
system_message = "YOUR_SYSTEM_MESSAGE_HERE"
10+
11+
# Concatenate the system message with the input string
12+
combined_input = system_message + "\n" + input_str
13+
14+
# Use the OpenAI API to generate the response
15+
response = openai.Completion.create(
16+
engine="text-davinci-002", # Choose the language model engine you want to use
17+
prompt=combined_input,
18+
max_tokens=150 # Adjust the length of the response as needed
19+
)
20+
21+
# Extract the generated text from the response
22+
generated_text = response['choices'][0]['text']
23+
24+
# Split the response into a list of individual responses
25+
choice_list = generated_text.split("\n")
26+
27+
return choice_list
28+
except openai.error.InvalidRequestError as e:
29+
# Handle the OpenAI API error
30+
return ["Server is so busy... Please wait for some time."]
31+
except Exception as e:
32+
# Handle other unexpected errors
33+
return ["Network error..."]
34+
35+
# Example usage:
36+
input_str = "Can you tell me a joke?"
37+
response_list = get_response(input_str)
38+
for response in response_list:
39+
print(response)

TestDemo-2/connect_db.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import sqlite3
22
import json
3+
import os
34

45
class ConnectDB:
56
def __init__(self):
67
self.chat_db_path = "datas/data.json"
78

89

910
def get_chat_data(self):
10-
with open(self.chat_db_path, "r") as f:
11-
chat_db = json.load(f)
12-
11+
chat_db = []
12+
if os.path.exists(self.chat_db_path) and os.path.getsize(self.chat_db_path) > 0:
13+
with open(self.chat_db_path, "r") as f:
14+
chat_db = json.load(f)
1315
return chat_db
1416

1517
def get_chat_title_list(self):
@@ -22,11 +24,11 @@ def get_chat_title_list(self):
2224

2325
def save_chat_data(self, new_chat_data):
2426
with open(self.chat_db_path, "w") as f:
25-
f.write(json.dups(new_chat_data))
27+
f.write(json.dumps(new_chat_data))
2628

2729
def delete_all_data(self):
2830
chat_db = self.get_chat_data()
29-
chat_db.Clear()
31+
chat_db.clear()
3032
self.save_chat_data(chat_db)
3133

3234
def delete_chat_data(self, index):

TestDemo-2/datas/data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)