Merge branch 'master' of https://gitea.ditaajipratama.net/aji/hendrik
This commit is contained in:
commit
d9ee874f51
@ -51,8 +51,7 @@ class HendrikTUI:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def new_session(self):
|
def new_session(self):
|
||||||
name = f"Session {datetime.now().strftime('%Y-%m-%d %H:%M')}"
|
self.current_session = None
|
||||||
self.current_session = self.session_mgr.create(name, self._model_info())
|
|
||||||
self.messages = [{"role": "system", "content": self.build_system_prompt(
|
self.messages = [{"role": "system", "content": self.build_system_prompt(
|
||||||
tools_definition=self.tools_def,
|
tools_definition=self.tools_def,
|
||||||
character=config.AGENT_CHARACTER or None,
|
character=config.AGENT_CHARACTER or None,
|
||||||
@ -60,6 +59,9 @@ class HendrikTUI:
|
|||||||
)}]
|
)}]
|
||||||
self.log.clear()
|
self.log.clear()
|
||||||
self.scroll = 0
|
self.scroll = 0
|
||||||
|
self.input_buffer = [""]
|
||||||
|
self.input_line = 0
|
||||||
|
self.input_col = 0
|
||||||
log(self, "welcome", WELCOME_ART)
|
log(self, "welcome", WELCOME_ART)
|
||||||
|
|
||||||
def switch_session(self, doc_id: int):
|
def switch_session(self, doc_id: int):
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user