Output if session db have no model info

This commit is contained in:
Dita Aji Pratama 2026-06-18 11:57:35 +07:00
parent dd4c6c674d
commit 85523c7f6b

View File

@ -5,8 +5,6 @@
import curses import curses
import json import json
import os import os
import textwrap
import config
# -- Color pair IDs (id 1-9, id 0 = default curses) -- # -- Color pair IDs (id 1-9, id 0 = default curses) --
C_HEADER = 1 # header bar: biru C_HEADER = 1 # header bar: biru
@ -90,21 +88,21 @@ def draw_chat(app, stdscr):
rendered.append(segments) rendered.append(segments)
def _add_blank(): def _add_blank():
rendered.append([(None, "")]) rendered.append([(None, "", False)])
def _wrap_render(text, indent=0, color=C_INPUT): def _wrap_render(text, indent=0, color=C_INPUT, bold=False):
available = w - indent - 1 # sisakan 1 kolom margin kanan available = w - indent - 1 # sisakan 1 kolom margin kanan
if available <= 0: if available <= 0:
_add_row([(color, " " * indent)]) _add_row([(color, " " * indent, bold)])
return return
for line in text.split("\n"): for line in text.split("\n"):
if not line: if not line:
_add_row([(color, " " * indent)]) _add_row([(color, " " * indent, bold)])
continue continue
start = 0 start = 0
while start < len(line): while start < len(line):
chunk = line[start:start + available] chunk = line[start:start + available]
_add_row([(color, " " * indent + chunk)]) _add_row([(color, " " * indent + chunk, bold)])
start += available start += available
for idx, item in enumerate(app.log): for idx, item in enumerate(app.log):
@ -130,21 +128,20 @@ def draw_chat(app, stdscr):
model_info = item.get("model_info", None) model_info = item.get("model_info", None)
if model_info: if model_info:
p_name, m_name = model_info p_name, m_name = model_info
if p_name:
info_line = f" {p_name} - {m_name} "
else:
info_line = f" {m_name} "
else: else:
p_name = config.resolve_provider(app.llm.base_url, app.llm.model) info_line = " Unknown - Model info not found "
m_name = app.llm.model _add_row([(C_USER, info_line, False)])
if p_name:
info_line = f" {p_name} - {m_name} "
else:
info_line = f" {m_name} "
_add_row([(C_USER, info_line)])
label = f" You ({item['time']}) " label = f" You ({item['time']}) "
_add_row([(C_USER, label)]) _add_row([(C_USER, label)])
_wrap_render(text, indent=1, color=C_INPUT) _wrap_render(text, indent=1, color=C_INPUT, bold=False)
elif role == "ai": elif role == "ai":
label = f" Hendrik ({item['time']}) " label = f" Hendrik ({item['time']}) "
_add_row([(C_AI, label)]) _add_row([(C_AI, label)])
_wrap_render(text, indent=1, color=C_INPUT) _wrap_render(text, indent=1, color=C_INPUT, bold=False)
elif role == "system": elif role == "system":
lines = text.split("\n") lines = text.split("\n")
_add_row([(C_SYSTEM, lines[0])]) _add_row([(C_SYSTEM, lines[0])])
@ -218,10 +215,11 @@ def draw_chat(app, stdscr):
for i in range(app.scroll, min(app.scroll + chat_h, total)): for i in range(app.scroll, min(app.scroll + chat_h, total)):
segments = rendered[i] segments = rendered[i]
x = 0 x = 0
for color, text in segments: for color, text, *bold_flag in segments:
if not text: if not text:
continue continue
attr = curses.color_pair(color) | curses.A_BOLD if color else curses.A_NORMAL is_bold = bold_flag[0] if bold_flag else True
attr = curses.color_pair(color) | (curses.A_BOLD if is_bold else 0) if color else curses.A_NORMAL
remaining = w - x remaining = w - x
if remaining <= 0: if remaining <= 0:
break break