Skip to content

Commit 4fa77c0

Browse files
committed
1. replace the current page index with prior/remaining.
2. added some separator lines to distinguish between function execution results and prompts.
1 parent 8752e60 commit 4fa77c0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

ailice/modules/AScripter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def UpdateSession(self, session: str):
8787
p = f"Exception when check the output of program execution: {str(e)}\n {traceback.format_exc()}"
8888
print(p)
8989
finally:
90-
self.sessions[session]['pages'].LoadPage(self.sessions[session]['output'] + p, "BOTTOM")
90+
self.sessions[session]['pages'].LoadPage(self.sessions[session]['output'] + "---" + p, "BOTTOM")
9191

9292
def OutputReader(self):
9393
while True:

ailice/modules/AScrollablePage.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ def __init__(self, functions: dict[str, str]):
99
return
1010

1111
def ConstructPrompt(self) -> str:
12-
pagesTotal = int((len(self.txt) + STEP) // STEP)
13-
pageIdx = min(max(int((self.currentIdx + int(STEP/2)) // STEP) + 1, 1), pagesTotal)
1412
ret = "To avoid excessive consumption of context space due to lengthy content, we have paginated the entire content. This is just one page, to browse more content, please use the following function(s) for page navigation.\n"
1513
funcs = []
1614
if ('SCROLLDOWN' in self.functions) and (self.currentIdx + STEP < len(self.txt)):
@@ -21,7 +19,12 @@ def ConstructPrompt(self) -> str:
2119
funcs.append(self.functions['SEARCHDOWN'])
2220
if ('SEARCHUP' in self.functions) and (self.currentIdx > 0):
2321
funcs.append(self.functions['SEARCHUP'])
24-
return f"page {pageIdx}/{pagesTotal}\n\n" + ret + "\n".join(funcs) if len(funcs) > 0 else ""
22+
pos = self.currentIdx
23+
pos = 0 if pos < 0 else pos
24+
pos = (len(self.txt) - STEP) if pos > (len(self.txt) - STEP) else pos
25+
prior = (float(pos)/float(len(self.txt))) * 100
26+
remaining = (float(len(self.txt) - pos - STEP)/float(len(self.txt))) * 100
27+
return f"Prior: {prior:.1f}% / Remaining: {remaining:.1f}% \n\n" + ret + "\n".join(funcs) if len(funcs) > 0 else ""
2528

2629
def LoadPage(self, txt: str, initPosition: str):
2730
self.txt = txt
@@ -65,4 +68,4 @@ def __call__(self, prompt: bool = True) -> str:
6568
else:
6669
start = self.currentIdx if self.currentIdx >= 0 else 0
6770
end = (self.currentIdx + STEP) if (self.currentIdx + STEP) >= 0 else 0
68-
return self.txt[start:end] + ("\n\n" + self.ConstructPrompt() if prompt else "")
71+
return "\n\n---\n\n" + self.txt[start:end] + ("\n\n---\n\n" + self.ConstructPrompt() if prompt else "")

0 commit comments

Comments
 (0)