add handle_exception

This commit is contained in:
seehi 2024-09-12 13:52:50 +08:00
parent ea9582cf0e
commit a16535fb08

View file

@ -7,13 +7,14 @@
@Modified By: mashenquan, 2023-11-1. According to RFC 116: Updated the type of index key.
"""
from collections import defaultdict
from typing import DefaultDict, Iterable, Set
from typing import DefaultDict, Iterable, Optional, Set
from pydantic import BaseModel, Field, SerializeAsAny
from metagpt.const import IGNORED_MESSAGE_ID
from metagpt.schema import Message
from metagpt.utils.common import any_to_str, any_to_str_set
from metagpt.utils.exceptions import handle_exception
class Memory(BaseModel):
@ -105,6 +106,7 @@ class Memory(BaseModel):
rsp += self.index[action]
return rsp
def get_by_position(self, position: int) -> Message:
"""Return the message by its position"""
@handle_exception
def get_by_position(self, position: int) -> Optional[Message]:
"""Returns the message at the given position if valid, otherwise returns None"""
return self.storage[position]