Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

63 fine tune sequence classification model #76

Merged
merged 6 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/.archive/Basic-GPT-GUI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import sys

# Load environment variables from the root-level .env file
env_path = os.path.join(os.path.dirname(__file__), '/.env')
env_path = os.path.join(os.path.dirname(__file__), "/.env")
load_dotenv(find_dotenv(env_path))

# Add the src/ directory to the sys.path to import modules from it
src_dir = os.path.join(os.path.dirname(__file__), 'src')
src_dir = os.path.join(os.path.dirname(__file__), "src")
sys.path.append(src_dir)

# Import and run the main function from gui.py (or any entry point in the src/ directory)
from gui import main

if __name__ == '__main__':
main()
if __name__ == "__main__":
main()
78 changes: 45 additions & 33 deletions .github/.archive/Basic-GPT-GUI/src/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@

# Setting up logging
logging.basicConfig(
filename='app.log',
filemode='a',
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
filename="app.log",
filemode="a",
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.INFO,
)

# Setting up panel
pn.extension()
_ = load_dotenv(find_dotenv()) # read local .env file
_ = load_dotenv(find_dotenv()) # read local .env file

# Initialize OpenAI API key
openai.api_key = os.getenv('OPENAI_API_KEY')
openai.api_key = os.getenv("OPENAI_API_KEY")


class ChatApplication(tk.Tk):
""" Main GUI Application
"""
"""Main GUI Application"""

def __init__(self, chat_model, messages=None, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
if messages is None:
messages = []
self.title("Chatbot")
self.configure(bg='white')
self.configure(bg="white")
self.chat_model = chat_model
self.chat_model.add_initial_message(messages)

# Role variable for checkbutton
self.role_var = tk.StringVar()
self.role_var.set('user')
self.role_var.set("user")

# Make window rounded
self.attributes('-alpha', 0.9)
self['bg']='white'
self.attributes("-alpha", 0.9)
self["bg"] = "white"

self.setup_ui()

Expand All @@ -58,44 +58,61 @@ def get_response(self, role, message):
messages=self.messages,
temperature=self.temperature,
)
return response.choices[0].message["content"] # type: ignore
return response.choices[0].message["content"] # type: ignore

# Reset conversation
def reset_conversation(self):
self.messages = []

# Add initial messages
def add_initial_messages(self, messages):
self.messages.extend(messages)

# Setup UI
def setup_ui(self):
self.geometry('800x600') # Increase window size
self.geometry("800x600") # Increase window size

self.top_frame = tk.Frame(self, bg='white')
self.top_frame = tk.Frame(self, bg="white")
self.top_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True)

self.model_label = tk.Label(self.top_frame, text=f"Model: {self.chat_model.model}", bg='white', fg='black')
self.model_label = tk.Label(
self.top_frame,
text=f"Model: {self.chat_model.model}",
bg="white",
fg="black",
)
self.model_label.pack(side=tk.LEFT, padx=5, pady=5)

self.text_area = scrolledtext.ScrolledText(self.top_frame, wrap = tk.WORD, width=40, height=10, font =("Arial", 15))
self.text_area = scrolledtext.ScrolledText(
self.top_frame, wrap=tk.WORD, width=40, height=10, font=("Arial", 15)
)
self.text_area.pack(side=tk.TOP, fill=tk.BOTH, expand=True, padx=5, pady=5)

self.bottom_frame = tk.Frame(self, bg='white')
self.bottom_frame = tk.Frame(self, bg="white")
self.bottom_frame.pack(side=tk.BOTTOM, fill=tk.X)

self.message_entry = tk.Entry(self.bottom_frame, width=30, font=("Arial", 15))
self.message_entry.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=5, pady=5)
self.message_entry.bind("<Return>", self.send_message)

self.send_button = tk.Button(self.bottom_frame, text="Send", command=self.send_message)
self.send_button = tk.Button(
self.bottom_frame, text="Send", command=self.send_message
)
self.send_button.pack(side=tk.LEFT, padx=5, pady=5)

self.reset_button = tk.Button(self.bottom_frame, text="Reset", command=self.reset_conversation)
self.reset_button = tk.Button(
self.bottom_frame, text="Reset", command=self.reset_conversation
)
self.reset_button.pack(side=tk.LEFT, padx=5, pady=5)

# Role selection
self.role_button = ttk.Checkbutton(self.bottom_frame, text="System", onvalue='system', offvalue='user', variable=self.role_var)
self.role_button = ttk.Checkbutton(
self.bottom_frame,
text="System",
onvalue="system",
offvalue="user",
variable=self.role_var,
)
self.role_button.pack(side=tk.LEFT, padx=5, pady=5)

# Send message to chatbot
Expand All @@ -121,8 +138,8 @@ def send_message(self, event=None):
self.text_area.config(state=tk.DISABLED)
logging.info(f"User: {message}, Bot: {response}")
except Exception as e:
messagebox.showerror("Error", str(e))
logging.error(f"Error while getting response: {str(e)}")
messagebox.showerror("Error", str(e))
logging.error(f"Error while getting response: {str(e)}")

# Reset conversation
def reset_conversation(self):
Expand All @@ -146,15 +163,10 @@ def reset_conversation(self):
- Your main job is to assist the user with whatever they're working on.\
- Await user input for further instructions.
"""
# Aggregate data into a list for the chatbot to use
messages = [
{
"role": "system",
"content": Instructions
}
]
# Aggregate data into a list for the chatbot to use
messages = [{"role": "system", "content": Instructions}]

# Initialize the chatbot
chat_model = OpenAI_Chat()
app = ChatApplication(chat_model, messages) # pass messages as the second argument
app.mainloop()
app.mainloop()
6 changes: 5 additions & 1 deletion .github/.archive/Basic-GPT-GUI/src/openai_chat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class OpenAI_Chat:
def __init__(self, model=os.getenv('MODEL', 'gpt-3.5-turbo'), temperature=os.getenv('TEMPERATURE', .5)):
def __init__(
self,
model=os.getenv("MODEL", "gpt-3.5-turbo"),
temperature=os.getenv("TEMPERATURE", 0.5),
):
self.model = model
self.temperature = float(temperature)
self.messages = []
Loading
Loading