Skip to content

Commit

Permalink
Config Tool: AI Config Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiannis128 committed Feb 20, 2024
1 parent 4c6bd07 commit 0059f4e
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions esbmc_ai_config/contexts/ai_config_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from typing_extensions import override

import urwid

from esbmc_ai.ai_models import AIModels

from esbmc_ai_config.models.config_manager import ConfigManager
from esbmc_ai_config.context_manager import ContextManager
from esbmc_ai_config.context import Context
from esbmc_ai_config.contexts.base_menu import BaseMenu
from esbmc_ai_config.contexts.esbmc_menu.esbmc_manage import ESBMCManage
from esbmc_ai_config.widgets.text_input_button import TextInputButton
from esbmc_ai_config.models.config_manager import ConfigManager
from esbmc_ai_config.contexts.list_select_dialog import ListSelectDialog


class AIConfigMenu(BaseMenu):
Expand All @@ -16,11 +19,37 @@ def __init__(self) -> None:

def _get_menu_choices(self) -> list[str | urwid.Widget]:
return [
"AI Model",
urwid.AttrMap(
urwid.Button(
"AI Model",
on_press=self._open_ai_model_dialog,
),
None,
"reversed",
),
"Temperature",
"API Request Cooldown",
]

def _open_ai_model_dialog(self, button: urwid.Button) -> None:
# Get built-in AI models.
options: list[str] = [ai_model.value.name for ai_model in AIModels]
ai_model = ConfigManager.json_config.get_value("ai_model")
current_option: int = 0
if isinstance(ai_model, str):
current_option = options.index(ai_model)
# TODO Load custom AI models
dialog: Context = ListSelectDialog(
title="AI Model",
options=options,
initial_choice=current_option,
item_selected=lambda ai_model: ConfigManager.json_config.set_value(
ai_model, "ai_model"
),
)

ContextManager.push_context(dialog)

@override
def build_ui(self) -> urwid.Widget:
self.choices = self._get_menu_choices()
Expand Down

0 comments on commit 0059f4e

Please sign in to comment.