Skip to content

Commit

Permalink
Merge pull request #738 from RS-labhub/main
Browse files Browse the repository at this point in the history
Quine Quest 011 Submision
  • Loading branch information
doberst authored May 17, 2024
2 parents d8754db + b42f37f commit 908c50a
Show file tree
Hide file tree
Showing 19 changed files with 601 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Quest/Chatbot/.github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
1 change: 1 addition & 0 deletions Quest/Chatbot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/__pycache__
Binary file added Quest/Chatbot/Assets/Chatbot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Quest/Chatbot/Assets/Classic Gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Quest/Chatbot/Assets/Classic_Interface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Quest/Chatbot/Assets/LLMWARE CHatBot Preview.mp4
Binary file not shown.
Binary file added Quest/Chatbot/Assets/Models.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Quest/Chatbot/Assets/Modern GUI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Quest/Chatbot/Assets/Modern_Interface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Quest/Chatbot/Assets/RS LOGO.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Quest/Chatbot/Assets/author.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 128 additions & 0 deletions Quest/Chatbot/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[email protected].
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series
of actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
25 changes: 25 additions & 0 deletions Quest/Chatbot/Chatbot Application/chatbot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from llmware.models import ModelCatalog
from llmware.prompts import Prompt

def simple_chatbot(model_name):
model = Prompt().load_model(model_name)

print(f"Chatbot initialized with model: {model_name}")

while True:
user_input = input("You: ")

output = model.prompt_main(user_input,
prompt_name="default_with_context",
temperature=0.30)
bot_response = output["llm_response"].strip("\n")

print("Bot:", bot_response)

if user_input.lower() == 'quit':
print("Exiting chatbot...")
break

if __name__ == "__main__":
model_name = "phi-3-gguf"
simple_chatbot(model_name)
124 changes: 124 additions & 0 deletions Quest/Chatbot/Chatbot UI/ChatbotGUI_Modern.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import customtkinter as ctk
from tkinter import LEFT, RIGHT, BOTH, X, Y, END, WORD
from llmware.prompts import Prompt


class Chatbot:

def __init__(self, root, model):
self.model = model
self.root = root
self.root.title("LLMWARE Chatbot Interface")
self.root.geometry("400x600")
self.root.overrideredirect(True) # Remove default title bar

ctk.set_appearance_mode("dark") # Modes: system (default), light, dark
ctk.set_default_color_theme(
"dark-blue"
) # Themes: blue (default), dark-blue, green

# Create custom title bar
self.title_bar = ctk.CTkFrame(self.root, height=30, corner_radius=0)
self.title_bar.pack(fill=X)

self.title_label = ctk.CTkLabel(
self.title_bar, text="LLMWARE Chatbot Interface", anchor="w", padx=10
)
self.title_label.pack(side=LEFT, fill=Y)

self.minimize_button = ctk.CTkButton(
self.title_bar, text="_", width=30, command=self.minimize_window
)
self.minimize_button.pack(side=RIGHT, padx=(0, 5), pady=(5, 0))

self.close_button = ctk.CTkButton(
self.title_bar, text="X", width=30, command=self.close_window
)
self.close_button.pack(side=RIGHT, padx=(0, 5), pady=(5, 0))

self.chat_frame = ctk.CTkFrame(root)
self.chat_frame.pack(expand=True, fill=BOTH, padx=10, pady=(0, 10))

self.chat_display = ctk.CTkTextbox(
self.chat_frame,
wrap=WORD,
state="disabled",
fg_color="#333333",
text_color="white",
)
self.chat_display.pack(expand=True, fill=BOTH, padx=10, pady=10)

self.input_frame = ctk.CTkFrame(root)
self.input_frame.pack(side=ctk.BOTTOM, fill=X, padx=10, pady=10)

self.input_entry = ctk.CTkEntry(
self.input_frame, placeholder_text="Type your message here..."
)
self.input_entry.pack(side=LEFT, expand=True, fill=X, padx=(0, 10))

self.send_button = ctk.CTkButton(
self.input_frame, text="Send", command=self.send_message
)
self.send_button.pack(side=RIGHT)

self.previous_sender = None # To keep track of the previous message sender

self.make_window_draggable()

def make_window_draggable(self):
self.title_bar.bind("<Button-1>", self.start_move)
self.title_bar.bind("<B1-Motion>", self.do_move)
self.title_bar.bind("<ButtonRelease-1>", self.stop_move)

def start_move(self, event):
self.x = event.x
self.y = event.y

def do_move(self, event):
deltax = event.x - self.x
deltay = event.y - self.y
new_x = self.root.winfo_x() + deltax
new_y = self.root.winfo_y() + deltay
self.root.geometry(f"+{new_x}+{new_y}")

def stop_move(self, event):
self.x = None
self.y = None

def minimize_window(self):
self.root.iconify()

def close_window(self):
self.root.destroy()

def send_message(self):
message = self.input_entry.get().strip()
if message != "":
self.chat_display.configure(state="normal")
if self.previous_sender == "Bot":
self.chat_display.insert(END, "\n\n")
self.chat_display.insert(END, "You: " + message + "\n")
self.chat_display.insert(
END, "Bot: " + self.generate_bot_response(message) + "\n\n"
)
self.chat_display.configure(state="disabled")
self.chat_display.see(END) # Scroll to the end
self.input_entry.delete(0, END)
self.previous_sender = "You"

def generate_bot_response(self, user_message="Hi"):
model = Prompt().load_model(self.model)

output = model.prompt_main(
user_message, prompt_name="default_with_context", temperature=0.30
)
bot_response = output["llm_response"].strip("\n")
# bot_response = output["llm_response"].strip("\n").split("\n")[0]

return bot_response


if __name__ == "__main__":
root = ctk.CTk()
app = Chatbot(root, "phi-3-gguf")
root.mainloop()
63 changes: 63 additions & 0 deletions Quest/Chatbot/Chatbot UI/ChatbotGUI_Old.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import tkinter as tk
from tkinter import scrolledtext
from llmware.models import ModelCatalog
from llmware.prompts import Prompt

class ChatbotUI:
def __init__(self, root):
self.root = root
self.root.title("LLMWARE Chatbot Interface")

self.chat_frame = tk.Frame(root)
self.chat_frame.pack(expand=True, fill=tk.BOTH)

self.chat_display = scrolledtext.ScrolledText(self.chat_frame, wrap=tk.WORD)
self.chat_display.pack(expand=True, fill=tk.BOTH)

self.input_frame = tk.Frame(root, bg="lightgray")
self.input_frame.pack(side=tk.BOTTOM, fill=tk.X)

self.input_entry = tk.Entry(self.input_frame)
self.input_entry.pack(side=tk.LEFT, expand=True, fill=tk.X)

self.send_button = tk.Button(self.input_frame, text="Send", command=self.send_message)
self.send_button.pack(side=tk.RIGHT)

self.previous_sender = None

def send_message():
user_input = entry.get()
chat_history.insert(tk.END, f"You: {user_input}\n")
chat_history.yview(tk.END) # Scroll to the bottom
entry.delete(0, tk.END) # Clear the entry field

# Get bot response
output = model.prompt_main(user_input, prompt_name="default_with_context", temperature=0.30)
bot_response = output["llm_response"].strip("\n")

# Display bot response
chat_history.insert(tk.END, f"Bot: {bot_response}\n\n")
chat_history.yview(tk.END) # Scroll to the bottom

# Create main window
root = tk.Tk()
root.title("LLMWARE Chatbot Interface")

# Load the model
model_name = "phi-3-gguf"
model = Prompt().load_model(model_name)

# Create chat history window
chat_history = tk.Text(root, width=50, height=15)
chat_history.grid(row=0, column=0, padx=10, pady=10, columnspan=2)

# Create entry field for user input
entry = tk.Entry(root, width=40)
entry.grid(row=1, column=0, padx=10, pady=10)

# Create send button
send_button = tk.Button(root, text="Send", width=8, command=send_message)
send_button.grid(row=1, column=1, padx=10, pady=10)

# Start the GUI event loop
root.mainloop()
Loading

0 comments on commit 908c50a

Please sign in to comment.