|
8 | 8 | import random |
9 | 9 | import json |
10 | 10 | from ailice.common.AConfig import config |
| 11 | +from ailice.common.AExceptions import AExceptionStop |
11 | 12 | from ailice.common.utils.ALogger import ALoggerSection, ALoggerMsg |
12 | 13 | from ailice.core.AConversation import AConversations |
13 | 14 | from ailice.core.AInterpreter import AInterpreter |
@@ -133,20 +134,30 @@ def __call__(self, txt: str) -> str: |
133 | 134 | self.SaveMsg(role="ASSISTANT", msg=ret, storeMsg=ret) |
134 | 135 | self.result = ret |
135 | 136 |
|
136 | | - msg = self.messenger.GetPreviousMsg() |
137 | | - if msg != None: |
138 | | - resp = f"Interruption. Reminder from super user: {msg}" |
139 | | - self.SaveMsg(role="SYSTEM", msg=resp, storeMsg=resp, loggerMsg=resp, logger=loggerSection) |
140 | | - continue |
141 | | - |
142 | | - resp = self.interpreter.EvalEntries(ret) |
143 | | - |
144 | | - if "" != resp: |
145 | | - self.interpreter.EvalVar(varName="returned_content_in_last_function_call", content=resp) |
146 | | - m = "This is a system-generated message. Since the function call in your previous message has returned information, the response to this message will be handled by the backend system instead of the user. Meanwhile, your previous message has been marked as private and has not been sent to the user. Function returned: {" + resp + "}\n\nThe returned text has been automatically saved to variable 'returned_content_in_last_function_call' for quick reference." |
147 | | - self.SaveMsg(role="SYSTEM", msg=m, storeMsg="Function returned: {" + resp + "}", logMsg=resp, logger=loggerSection) |
148 | | - else: |
149 | | - return self.result |
| 137 | + try: |
| 138 | + msg = self.messenger.GetPreviousMsg() |
| 139 | + if (str == type(msg)) and ("/stop" == msg.strip()): |
| 140 | + raise AExceptionStop() |
| 141 | + elif msg != None: |
| 142 | + resp = f"Interruption. Reminder from super user: {msg}" |
| 143 | + self.SaveMsg(role="SYSTEM", msg=resp, storeMsg=resp, loggerMsg=resp, logger=loggerSection) |
| 144 | + continue |
| 145 | + |
| 146 | + resp = self.interpreter.EvalEntries(ret) |
| 147 | + |
| 148 | + if "" != resp: |
| 149 | + self.interpreter.EvalVar(varName="returned_content_in_last_function_call", content=resp) |
| 150 | + m = "This is a system-generated message. Since the function call in your previous message has returned information, the response to this message will be handled by the backend system instead of the user. Meanwhile, your previous message has been marked as private and has not been sent to the user. Function returned: {" + resp + "}\n\nThe returned text has been automatically saved to variable 'returned_content_in_last_function_call' for quick reference." |
| 151 | + self.SaveMsg(role="SYSTEM", msg=m, storeMsg="Function returned: {" + resp + "}", logMsg=resp, logger=loggerSection) |
| 152 | + else: |
| 153 | + return self.result |
| 154 | + except AExceptionStop as e: |
| 155 | + resp = "Interruption. The task was terminated by the superuser." |
| 156 | + self.SaveMsg(role="SYSTEM", msg=resp, storeMsg=resp, logMsg=resp, logger=loggerSection) |
| 157 | + |
| 158 | + resp = "I will stop here due to the superuser's request to terminate the task." |
| 159 | + self.SaveMsg(role="ASSISTANT", msg=resp, storeMsg=resp, logMsg=resp, logger=loggerSection) |
| 160 | + raise e |
150 | 161 |
|
151 | 162 | def EvalCall(self, agentType: str, agentName: str, msg: str) -> str: |
152 | 163 | if agentType not in self.promptsManager: |
|
0 commit comments