Further enhance this debate bot, and make it output unique responses. And also add…
- User
Further enhance this debate bot, and make it output unique responses. And also add further features:
code - Assistant
Further enhance this debate bot, and make it output unique responses. And also add further features:
import g4f.client
import tkinter as tk
from tkinter import ttk
import threading
# Configuration
GPT_MODEL = 'gpt-4o' # Or any other model suitable for debates
# Initialize the G4F client
gpt_client = g4f.client.Client()
# Debate history and guessed characters
debate_history = {}
guessed_characters = set()
# Custom format preset
FORMAT_PRESET = """
system
{{#if system}}{{system}}\n{{/if}}
{{#if wiBefore}}{{wiBefore}}\n{{/if}}
{{#if description}}{{description}}\n{{/if}}
{{#if personality}}{char}'s personality: {{personality}}\n{{/if}}
{{#if scenario}}Scenario: {{scenario}}\n{{/if}}
{{#if wiAfter}}{{wiAfter}}\n{{/if}}
{{#if persona}}{{persona}}\n{{/if}}
{{trim}}
"""
# Debate prompt
DEBATE_PROMPT = """
I'm going to give you an imaginary theoretically abduction prompt of who fights better. You're a smart API that will smartly debate on who fights better (fictional character, ver.) All guesses that aren't fictional characters are wrong and thereby banned, and also apply real-world applications.
["For Example: Goku fights better than Simpson"]
Make sure your arguments are consistent and consider the context of previous debates. You'll also have to only pick ONE fictional character that beats {character}, just like in the game "What beats rock?", but instead you can't pick the character that's already been chosen.
First Debate of the Day: What fights better than {character}?
"""
def generate_debate_prompt(character):
"""Generates a debate prompt using a custom format preset."""
# Prepare the data for formatting
format_data = {
'system': 'You are a debate AI specialized in comparing fictional characters based on their fighting abilities.',
'description': 'The debate focuses on who fights better among fictional characters. Provide detailed arguments.',
'personality': 'The debate AI should be assertive and analytical.',
'scenario': DEBATE_PROMPT.format(character=character),
'wiBefore': 'Consider the strengths and weaknesses of the characters involved.',
'wiAfter': 'Summarize the debate and conclude which character fights better. Ensure consistency with previous debates.',
'persona': f'Debate with a focus on {character}\'s abilities and real-world applications.',
}
# Format the prompt based on the format preset
formatted_prompt = FORMAT_PRESET
for key, value in format_data.items():
formatted_prompt = formatted_prompt.replace(f'{{{{{key}}}}}', value)
return formatted_prompt
def query_debate_ai(character):
"""Queries the debate AI for the best fighting fictional character."""
prompt = generate_debate_prompt(character)
response = gpt_client.chat.completions.create(
model=GPT_MODEL,
messages=[{"role": "user", "content": prompt}],
max_tokens=2048
)
result = response.choices[0].message.content
# Store the response in history
debate_history[character] = result
return result
def ensure_consistency(character, response):
"""Ensures consistency in the debate responses by checking against history."""
for opponent, previous_response in debate_history.items():
if opponent != character:
if character in previous_response:
# Check if the new response contradicts previous responses
if ("loses to" in previous_response and "beats" in response) or \
("beats" in previous_response and "loses to" in response):
return (f"Your previous response about {opponent} was inconsistent with the current debate about {character}. "
"Please review and adjust your response.")
return response
def filter_guessable_characters(character):
"""Filters out characters that have already been guessed or debated."""
if character in guessed_characters:
return "This character has already been debated. Please choose a different one."
# Add the new character to guessed characters
guessed_characters.add(character)
return None
def on_submit():
character = entry.get().strip()
if not character:
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, "Please enter a fictional character.")
return
# Filter out previously guessed characters
filtered_message = filter_guessable_characters(character)
if filtered_message:
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, filtered_message)
return
submit_button.config(state="disabled")
threading.Thread(target=process_input, args=(character,)).start()
def process_input(character):
response = query_debate_ai(character)
consistent_response = ensure_consistency(character, response)
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, consistent_response)
submit_button.config(state="normal")
root = tk.Tk()
root.title("Debate AI Bot")
style = ttk.Style()
style.theme_use("clam")
entry_frame = ttk.Frame(root, padding="10")
entry_frame.pack(fill=tk.BOTH, expand=True)
entry_label = ttk.Label(entry_frame, text="Enter Fictional Character:")
entry_label.grid(row=0, column=0, padx=5, pady=5)
entry = ttk.Entry(entry_frame, width=40)
entry.grid(row=0, column=1, padx=5, pady=5)
submit_button = ttk.Button(entry_frame, text="Submit", command=on_submit)
submit_button.grid(row=1, column=0, columnspan=2, pady=10)
result_frame = ttk.Frame(root, padding="10")
result_frame.pack(fill=tk.BOTH, expand=True)
result_text = tk.Text(result_frame, height=10, width=40, wrap=tk.WORD)
result_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
result_scroll_bar = ttk.Scrollbar(result_frame, orient=tk.VERTICAL, command=result_text.yview)
result_scroll_bar.pack(side=tk.RIGHT, fill=tk.Y)
result_text.config(yscrollcommand=result_scroll_bar.set)
root.mainloop()
Certainly! Enhancing your Debate AI Bot to produce more unique responses and adding additional features can significantly improve user experience and engagement. Below, I'll outline several enhancements and provide code snippets to implement them. The key enhancements include:
Let's go through each enhancement in detail.
To make the bot output unique responses, you can introduce variability in the prompts and adjust the AI's parameters such as temperature and top_p. Higher temperature values yield more creative and varied outputs.
temperature to make responses more diverse.Modify the query_debate_ai function to include parameters for uniqueness.
def query_debate_ai(character):
"""Queries the debate AI for the best fighting fictional character with unique responses."""
prompt = generate_debate_prompt(character)
response = gpt_client.chat.completions.create(
model=GPT_MODEL,
messages=[{"role": "user", "content": prompt}],
max_tokens=2048,
temperature=0.8, # Increased temperature for more creativity
top_p=0.9, # Adjusted top_p for diversity
frequency_penalty=0.5, # Penalize new tokens based on existing frequency
presence_penalty=0.3 # Encourage new topics
)
result = response.choices[0].message.content.strip()
# Store the response in history
debate_history[character] = result
return result
Persisting the debate history allows users to revisit past debates even after restarting the application.
debate_history to a JSON file.debate_history when the application starts.Add functions to save and load history.
import json
import os
HISTORY_FILE = "debate_history.json"
def save_debate_history():
"""Saves the debate history to a JSON file."""
with open(HISTORY_FILE, 'w') as f:
json.dump({
'debate_history': debate_history,
'guessed_characters': list(guessed_characters)
}, f, indent=4)
def load_debate_history():
"""Loads the debate history from a JSON file."""
global debate_history, guessed_characters
if os.path.exists(HISTORY_FILE):
with open(HISTORY_FILE, 'r') as f:
data = json.load(f)
debate_history = data.get('debate_history', {})
guessed_characters = set(data.get('guessed_characters', []))
Call load_debate_history() at the beginning of your script and save_debate_history() whenever the history is updated.
# Load history on startup
load_debate_history()
# Modify process_input to save history after processing
def process_input(character):
response = query_debate_ai(character)
consistent_response = ensure_consistency(character, response)
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, consistent_response)
submit_button.config(state="normal")
save_debate_history()
Allow users to view past debates within the application.
Add a new button and its corresponding functionality.
def view_history():
history_window = tk.Toplevel(root)
history_window.title("Debate History")
history_text = tk.Text(history_window, wrap=tk.WORD, width=80, height=20)
history_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
history_scroll = ttk.Scrollbar(history_window, orient=tk.VERTICAL, command=history_text.yview)
history_scroll.pack(side=tk.RIGHT, fill=tk.Y)
history_text.config(yscrollcommand=history_scroll.set)
if not debate_history:
history_text.insert(tk.END, "No debates have been conducted yet.")
else:
for character, debate in debate_history.items():
history_text.insert(tk.END, f"Debate: What fights better than {character}?\n")
history_text.insert(tk.END, f"{debate}\n\n")
# Add the "View History" button
history_button = ttk.Button(entry_frame, text="View History", command=view_history)
history_button.grid(row=2, column=0, columnspan=2, pady=5)
Provide an option to reset the debate history, allowing users to start fresh.
Implement the reset functionality.
from tkinter import messagebox
def reset_session():
if messagebox.askyesno("Reset Session", "Are you sure you want to reset the debate history?"):
global debate_history, guessed_characters
debate_history.clear()
guessed_characters.clear()
save_debate_history()
result_text.delete(1.0, tk.END)
messagebox.showinfo("Reset", "Debate history has been reset.")
# Add the "Reset Session" button
reset_button = ttk.Button(entry_frame, text="Reset Session", command=reset_session)
reset_button.grid(row=3, column=0, columnspan=2, pady=5)
Allow users to customize aspects of the AI's responses, such as tone (e.g., formal, casual) or length.
Add UI elements for customization and adjust prompt generation accordingly.
# Add customization options
custom_frame = ttk.LabelFrame(entry_frame, text="Customization", padding="10")
custom_frame.grid(row=4, column=0, columnspan=2, pady=10, sticky="ew")
# Tone selection
tone_label = ttk.Label(custom_frame, text="Tone:")
tone_label.grid(row=0, column=0, padx=5, pady=5, sticky="e")
tone_var = tk.StringVar(value="Assertive")
tone_options = ["Assertive", "Casual", "Humorous", "Formal"]
tone_menu = ttk.OptionMenu(custom_frame, tone_var, tone_var.get(), *tone_options)
tone_menu.grid(row=0, column=1, padx=5, pady=5, sticky="w")
# Length selection
length_label = ttk.Label(custom_frame, text="Response Length:")
length_label.grid(row=1, column=0, padx=5, pady=5, sticky="e")
length_var = tk.StringVar(value="Medium")
length_options = ["Short", "Medium", "Long"]
length_menu = ttk.OptionMenu(custom_frame, length_var, length_var.get(), *length_options)
length_menu.grid(row=1, column=1, padx=5, pady=5, sticky="w")
Update generate_debate_prompt to include these preferences.
def generate_debate_prompt(character):
"""Generates a debate prompt using a custom format preset."""
# Prepare the data for formatting
format_data = {
'system': 'You are a debate AI specialized in comparing fictional characters based on their fighting abilities.',
'description': 'The debate focuses on who fights better among fictional characters. Provide detailed arguments.',
'personality': f'The debate AI should be {tone_var.get().lower()} and analytical.',
'scenario': DEBATE_PROMPT.format(character=character),
'wiBefore': 'Consider the strengths and weaknesses of the characters involved.',
'wiAfter': 'Summarize the debate and conclude which character fights better. Ensure consistency with previous debates.',
'persona': f'Debate with a focus on {character}\'s abilities and real-world applications.',
'length': length_var.get()
}
# Adjust max_tokens based on length preference
if format_data['length'] == "Short":
max_tokens = 500
elif format_data['length'] == "Medium":
max_tokens = 1000
else:
max_tokens = 1500
# Format the prompt based on the format preset
formatted_prompt = FORMAT_PRESET
for key, value in format_data.items():
formatted_prompt = formatted_prompt.replace(f'{{{{{key}}}}}', value)
return formatted_prompt, max_tokens
def query_debate_ai(character):
"""Queries the debate AI for the best fighting fictional character with unique responses."""
prompt, max_tokens = generate_debate_prompt(character)
response = gpt_client.chat.completions.create(
model=GPT_MODEL,
messages=[{"role": "user", "content": prompt}],
max_tokens=max_tokens,
temperature=0.8, # Increased temperature for more creativity
top_p=0.9, # Adjusted top_p for diversity
frequency_penalty=0.5,
presence_penalty=0.3
)
result = response.choices[0].message.content.strip()
# Store the response in history
debate_history[character] = result
return result
def process_input(character):
response = query_debate_ai(character)
consistent_response = ensure_consistency(character, response)
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, consistent_response)
submit_button.config(state="normal")
save_debate_history()
Ensure the application handles API errors gracefully and informs the user accordingly.
Modify query_debate_ai and process_input to handle errors.
def query_debate_ai(character):
"""Queries the debate AI for the best fighting fictional character with unique responses."""
prompt, max_tokens = generate_debate_prompt(character)
try:
response = gpt_client.chat.completions.create(
model=GPT_MODEL,
messages=[{"role": "user", "content": prompt}],
max_tokens=max_tokens,
temperature=0.8, # Increased temperature for more creativity
top_p=0.9, # Adjusted top_p for diversity
frequency_penalty=0.5,
presence_penalty=0.3
)
result = response.choices[0].message.content.strip()
except Exception as e:
result = f"An error occurred while fetching the response: {str(e)}"
if "An error occurred" not in result:
# Store the response in history only if successful
debate_history[character] = result
return result
def process_input(character):
response = query_debate_ai(character)
if "An error occurred" not in response:
consistent_response = ensure_consistency(character, response)
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, consistent_response)
else:
# Display the error message directly
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, response)
submit_button.config(state="normal")
save_debate_history()
Improving the prompt can lead to more coherent, relevant, and unique responses. Here's how you can optimize it:
Revise the DEBATE_PROMPT and generate_debate_prompt functions.
DEBATE_PROMPT = """
I'm going to present a hypothetical debate about which fictional character fights better. You're an intelligent debate AI that will analyze and argue which character is superior in fighting abilities. All character comparisons should strictly involve fictional characters from any genre (e.g., anime, comics, movies, literature). Real-world individuals or non-fictional entities are not valid and should be disregarded.
["For Example: Goku fights better than Homer Simpson"]
Ensure your arguments are logical, well-structured, and consider the context of previous debates to maintain consistency. You must select ONE fictional character that outperforms {character} in combat. Similar to the game "What beats rock?", you cannot choose a character already selected in earlier debates.
First Debate of the Day: What fictional character fights better than {character}?
"""
def generate_debate_prompt(character):
"""Generates a debate prompt using a custom format preset."""
# Prepare the data for formatting
format_data = {
'system': 'You are a debate AI specialized in comparing fictional characters based on their fighting abilities.',
'description': 'The debate focuses on who fights better among fictional characters. Provide detailed and well-argued points.',
'personality': f'The debate AI should be {tone_var.get().lower()} and analytical.',
'scenario': DEBATE_PROMPT.format(character=character),
'wiBefore': 'Consider the strengths and weaknesses of the characters involved, referencing previous debates if applicable.',
'wiAfter': 'Summarize the debate and conclude which character fights better. Ensure consistency with previous debates.',
'persona': f'Debate with a focus on {character}\'s abilities and real-world applications.',
'length': length_var.get()
}
# Adjust max_tokens based on length preference
if format_data['length'] == "Short":
max_tokens = 500
elif format_data['length'] == "Medium":
max_tokens = 1000
else:
max_tokens = 1500
# Format the prompt based on the format preset
formatted_prompt = FORMAT_PRESET
for key, value in format_data.items():
formatted_prompt = formatted_prompt.replace(f'{{{{{key}}}}}', value)
return formatted_prompt, max_tokens
Below is the complete enhanced code integrating all the above modifications:
Unique Responses:
temperature and adjusted top_p to make responses more creative and varied.frequency_penalty and presence_penalty to encourage new topics and reduce repetition.New Features:
Optimized Prompt Engineering:
These enhancements should make your Debate AI Bot more robust, user-friendly, and capable of providing engaging and varied debates. You can further customize and expand upon these features based on user feedback and specific requirements.
Not yet included in a published release.
import g4f.client
import tkinter as tk
from tkinter import ttk, messagebox
import threading
import json
import os
# Configuration
GPT_MODEL = 'gpt-4o' # Or any other model suitable for debates
HISTORY_FILE = "debate_history.json"
# Initialize the G4F client
gpt_client = g4f.client.Client()
# Debate history and guessed characters
debate_history = {}
guessed_characters = set()
# Custom format preset
FORMAT_PRESET = """
system
{{#if system}}{{system}}\n{{/if}}
{{#if wiBefore}}{{wiBefore}}\n{{/if}}
{{#if description}}{{description}}\n{{/if}}
{{#if personality}}{char}'s personality: {{personality}}\n{{/if}}
{{#if scenario}}Scenario: {{scenario}}\n{{/if}}
{{#if wiAfter}}{{wiAfter}}\n{{/if}}
{{#if persona}}{{persona}}\n{{/if}}
{{trim}}
"""
# Debate prompt
DEBATE_PROMPT = """
I'm going to present a hypothetical debate about which fictional character fights better. You're an intelligent debate AI that will analyze and argue which character is superior in fighting abilities. All character comparisons should strictly involve fictional characters from any genre (e.g., anime, comics, movies, literature). Real-world individuals or non-fictional entities are not valid and should be disregarded.
["For Example: Goku fights better than Homer Simpson"]
Ensure your arguments are logical, well-structured, and consider the context of previous debates to maintain consistency. You must select ONE fictional character that outperforms {character} in combat. Similar to the game "What beats rock?", you cannot choose a character already selected in earlier debates.
First Debate of the Day: What fictional character fights better than {character}?
"""
def save_debate_history():
"""Saves the debate history to a JSON file."""
with open(HISTORY_FILE, 'w') as f:
json.dump({
'debate_history': debate_history,
'guessed_characters': list(guessed_characters)
}, f, indent=4)
def load_debate_history():
"""Loads the debate history from a JSON file."""
global debate_history, guessed_characters
if os.path.exists(HISTORY_FILE):
with open(HISTORY_FILE, 'r') as f:
data = json.load(f)
debate_history = data.get('debate_history', {})
guessed_characters = set(data.get('guessed_characters', []))
def generate_debate_prompt(character):
"""Generates a debate prompt using a custom format preset."""
# Prepare the data for formatting
format_data = {
'system': 'You are a debate AI specialized in comparing fictional characters based on their fighting abilities.',
'description': 'The debate focuses on who fights better among fictional characters. Provide detailed and well-argued points.',
'personality': f'The debate AI should be {tone_var.get().lower()} and analytical.',
'scenario': DEBATE_PROMPT.format(character=character),
'wiBefore': 'Consider the strengths and weaknesses of the characters involved, referencing previous debates if applicable.',
'wiAfter': 'Summarize the debate and conclude which character fights better. Ensure consistency with previous debates.',
'persona': f'Debate with a focus on {character}\'s abilities and real-world applications.',
'length': length_var.get()
}
# Adjust max_tokens based on length preference
if format_data['length'] == "Short":
max_tokens = 500
elif format_data['length'] == "Medium":
max_tokens = 1000
else:
max_tokens = 1500
# Format the prompt based on the format preset
formatted_prompt = FORMAT_PRESET
for key, value in format_data.items():
formatted_prompt = formatted_prompt.replace(f'{{{{{key}}}}}', value)
return formatted_prompt, max_tokens
def query_debate_ai(character):
"""Queries the debate AI for the best fighting fictional character with unique responses."""
prompt, max_tokens = generate_debate_prompt(character)
try:
response = gpt_client.chat.completions.create(
model=GPT_MODEL,
messages=[{"role": "user", "content": prompt}],
max_tokens=max_tokens,
temperature=0.8, # Increased temperature for more creativity
top_p=0.9, # Adjusted top_p for diversity
frequency_penalty=0.5,
presence_penalty=0.3
)
result = response.choices[0].message.content.strip()
except Exception as e:
result = f"An error occurred while fetching the response: {str(e)}"
if "An error occurred" not in result:
# Store the response in history
debate_history[character] = result
return result
def ensure_consistency(character, response):
"""Ensures consistency in the debate responses by checking against history."""
for opponent, previous_response in debate_history.items():
if opponent != character:
if character in previous_response:
# Check if the new response contradicts previous responses
if ("loses to" in previous_response and "beats" in response) or \
("beats" in previous_response and "loses to" in response):
return (f"Your previous response about {opponent} was inconsistent with the current debate about {character}. "
"Please review and adjust your response.")
return response
def filter_guessable_characters(character):
"""Filters out characters that have already been guessed or debated."""
if character in guessed_characters:
return "This character has already been debated. Please choose a different one."
# Add the new character to guessed characters
guessed_characters.add(character)
return None
def on_submit():
character = entry.get().strip()
if not character:
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, "Please enter a fictional character.")
return
# Filter out previously guessed characters
filtered_message = filter_guessable_characters(character)
if filtered_message:
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, filtered_message)
return
submit_button.config(state="disabled")
threading.Thread(target=process_input, args=(character,)).start()
def process_input(character):
response = query_debate_ai(character)
if "An error occurred" not in response:
consistent_response = ensure_consistency(character, response)
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, consistent_response)
else:
# Display the error message directly
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, response)
submit_button.config(state="normal")
save_debate_history()
def view_history():
history_window = tk.Toplevel(root)
history_window.title("Debate History")
history_text = tk.Text(history_window, wrap=tk.WORD, width=80, height=20)
history_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
history_scroll = ttk.Scrollbar(history_window, orient=tk.VERTICAL, command=history_text.yview)
history_scroll.pack(side=tk.RIGHT, fill=tk.Y)
history_text.config(yscrollcommand=history_scroll.set)
if not debate_history:
history_text.insert(tk.END, "No debates have been conducted yet.")
else:
for character, debate in debate_history.items():
history_text.insert(tk.END, f"Debate: What fictional character fights better than {character}?\n")
history_text.insert(tk.END, f"{debate}\n\n")
def reset_session():
if messagebox.askyesno("Reset Session", "Are you sure you want to reset the debate history?"):
global debate_history, guessed_characters
debate_history.clear()
guessed_characters.clear()
save_debate_history()
result_text.delete(1.0, tk.END)
messagebox.showinfo("Reset", "Debate history has been reset.")
# Load history on startup
load_debate_history()
root = tk.Tk()
root.title("Debate AI Bot")
style = ttk.Style()
style.theme_use("clam")
entry_frame = ttk.Frame(root, padding="10")
entry_frame.pack(fill=tk.BOTH, expand=True)
entry_label = ttk.Label(entry_frame, text="Enter Fictional Character:")
entry_label.grid(row=0, column=0, padx=5, pady=5, sticky="e")
entry = ttk.Entry(entry_frame, width=40)
entry.grid(row=0, column=1, padx=5, pady=5, sticky="w")
submit_button = ttk.Button(entry_frame, text="Submit", command=on_submit)
submit_button.grid(row=1, column=0, columnspan=2, pady=10)
# Add the "View History" button
history_button = ttk.Button(entry_frame, text="View History", command=view_history)
history_button.grid(row=2, column=0, columnspan=2, pady=5)
# Add the "Reset Session" button
reset_button = ttk.Button(entry_frame, text="Reset Session", command=reset_session)
reset_button.grid(row=3, column=0, columnspan=2, pady=5)
# Add customization options
custom_frame = ttk.LabelFrame(entry_frame, text="Customization", padding="10")
custom_frame.grid(row=4, column=0, columnspan=2, pady=10, sticky="ew")
# Tone selection
tone_label = ttk.Label(custom_frame, text="Tone:")
tone_label.grid(row=0, column=0, padx=5, pady=5, sticky="e")
tone_var = tk.StringVar(value="Assertive")
tone_options = ["Assertive", "Casual", "Humorous", "Formal"]
tone_menu = ttk.OptionMenu(custom_frame, tone_var, tone_var.get(), *tone_options)
tone_menu.grid(row=0, column=1, padx=5, pady=5, sticky="w")
# Length selection
length_label = ttk.Label(custom_frame, text="Response Length:")
length_label.grid(row=1, column=0, padx=5, pady=5, sticky="e")
length_var = tk.StringVar(value="Medium")
length_options = ["Short", "Medium", "Long"]
length_menu = ttk.OptionMenu(custom_frame, length_var, length_var.get(), *length_options)
length_menu.grid(row=1, column=1, padx=5, pady=5, sticky="w")
result_frame = ttk.Frame(root, padding="10")
result_frame.pack(fill=tk.BOTH, expand=True)
result_text = tk.Text(result_frame, height=15, width=80, wrap=tk.WORD)
result_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
result_scroll_bar = ttk.Scrollbar(result_frame, orient=tk.VERTICAL, command=result_text.yview)
result_scroll_bar.pack(side=tk.RIGHT, fill=tk.Y)
result_text.config(yscrollcommand=result_scroll_bar.set)
root.mainloop()