From a04f6e5e87784a1aca2d4ffbad400811ad63cf41 Mon Sep 17 00:00:00 2001 From: Anton Dubovik Date: Mon, 18 Sep 2023 14:38:38 +0100 Subject: [PATCH] Fixed SAST findings --- client/client_adapter.py | 6 +++++- client/client_bedrock.py | 13 ++++++++++--- utils/input.py | 5 +++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/client/client_adapter.py b/client/client_adapter.py index cbfe026..fe202ff 100644 --- a/client/client_adapter.py +++ b/client/client_adapter.py @@ -73,7 +73,11 @@ def main(): input = make_input() - while True: + turn = 0 + max_turns = 128 + while turn < max_turns: + turn += 1 + content = input() if content == ":clear": history = [] diff --git a/client/client_bedrock.py b/client/client_bedrock.py index cc038ab..5b34f19 100755 --- a/client/client_bedrock.py +++ b/client/client_bedrock.py @@ -8,7 +8,8 @@ from utils.cli import choose_deployment from utils.env import get_env from utils.init import init -from utils.printing import get_input, print_ai, print_info +from utils.input import make_input +from utils.printing import print_ai, print_info async def main(): @@ -24,8 +25,14 @@ async def main(): history: List[Message] = [] - while True: - content = get_input("> ") + input = make_input() + + turn = 0 + max_turns = 128 + while turn < max_turns: + turn += 1 + + content = input() history.append(Message(role="user", content=content)) response = await model.achat(chat_emulation_type, history) diff --git a/utils/input.py b/utils/input.py index 8418603..d38364c 100644 --- a/utils/input.py +++ b/utils/input.py @@ -5,7 +5,7 @@ from utils.files import get_project_root -def make_input(): +def make_input(limit: int = 8000): session = None def input(prompt_text="> ", style=Style.from_dict({"": "#ff0000"})): @@ -15,6 +15,7 @@ def input(prompt_text="> ", style=Style.from_dict({"": "#ff0000"})): history=FileHistory(str(get_project_root() / ".history")) ) - return session.prompt(prompt_text, style=style) + response = session.prompt(prompt_text, style=style) + return response[:limit] return input