feat: ade support for showing errored messages in ade
This commit is contained in:
@@ -63,13 +63,13 @@ class LettaMessage(BaseModel):
|
|||||||
dt = dt.replace(tzinfo=timezone.utc)
|
dt = dt.replace(tzinfo=timezone.utc)
|
||||||
return dt.isoformat(timespec="seconds")
|
return dt.isoformat(timespec="seconds")
|
||||||
|
|
||||||
@field_serializer("is_err", when_used="unless-none")
|
@field_serializer("is_err", mode="wrap")
|
||||||
def serialize_is_err(self, value: bool | None, _info):
|
def serialize_is_err(self, value: bool | None, handler, _info):
|
||||||
"""
|
"""
|
||||||
Only serialize is_err field when it's True (for debugging purposes).
|
Only serialize is_err field when it's True (for debugging purposes).
|
||||||
When is_err is None or False, this field will be excluded from the JSON output.
|
When is_err is None or False, this field will be excluded from the JSON output.
|
||||||
"""
|
"""
|
||||||
return value if value is True else None
|
return handler(value) if value is True else None
|
||||||
|
|
||||||
|
|
||||||
class SystemMessage(LettaMessage):
|
class SystemMessage(LettaMessage):
|
||||||
|
|||||||
@@ -269,6 +269,7 @@ class Message(BaseMessage):
|
|||||||
otid=otid,
|
otid=otid,
|
||||||
sender_id=self.sender_id,
|
sender_id=self.sender_id,
|
||||||
step_id=self.step_id,
|
step_id=self.step_id,
|
||||||
|
is_err=self.is_err,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# Otherwise, we may have a list of multiple types
|
# Otherwise, we may have a list of multiple types
|
||||||
@@ -287,6 +288,7 @@ class Message(BaseMessage):
|
|||||||
otid=otid,
|
otid=otid,
|
||||||
sender_id=self.sender_id,
|
sender_id=self.sender_id,
|
||||||
step_id=self.step_id,
|
step_id=self.step_id,
|
||||||
|
is_err=self.is_err,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif isinstance(content_part, ReasoningContent):
|
elif isinstance(content_part, ReasoningContent):
|
||||||
@@ -301,6 +303,7 @@ class Message(BaseMessage):
|
|||||||
name=self.name,
|
name=self.name,
|
||||||
otid=otid,
|
otid=otid,
|
||||||
step_id=self.step_id,
|
step_id=self.step_id,
|
||||||
|
is_err=self.is_err,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif isinstance(content_part, RedactedReasoningContent):
|
elif isinstance(content_part, RedactedReasoningContent):
|
||||||
@@ -315,6 +318,7 @@ class Message(BaseMessage):
|
|||||||
otid=otid,
|
otid=otid,
|
||||||
sender_id=self.sender_id,
|
sender_id=self.sender_id,
|
||||||
step_id=self.step_id,
|
step_id=self.step_id,
|
||||||
|
is_err=self.is_err,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif isinstance(content_part, OmittedReasoningContent):
|
elif isinstance(content_part, OmittedReasoningContent):
|
||||||
@@ -328,6 +332,7 @@ class Message(BaseMessage):
|
|||||||
name=self.name,
|
name=self.name,
|
||||||
otid=otid,
|
otid=otid,
|
||||||
step_id=self.step_id,
|
step_id=self.step_id,
|
||||||
|
is_err=self.is_err,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -355,6 +360,7 @@ class Message(BaseMessage):
|
|||||||
otid=otid,
|
otid=otid,
|
||||||
sender_id=self.sender_id,
|
sender_id=self.sender_id,
|
||||||
step_id=self.step_id,
|
step_id=self.step_id,
|
||||||
|
is_err=self.is_err,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -371,6 +377,7 @@ class Message(BaseMessage):
|
|||||||
otid=otid,
|
otid=otid,
|
||||||
sender_id=self.sender_id,
|
sender_id=self.sender_id,
|
||||||
step_id=self.step_id,
|
step_id=self.step_id,
|
||||||
|
is_err=self.is_err,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self.role == MessageRole.tool:
|
elif self.role == MessageRole.tool:
|
||||||
@@ -416,6 +423,7 @@ class Message(BaseMessage):
|
|||||||
otid=Message.generate_otid_from_id(self.id, len(messages)),
|
otid=Message.generate_otid_from_id(self.id, len(messages)),
|
||||||
sender_id=self.sender_id,
|
sender_id=self.sender_id,
|
||||||
step_id=self.step_id,
|
step_id=self.step_id,
|
||||||
|
is_err=self.is_err,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self.role == MessageRole.user:
|
elif self.role == MessageRole.user:
|
||||||
@@ -437,6 +445,7 @@ class Message(BaseMessage):
|
|||||||
otid=self.otid,
|
otid=self.otid,
|
||||||
sender_id=self.sender_id,
|
sender_id=self.sender_id,
|
||||||
step_id=self.step_id,
|
step_id=self.step_id,
|
||||||
|
is_err=self.is_err,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self.role == MessageRole.system:
|
elif self.role == MessageRole.system:
|
||||||
|
|||||||
@@ -125,14 +125,7 @@ class StreamingResponseWithStatusCode(StreamingResponse):
|
|||||||
if not isinstance(content, bytes):
|
if not isinstance(content, bytes):
|
||||||
content = content.encode(self.charset)
|
content = content.encode(self.charset)
|
||||||
more_body = False
|
more_body = False
|
||||||
await send(
|
raise Exception(f"An exception occurred mid-stream with status code {status_code} with content {content}")
|
||||||
{
|
|
||||||
"type": "http.response.body",
|
|
||||||
"body": content,
|
|
||||||
"more_body": more_body,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
raise Exception(f"An exception occurred mid-stream with status code {status_code}", detail={"content": content})
|
|
||||||
else:
|
else:
|
||||||
content = chunk
|
content = chunk
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user