From a2782e4fc642f7410061c8b4c015ecb633e1124b Mon Sep 17 00:00:00 2001 From: Vesna Tanko Date: Fri, 12 May 2023 11:24:13 +0200 Subject: [PATCH 1/4] Chat GPT: Save access key to system keyring service --- orangecontrib/prototypes/widgets/owchatgpt.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/orangecontrib/prototypes/widgets/owchatgpt.py b/orangecontrib/prototypes/widgets/owchatgpt.py index 1dd6aee2..d9e5b475 100644 --- a/orangecontrib/prototypes/widgets/owchatgpt.py +++ b/orangecontrib/prototypes/widgets/owchatgpt.py @@ -9,6 +9,7 @@ from Orange.data import Table, StringVariable from Orange.widgets import gui +from Orange.widgets.credentials import CredentialManager from Orange.widgets.utils.itemmodels import DomainModel from Orange.widgets.settings import Setting, DomainContextHandler, \ ContextSetting @@ -52,7 +53,7 @@ class OWChatGPT(OWWidget): keywords = ["text", "gpt"] settingsHandler = DomainContextHandler() - access_key = Setting("") # TODO + access_key = "" model_index = Setting(0) text_var = ContextSetting(None) prompt_start = Setting("") @@ -76,12 +77,16 @@ def __init__(self): self.__start_text_edit: QTextEdit = None self.__end_text_edit: QTextEdit = None self.__answer_text_edit: QPlainTextEdit = None + + self.__cm = CredentialManager("Ask") + self.access_key = self.__cm.access_key or "" + self.setup_gui() def setup_gui(self): box = gui.vBox(self.controlArea, "Chat GPT") edit: QLineEdit = gui.lineEdit(box, self, "access_key", "Access key:", - callback=self.commit.deferred) + callback=self.__on_access_key_changed) edit.setEchoMode(QLineEdit.Password) gui.comboBox(box, self, "model_index", label="Model:", items=MODELS, callback=self.commit.deferred) @@ -112,6 +117,10 @@ def setup_gui(self): self.__answer_text_edit = QPlainTextEdit(readOnly=True) box.layout().addWidget(self.__answer_text_edit) + def __on_access_key_changed(self): + self.__cm.access_key = self.access_key + self.commit.deferred() + def __on_start_text_edit_changed(self): prompt_start = self.__start_text_edit.toPlainText() if self.prompt_start != prompt_start: From f4921c1f20b6b8f48134be788cbd5dc22ced88c9 Mon Sep 17 00:00:00 2001 From: Vesna Tanko Date: Fri, 12 May 2023 15:15:35 +0200 Subject: [PATCH 2/4] Chat GPT: Add system content to the model --- orangecontrib/prototypes/widgets/owchatgpt.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/orangecontrib/prototypes/widgets/owchatgpt.py b/orangecontrib/prototypes/widgets/owchatgpt.py index d9e5b475..723a6491 100644 --- a/orangecontrib/prototypes/widgets/owchatgpt.py +++ b/orangecontrib/prototypes/widgets/owchatgpt.py @@ -32,7 +32,10 @@ def run_gpt( content = f"{prompt_start}\n{text}.\n{prompt_end}" response = openai.ChatCompletion.create( model=model, - messages=[{"role": "user", "content": content}] + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": content}, + ] ) return response.choices[0].message.content From 1a30167b0245bf19f41b113330e2c8edf400b4d0 Mon Sep 17 00:00:00 2001 From: Vesna Tanko Date: Thu, 24 Aug 2023 14:37:07 +0200 Subject: [PATCH 3/4] Chat GPT: Nicer UI --- orangecontrib/prototypes/widgets/owchatgpt.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/orangecontrib/prototypes/widgets/owchatgpt.py b/orangecontrib/prototypes/widgets/owchatgpt.py index 723a6491..8fd41789 100644 --- a/orangecontrib/prototypes/widgets/owchatgpt.py +++ b/orangecontrib/prototypes/widgets/owchatgpt.py @@ -1,6 +1,6 @@ from typing import Optional -from AnyQt.QtCore import Signal +from AnyQt.QtCore import Signal, Qt from AnyQt.QtGui import QFocusEvent from AnyQt.QtWidgets import QPlainTextEdit, QLineEdit, QTextEdit @@ -87,16 +87,18 @@ def __init__(self): self.setup_gui() def setup_gui(self): - box = gui.vBox(self.controlArea, "Chat GPT") - edit: QLineEdit = gui.lineEdit(box, self, "access_key", "Access key:", + box = gui.vBox(self.controlArea, "Model") + edit: QLineEdit = gui.lineEdit(box, self, "access_key", "API Key:", + orientation=Qt.Horizontal, callback=self.__on_access_key_changed) edit.setEchoMode(QLineEdit.Password) gui.comboBox(box, self, "model_index", label="Model:", + orientation=Qt.Horizontal, items=MODELS, callback=self.commit.deferred) - gui.comboBox(self.controlArea, self, "text_var", "Options", - "Text field:", model=self.__text_var_model, - callback=self.commit.deferred) + gui.comboBox(self.controlArea, self, "text_var", "Data", + "Text variable:", model=self.__text_var_model, + orientation=Qt.Horizontal, callback=self.commit.deferred) box = gui.vBox(self.controlArea, "Prompt") gui.label(box, self, "Start:") From 9703bde999d91d11d3046afbe795dc4c25762912 Mon Sep 17 00:00:00 2001 From: Vesna Tanko Date: Thu, 24 Aug 2023 14:44:58 +0200 Subject: [PATCH 4/4] ChatGPT Summarize: Rename --- orangecontrib/prototypes/widgets/owchatgpt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/orangecontrib/prototypes/widgets/owchatgpt.py b/orangecontrib/prototypes/widgets/owchatgpt.py index 8fd41789..8afc19b2 100644 --- a/orangecontrib/prototypes/widgets/owchatgpt.py +++ b/orangecontrib/prototypes/widgets/owchatgpt.py @@ -49,8 +49,8 @@ def focusOutEvent(self, ev: QFocusEvent): class OWChatGPT(OWWidget): - name = "Chat GPT" - description = "Chat GPT." + name = "ChatGPT Summarize" + description = "Summarize content using a ChatGPT." icon = "icons/chatgpt.svg" priority = 10 keywords = ["text", "gpt"]