From 6113bf88ea0d7f374774249d5c277cf5f5b0875d Mon Sep 17 00:00:00 2001 From: "Seung-been \"Steven\" Lee" Date: Wed, 24 May 2023 13:39:40 +0900 Subject: [PATCH] Add files --- kanu/__main__.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ kanu/version.py | 1 + setup.py | 18 ++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 kanu/__main__.py create mode 100644 kanu/version.py create mode 100644 setup.py diff --git a/kanu/__main__.py b/kanu/__main__.py new file mode 100644 index 0000000..cf50da8 --- /dev/null +++ b/kanu/__main__.py @@ -0,0 +1,56 @@ +import tkinter as tk +from tkinter import messagebox + +import openai + +from .version import __version__ + +def get_input(entry): + user_input = entry.get() + openai.api_key = user_input + +def send_message(chat_log, entry, messages): + if openai.api_key is None: + messagebox.showerror("Error", "OpenAI API Key is not set.") + return + + message = entry.get() + messages += [{"role": "user", "content": message}] + bot_response = openai.ChatCompletion.create( + model='gpt-3.5-turbo', + messages=messages, + ) + response = bot_response["choices"][0]["message"]["content"] + messages += [{"role": "assistant", "content": response}] + chat_log.insert(tk.END, "\nYou: " + message) + chat_log.insert(tk.END, "\nBot: " + response) + entry.delete(0, tk.END) + +def main(): + root = tk.Tk() + root.title(f"KANU ({__version__})") + root.geometry("800x700") + label = tk.Label(root, text="OpenAI API Key") + label.pack() + + openai_api_key_entry = tk.Entry(root) + openai_api_key_entry.pack() + + openai_api_key_button = tk.Button(root, text="Submit", command=lambda: get_input(openai_api_key_entry)) + openai_api_key_button.pack() + + messages = [{"role": "system", "content": "You are a helpful assistant."}] + + chat_log = tk.Text(root, width=70, height=20) + chat_log.pack() + + chat_entry = tk.Entry(root, width=50) + chat_entry.pack() + + chat_send_button = tk.Button(root, text="Send", command=lambda: send_message(chat_log, chat_entry, messages)) + chat_send_button.pack() + + root.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/kanu/version.py b/kanu/version.py new file mode 100644 index 0000000..a68927d --- /dev/null +++ b/kanu/version.py @@ -0,0 +1 @@ +__version__ = "0.1.0" \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8018a52 --- /dev/null +++ b/setup.py @@ -0,0 +1,18 @@ +from setuptools import setup, find_packages + +exec(open("kanu/version.py").read()) + +setup( + name="kanu", + version=__version__, + author='Seung-been "Steven" Lee', + author_email="sbstevenlee@gmail.com", + description="KANU", + url="https://github.com/sbslee/kanu", + packages=find_packages(), + install_requires=["openai"], + license="MIT", + entry_points={"console_scripts": ["kanu=kanu.__main__:main"]}, + long_description="This is a detailed description of the package.", + long_description_content_type="text/plain" +) \ No newline at end of file