Skip to content

Commit

Permalink
added support for custom instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
AmberSahdev committed Mar 13, 2024
1 parent 28ba777 commit 33a1afa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
9 changes: 6 additions & 3 deletions app/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ def __init__(self):
with open(path_to_context_file, 'r') as file:
self.context = file.read()

if 'default_browser' in settings_dict.keys() and settings_dict['default_browser']:
self.context += f'\nDefault browser is {settings_dict["default_browser"]}.'

self.context += f' Locally installed apps are {",".join(local_info.locally_installed_apps)}.'
self.context += f' OS is {local_info.operating_system}.'
self.context += f' Primary screen size is {Screen().get_size()}.\n'

if 'default_browser' in settings_dict.keys() and settings_dict['default_browser']:
self.context += f'\nDefault browser is {settings_dict["default_browser"]}.'

if 'custom_llm_instructions' in settings_dict:
self.context += f'\nCustom user-added info: {settings_dict["custom_llm_instructions"]}.'

self.client = OpenAI()
self.model = 'gpt-4-vision-preview'

Expand Down
25 changes: 18 additions & 7 deletions app/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ def display_current_status(self, text: str):
class SettingsWindow(tk.Toplevel):
"""
Self-contained settings sub-window for the UI
TODO:
1. Add text box for custom LLM instructions to include with every request
"""

def __init__(self, parent):
super().__init__(parent)
self.title('Settings')
self.geometry('300x350')
self.minsize(300, 450)
self.create_widgets()

self.settings = Settings()
Expand All @@ -51,6 +48,8 @@ def __init__(self, parent):
self.browser_combobox.set(settings_dict['default_browser'])
if 'play_ding_on_completion' in settings_dict:
self.play_ding.set(1 if settings_dict['play_ding_on_completion'] else 0)
if 'custom_llm_instructions' in settings_dict:
self.llm_instructions_text.insert('1.0', settings_dict['custom_llm_instructions'])

def create_widgets(self) -> None:
# Label for API Key
Expand All @@ -72,6 +71,14 @@ def create_widgets(self) -> None:
self.browser_combobox.pack(pady=5)
self.browser_combobox.set('Choose Browser')

# Label for Custom LLM Instructions
label_llm = tk.Label(self, text='Custom LLM Instructions:')
label_llm.pack(pady=10)

# Text Box for Custom LLM Instructions
self.llm_instructions_text = tk.Text(self, height=5, width=40)
self.llm_instructions_text.pack(pady=5)

# Checkbox for "Play Ding" option
self.play_ding = tk.IntVar()
play_ding_checkbox = ttk.Checkbutton(self, text="Play Ding on Completion", variable=self.play_ding)
Expand All @@ -85,7 +92,7 @@ def create_widgets(self) -> None:
link_label = tk.Label(self, text='Instructions', fg='#499CE4')
link_label.pack()
link_label.bind('<Button-1>', lambda e: open_link(
'https://github.com/AmberSahdev/Open-Interface?tab=readme-ov-file#setup'))
'https://github.com/AmberSahdev/Open-Interface?tab=readme-ov-file#setup-%EF%B8%8F'))

# Version Label
version_label = tk.Label(self, text=f'Version: {str(version)}', font=('Helvetica', 10))
Expand All @@ -94,8 +101,12 @@ def create_widgets(self) -> None:
def save_button(self) -> None:
api_key = self.api_key_entry.get().strip()
default_browser = self.browser_var.get()
settings_dict = {'api_key': api_key, 'default_browser': default_browser,
'play_ding_on_completion': bool(self.play_ding.get())}
settings_dict = {
'api_key': api_key,
'default_browser': default_browser,
'play_ding_on_completion': bool(self.play_ding.get()),
'custom_llm_instructions': self.llm_instructions_text.get("1.0", "end-1c").strip()
}

self.settings.save_settings_to_file(settings_dict)
self.destroy()
Expand Down

0 comments on commit 33a1afa

Please sign in to comment.