Skip to content

Commit

Permalink
[Log]rm list message (#289)
Browse files Browse the repository at this point in the history
* rm list message

* rm pdb
  • Loading branch information
Southpika committed Jan 12, 2024
1 parent 0fc495e commit 4ef47ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 34 deletions.
31 changes: 8 additions & 23 deletions erniebot-agent/src/erniebot_agent/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,18 @@ def format(self, record):
log_message += to_pretty_json(output)
return log_message

def extract_content(self, text: Union[List[Message], Message, str], output: list) -> List[dict]:
def extract_content(self, text: Union[Message, str], output: list) -> List[dict]:
"""Extract the content from message and convert to json format."""
if isinstance(text, list):
# List of messages
chat_lis = []
func_lis = []
for i in range(len(text)):
if isinstance(text[i], Message):
chat_res, func_res = self.handle_message(text[i])
chat_lis.append(chat_res)
if func_res:
func_lis.append(func_res)
output += [{"conversation": chat_lis.copy()}]
if func_lis:
output += [{"function_call": func_lis.copy()}]
return output

elif isinstance(text, str):
# Only handle Message Type
return []
else:
if isinstance(text, Message):
# Message type
chat_res, func_res = self.handle_message(text)
output += [{"conversation": [chat_res]}]
output += [chat_res]
if func_res:
output += [{"function_call": [func_res]}]
return output
elif isinstance(text, str):
# Only handle Message Type
return []

def handle_message(self, message):
if isinstance(message, FunctionMessage):
Expand Down Expand Up @@ -190,9 +175,9 @@ def setup_logging(
set_role_color()

log_file_path = C.get_logging_file_path()
if log_file_path is None:
log_file_path = "erniebot-agent.log"
if use_file_handler or log_file_path:
if log_file_path is None:
log_file_path = "erniebot-agent.log"
file_handler = logging.FileHandler(log_file_path)
file_handler.setFormatter(FileFormatter("%(message)s"))
logger.addHandler(file_handler)
Expand Down
15 changes: 4 additions & 11 deletions erniebot-agent/src/erniebot_agent/utils/output_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List, Optional, Union
from typing import Optional, Union

from erniebot_agent.memory.messages import Message
from erniebot_agent.utils.json import to_pretty_json
Expand All @@ -36,7 +36,7 @@ class ColoredContent:

def __init__(
self,
text: Union[str, Message, List[Message]],
text: Union[str, Message],
role: Optional[str] = None,
color: Optional[str] = None,
):
Expand Down Expand Up @@ -78,16 +78,9 @@ def _colorize_text(self, text: str, color: Optional[str]) -> str:
else:
return _COLORS[color] + str(text) + _COLORS["RESET"]

def _colorize_msg(self, message: Union[Message, List[Message]], role_color: dict) -> str:
def _colorize_msg(self, message: Message, role_color: dict) -> str:
max_length = self.max_length if self.max_length else 150
res = ""
if isinstance(message, list):
for msg in message:
res += self._colorize_msg_by_role(msg, role_color, max_length)
res += "\n"
else:
res = self._colorize_msg_by_role(message, role_color, max_length)
return res
return self._colorize_msg_by_role(message, role_color, max_length)

def _colorize_msg_by_role(self, msg: Message, role_color: dict, max_length: int):
res = ""
Expand Down

0 comments on commit 4ef47ec

Please sign in to comment.