mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-10-10 03:30:56 +00:00
[dev] refresh print
This commit is contained in:
parent
cffeac8565
commit
89498c6c3b
4 changed files with 20 additions and 17 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import datetime
|
||||
import os
|
||||
import time
|
||||
from typing import List
|
||||
|
||||
|
|
@ -105,7 +106,9 @@ class CliMemoryChat(BaseMemoryChat):
|
|||
while True:
|
||||
time.sleep(refresh_time)
|
||||
result = self.memory_service.do_operation(op_name=query)
|
||||
questionary.print(result, flush=True)
|
||||
os.system('clear')
|
||||
self.print_logo()
|
||||
questionary.print(result)
|
||||
|
||||
else:
|
||||
questionary.print("unknown command received. Please try again!")
|
||||
|
|
@ -121,8 +124,7 @@ class CliMemoryChat(BaseMemoryChat):
|
|||
|
||||
while True:
|
||||
try:
|
||||
query = questionary.text(message="user:", multiline=False, qmark=">").ask()
|
||||
|
||||
query = questionary.text(message="user:", multiline=False, qmark=">").unsafe_ask()
|
||||
if not query:
|
||||
continue
|
||||
|
||||
|
|
@ -149,7 +151,7 @@ class CliMemoryChat(BaseMemoryChat):
|
|||
|
||||
except KeyboardInterrupt:
|
||||
questionary.print("User interrupt occurred.")
|
||||
is_exit = questionary.confirm("continue exit?").ask()
|
||||
is_exit = questionary.confirm("continue exit").unsafe_ask()
|
||||
if is_exit:
|
||||
self.memory_service.stop_service()
|
||||
break
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from memory_scope.chat.global_context import G_CONTEXT
|
|||
from memory_scope.enumeration.language_enum import LanguageEnum
|
||||
from memory_scope.utils.logger import Logger
|
||||
from memory_scope.utils.tool_functions import init_instance_by_config
|
||||
from memory_scope.utils.timer import timer
|
||||
|
||||
|
||||
class CliJob(object):
|
||||
|
|
@ -35,6 +36,7 @@ class CliJob(object):
|
|||
G_CONTEXT.language = LanguageEnum(global_config["language"])
|
||||
G_CONTEXT.thread_pool = ThreadPoolExecutor(max_workers=int(global_config["max_workers"]))
|
||||
|
||||
@timer
|
||||
def init_global_content_by_config(self):
|
||||
# set global config
|
||||
self.set_global_config()
|
||||
|
|
@ -63,6 +65,7 @@ class CliJob(object):
|
|||
def run(self, config: str):
|
||||
self.load_config(config)
|
||||
self.init_global_content_by_config()
|
||||
|
||||
with G_CONTEXT.thread_pool:
|
||||
memory_chat = list(G_CONTEXT.memory_chat_dict.values())[0]
|
||||
memory_chat.run()
|
||||
|
|
|
|||
|
|
@ -9,4 +9,4 @@ class DummyWorker(BaseWorker):
|
|||
workflow_name = self.get_context(WORKFLOW_NAME)
|
||||
self.logger.info(f"enter workflow={workflow_name}.dummy_worker!")
|
||||
ts = int(datetime.datetime.now().timestamp())
|
||||
self.set_context(RESULT, f"test {workflow_name} ts={ts}")
|
||||
self.set_context(RESULT, f"test {workflow_name} \nts={ts}")
|
||||
|
|
|
|||
|
|
@ -4,16 +4,13 @@ import time
|
|||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
from importlib import import_module
|
||||
from typing import get_args
|
||||
|
||||
import pyfiglet
|
||||
from termcolor import colored, COLORS
|
||||
from termcolor._types import Color
|
||||
|
||||
from memory_scope.constants.common_constants import WEEKDAYS
|
||||
from memory_scope.enumeration.message_role_enum import MessageRoleEnum
|
||||
|
||||
ALL_COLORS = get_args(COLORS)
|
||||
|
||||
def under_line_to_hump(underline_str):
|
||||
sub = re.sub(r"(_\w)", lambda x: x.group(1)[1].upper(), underline_str)
|
||||
|
|
@ -39,7 +36,8 @@ def init_instance_by_config(config: dict, default_class_path: str = "memory_scop
|
|||
module = import_module(".".join(class_paths))
|
||||
|
||||
cls_name = under_line_to_hump(class_name)
|
||||
return getattr(module, cls_name)(**config_copy, **kwargs)
|
||||
config_copy.update(kwargs)
|
||||
return getattr(module, cls_name)(**config_copy)
|
||||
|
||||
|
||||
def complete_config_name(config_name: str, suffix: str = ".json"):
|
||||
|
|
@ -76,16 +74,16 @@ def get_datetime_info_dict(parse_dt: datetime):
|
|||
}
|
||||
|
||||
|
||||
def time_to_formatted_str(time: datetime | str | int | float = None,
|
||||
def time_to_formatted_str(dt: datetime | str | int | float = None,
|
||||
date_format: str = "%Y%m%d", # e.g. %Y%m%d -> "20240528", add %H:%M:%S
|
||||
string_format: str = "") -> str:
|
||||
|
||||
if isinstance(time, str | int | float):
|
||||
if isinstance(time, str):
|
||||
time = float(time)
|
||||
current_dt = datetime.fromtimestamp(time)
|
||||
elif isinstance(time, datetime):
|
||||
current_dt = time
|
||||
if isinstance(dt, str | int | float):
|
||||
if isinstance(dt, str):
|
||||
dt = float(dt)
|
||||
current_dt = datetime.fromtimestamp(dt)
|
||||
elif isinstance(dt, datetime):
|
||||
current_dt = dt
|
||||
else:
|
||||
current_dt = datetime.now()
|
||||
|
||||
|
|
@ -98,7 +96,7 @@ def time_to_formatted_str(time: datetime | str | int | float = None,
|
|||
return return_str
|
||||
|
||||
|
||||
def char_logo(words: str, seed: int = time.time_ns(), color: Color = None):
|
||||
def char_logo(words: str, seed: int = time.time_ns(), color=None):
|
||||
font = pyfiglet.Figlet()
|
||||
rendered_text = font.renderText(words)
|
||||
colored_lines = []
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue