Fix failing tests and add safe json serializer
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import json
|
||||
from typing import List, Union
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
@@ -7,6 +6,7 @@ from letta.schemas.enums import MessageStreamStatus
|
||||
from letta.schemas.letta_message import LettaMessage
|
||||
from letta.schemas.message import Message
|
||||
from letta.schemas.usage import LettaUsageStatistics
|
||||
from letta.utils import json_dumps
|
||||
|
||||
# TODO: consider moving into own file
|
||||
|
||||
@@ -25,7 +25,7 @@ class LettaResponse(BaseModel):
|
||||
usage: LettaUsageStatistics = Field(..., description="The usage statistics of the agent.")
|
||||
|
||||
def __str__(self):
|
||||
return json.dumps(
|
||||
return json_dumps(
|
||||
{
|
||||
"messages": [message.model_dump() for message in self.messages],
|
||||
# Assume `Message` and `LettaMessage` have a `dict()` method
|
||||
|
||||
@@ -1058,7 +1058,12 @@ def create_uuid_from_string(val: str):
|
||||
|
||||
|
||||
def json_dumps(data, indent=2):
|
||||
return json.dumps(data, indent=indent, ensure_ascii=False)
|
||||
def safe_serializer(obj):
|
||||
if isinstance(obj, datetime):
|
||||
return obj.isoformat()
|
||||
raise TypeError(f"Type {type(obj)} not serializable")
|
||||
|
||||
return json.dumps(data, indent=indent, default=safe_serializer, ensure_ascii=False)
|
||||
|
||||
|
||||
def json_loads(data):
|
||||
|
||||
7386
openapi_letta.json
Normal file
7386
openapi_letta.json
Normal file
File diff suppressed because it is too large
Load Diff
6392
openapi_openai.json
Normal file
6392
openapi_openai.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -371,15 +371,10 @@ def assert_inner_monologue_is_valid(message: Message) -> None:
|
||||
"""
|
||||
Helper function to check that the inner monologue is valid.
|
||||
"""
|
||||
invalid_chars = "(){}[]"
|
||||
# Sometimes the syntax won't be correct and internal syntax will leak into message
|
||||
invalid_phrases = ["functions", "send_message"]
|
||||
invalid_phrases = ["functions", "send_message", "arguments"]
|
||||
|
||||
monologue = message.content
|
||||
for char in invalid_chars:
|
||||
if char in monologue:
|
||||
raise InvalidInnerMonologueError(messages=[message], explanation=f"{char} is in monologue")
|
||||
|
||||
for phrase in invalid_phrases:
|
||||
if phrase in monologue:
|
||||
raise InvalidInnerMonologueError(messages=[message], explanation=f"{phrase} is in monologue")
|
||||
|
||||
Reference in New Issue
Block a user