refactor(gui): improve persona preferred models UI and remove embedded preset managers
This commit is contained in:
123
src/gui_2.py
123
src/gui_2.py
@@ -1271,14 +1271,15 @@ class App:
|
||||
"provider": self.current_provider,
|
||||
"model": self.current_model,
|
||||
"temperature": 0.7,
|
||||
"max_output_tokens": 4096
|
||||
"max_output_tokens": 4096,
|
||||
"history_trunc_limit": 900000
|
||||
}]
|
||||
self._editing_persona_scope = "project"
|
||||
self._editing_persona_is_new = True
|
||||
imgui.separator()
|
||||
personas = getattr(self.controller, 'personas', {})
|
||||
for name in sorted(personas.keys()):
|
||||
is_sel = (name == self._editing_persona_name and not self._editing_persona_is_new)
|
||||
is_sel = (name == self._editing_persona_name and not getattr(self, '_editing_persona_is_new', False))
|
||||
if imgui.selectable(name, is_sel)[0]:
|
||||
p = personas[name]
|
||||
self._editing_persona_name = p.name
|
||||
@@ -1306,73 +1307,99 @@ class App:
|
||||
_, self._editing_persona_name = imgui.input_text("##pname", self._editing_persona_name, 128)
|
||||
|
||||
imgui.text("Scope:")
|
||||
if imgui.radio_button("Global##pscope", self._editing_persona_scope == "global"):
|
||||
if imgui.radio_button("Global##pscope", getattr(self, '_editing_persona_scope', 'project') == "global"):
|
||||
self._editing_persona_scope = "global"
|
||||
imgui.same_line()
|
||||
if imgui.radio_button("Project##pscope", self._editing_persona_scope == "project"):
|
||||
if imgui.radio_button("Project##pscope", getattr(self, '_editing_persona_scope', 'project') == "project"):
|
||||
self._editing_persona_scope = "project"
|
||||
|
||||
imgui.separator()
|
||||
|
||||
imgui.text("Preferred Models:")
|
||||
providers = self.controller.PROVIDERS
|
||||
imgui.begin_child("pref_models_list", imgui.ImVec2(0, 150), True)
|
||||
if not hasattr(self, '_persona_pref_models_expanded'):
|
||||
self._persona_pref_models_expanded = {}
|
||||
imgui.begin_child("pref_models_list", imgui.ImVec2(0, 200), True)
|
||||
to_remove = []
|
||||
for i, entry in enumerate(self._editing_persona_preferred_models_list):
|
||||
imgui.push_id(f"pref_model_{i}")
|
||||
imgui.text(f"{i+1}.")
|
||||
|
||||
prov = entry.get("provider", "Unknown")
|
||||
mod = entry.get("model", "Unknown")
|
||||
is_expanded = self._persona_pref_models_expanded.get(i, False)
|
||||
|
||||
if imgui.button("-" if is_expanded else "+"):
|
||||
self._persona_pref_models_expanded[i] = not is_expanded
|
||||
imgui.same_line()
|
||||
|
||||
imgui.set_next_item_width(120)
|
||||
prov = entry.get("provider", "")
|
||||
p_idx = providers.index(prov) + 1 if prov in providers else 0
|
||||
changed_p, p_idx = imgui.combo("##prov", p_idx, ["None"] + providers)
|
||||
if changed_p:
|
||||
entry["provider"] = providers[p_idx-1] if p_idx > 0 else ""
|
||||
|
||||
imgui.same_line()
|
||||
imgui.set_next_item_width(200)
|
||||
curr_prov = entry.get("provider", "")
|
||||
m_list = self.controller.all_available_models.get(curr_prov, [])
|
||||
model = entry.get("model", "")
|
||||
m_idx = m_list.index(model) + 1 if model in m_list else 0
|
||||
changed_m, m_idx = imgui.combo("##model", m_idx, ["None"] + m_list)
|
||||
if changed_m:
|
||||
entry["model"] = m_list[m_idx-1] if m_idx > 0 else ""
|
||||
|
||||
imgui.same_line()
|
||||
imgui.text("T:")
|
||||
imgui.same_line()
|
||||
imgui.set_next_item_width(60)
|
||||
_, entry["temperature"] = imgui.input_float("##temp", entry.get("temperature", 0.7), 0.1, 0.1, "%.1f")
|
||||
|
||||
imgui.same_line()
|
||||
imgui.text("Max:")
|
||||
imgui.same_line()
|
||||
imgui.set_next_item_width(80)
|
||||
_, entry["max_output_tokens"] = imgui.input_int("##maxt", entry.get("max_output_tokens", 4096))
|
||||
|
||||
imgui.same_line()
|
||||
imgui.text(f"{i+1}. {prov} - {mod}")
|
||||
imgui.same_line(imgui.get_content_region_avail().x - 30)
|
||||
if imgui.button("x"):
|
||||
to_remove.append(i)
|
||||
|
||||
if is_expanded:
|
||||
imgui.indent(20)
|
||||
|
||||
imgui.text("Provider:")
|
||||
imgui.same_line()
|
||||
imgui.set_next_item_width(150)
|
||||
p_idx = providers.index(prov) + 1 if prov in providers else 0
|
||||
changed_p, p_idx = imgui.combo("##prov", p_idx, ["None"] + providers)
|
||||
if changed_p:
|
||||
entry["provider"] = providers[p_idx-1] if p_idx > 0 else ""
|
||||
|
||||
imgui.same_line()
|
||||
imgui.text("Model:")
|
||||
imgui.same_line()
|
||||
imgui.set_next_item_width(250)
|
||||
curr_prov = entry.get("provider", "")
|
||||
m_list = self.controller.all_available_models.get(curr_prov, [])
|
||||
m_idx = m_list.index(mod) + 1 if mod in m_list else 0
|
||||
changed_m, m_idx = imgui.combo("##model", m_idx, ["None"] + m_list)
|
||||
if changed_m:
|
||||
entry["model"] = m_list[m_idx-1] if m_idx > 0 else ""
|
||||
|
||||
imgui.text("Temperature:")
|
||||
imgui.same_line()
|
||||
imgui.set_next_item_width(100)
|
||||
_, entry["temperature"] = imgui.input_float("##temp", entry.get("temperature", 0.7), 0.1, 0.1, "%.1f")
|
||||
|
||||
imgui.same_line()
|
||||
imgui.text("Max Output Tokens:")
|
||||
imgui.same_line()
|
||||
imgui.set_next_item_width(100)
|
||||
_, entry["max_output_tokens"] = imgui.input_int("##maxt", entry.get("max_output_tokens", 4096))
|
||||
|
||||
imgui.text("History Truncation Limit:")
|
||||
imgui.same_line()
|
||||
imgui.set_next_item_width(100)
|
||||
_, entry["history_trunc_limit"] = imgui.input_int("##hist", entry.get("history_trunc_limit", 900000))
|
||||
|
||||
imgui.unindent(20)
|
||||
imgui.dummy(imgui.ImVec2(0, 4))
|
||||
imgui.pop_id()
|
||||
for i in reversed(to_remove):
|
||||
self._editing_persona_preferred_models_list.pop(i)
|
||||
if i in self._persona_pref_models_expanded:
|
||||
del self._persona_pref_models_expanded[i]
|
||||
imgui.end_child()
|
||||
|
||||
if imgui.button("Add Preferred Model"):
|
||||
idx = len(self._editing_persona_preferred_models_list)
|
||||
self._editing_persona_preferred_models_list.append({
|
||||
"provider": self.current_provider,
|
||||
"model": self.current_model,
|
||||
"temperature": 0.7,
|
||||
"max_output_tokens": 4096
|
||||
"max_output_tokens": 4096,
|
||||
"history_trunc_limit": 900000
|
||||
})
|
||||
self._persona_pref_models_expanded[idx] = True
|
||||
|
||||
imgui.separator()
|
||||
imgui.text("Tool Preset:")
|
||||
imgui.same_line()
|
||||
t_preset_names = ["None"] + sorted(self.controller.tool_presets.keys())
|
||||
t_idx = t_preset_names.index(self._editing_persona_tool_preset_id) if self._editing_persona_tool_preset_id in t_preset_names else 0
|
||||
t_idx = t_preset_names.index(self._editing_persona_tool_preset_id) if getattr(self, '_editing_persona_tool_preset_id', '') in t_preset_names else 0
|
||||
imgui.push_item_width(200)
|
||||
_, t_idx = imgui.combo("##ptoolpreset", t_idx, t_preset_names)
|
||||
self._editing_persona_tool_preset_id = t_preset_names[t_idx] if t_idx > 0 else ""
|
||||
@@ -1382,16 +1409,15 @@ class App:
|
||||
imgui.text("Bias Profile:")
|
||||
imgui.same_line()
|
||||
bias_names = ["None"] + sorted(self.controller.bias_profiles.keys())
|
||||
b_idx = bias_names.index(self._editing_persona_bias_profile_id) if self._editing_persona_bias_profile_id in bias_names else 0
|
||||
b_idx = bias_names.index(self._editing_persona_bias_profile_id) if getattr(self, '_editing_persona_bias_profile_id', '') in bias_names else 0
|
||||
imgui.push_item_width(200)
|
||||
_, b_idx = imgui.combo("##pbiasprofile", b_idx, bias_names)
|
||||
self._editing_persona_bias_profile_id = bias_names[b_idx] if b_idx > 0 else ""
|
||||
imgui.pop_item_width()
|
||||
|
||||
if imgui.collapsing_header("Manage Tool Presets & Biases"):
|
||||
imgui.begin_child("tool_preset_embedded", imgui.ImVec2(0, 300), True)
|
||||
self._render_tool_preset_manager_content(is_embedded=True)
|
||||
imgui.end_child()
|
||||
imgui.same_line()
|
||||
if imgui.button("Manage Tools##p_tools"):
|
||||
self.show_tool_preset_manager_window = True
|
||||
|
||||
imgui.separator()
|
||||
imgui.text("System Prompt:")
|
||||
@@ -1412,10 +1438,9 @@ class App:
|
||||
self._editing_persona_system_prompt = p.system_prompt
|
||||
self._load_preset_idx = 0
|
||||
|
||||
if imgui.collapsing_header("Manage Prompt Presets"):
|
||||
imgui.begin_child("prompt_preset_embedded", imgui.ImVec2(0, 200), True)
|
||||
self._render_preset_manager_content(is_embedded=True)
|
||||
imgui.end_child()
|
||||
imgui.same_line()
|
||||
if imgui.button("Manage Prompts##p_prompts"):
|
||||
self.show_preset_manager_window = True
|
||||
|
||||
_, self._editing_persona_system_prompt = imgui.input_text_multiline("##pprompt", self._editing_persona_system_prompt, imgui.ImVec2(-1, 150))
|
||||
|
||||
@@ -1433,7 +1458,7 @@ class App:
|
||||
bias_profile=self._editing_persona_bias_profile_id or None,
|
||||
preferred_models=save_models,
|
||||
)
|
||||
self.controller._cb_save_persona(persona, self._editing_persona_scope)
|
||||
self.controller._cb_save_persona(persona, getattr(self, '_editing_persona_scope', 'project'))
|
||||
self.ai_status = f"Saved Persona: {persona.name}"
|
||||
except Exception as e:
|
||||
self.ai_status = f"Error saving persona: {e}"
|
||||
@@ -1445,7 +1470,7 @@ class App:
|
||||
imgui.same_line()
|
||||
if imgui.button("Delete", imgui.ImVec2(100, 0)):
|
||||
if not getattr(self, '_editing_persona_is_new', True) and self._editing_persona_name:
|
||||
self.controller._cb_delete_persona(self._editing_persona_name, self._editing_persona_scope)
|
||||
self.controller._cb_delete_persona(self._editing_persona_name, getattr(self, '_editing_persona_scope', 'project'))
|
||||
self.ai_status = f"Deleted Persona: {self._editing_persona_name}"
|
||||
self._editing_persona_name = ""
|
||||
self._editing_persona_is_new = True
|
||||
|
||||
Reference in New Issue
Block a user