mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-27 01:11:40 +00:00
Merge PR #225: fix: preserve empty content in ReadResult.to_dict()
Authored by Farukest. Fixes #224.
This commit is contained in:
commit
39bfd226b8
2 changed files with 10 additions and 2 deletions
|
|
@ -67,10 +67,18 @@ class TestReadResult:
|
||||||
def test_to_dict_omits_defaults(self):
|
def test_to_dict_omits_defaults(self):
|
||||||
r = ReadResult()
|
r = ReadResult()
|
||||||
d = r.to_dict()
|
d = r.to_dict()
|
||||||
assert "content" not in d # empty string omitted
|
|
||||||
assert "error" not in d # None omitted
|
assert "error" not in d # None omitted
|
||||||
assert "similar_files" not in d # empty list omitted
|
assert "similar_files" not in d # empty list omitted
|
||||||
|
|
||||||
|
def test_to_dict_preserves_empty_content(self):
|
||||||
|
"""Empty file should still have content key in the dict."""
|
||||||
|
r = ReadResult(content="", total_lines=0, file_size=0)
|
||||||
|
d = r.to_dict()
|
||||||
|
assert "content" in d
|
||||||
|
assert d["content"] == ""
|
||||||
|
assert d["total_lines"] == 0
|
||||||
|
assert d["file_size"] == 0
|
||||||
|
|
||||||
def test_to_dict_includes_values(self):
|
def test_to_dict_includes_values(self):
|
||||||
r = ReadResult(content="hello", total_lines=10, file_size=50, truncated=True)
|
r = ReadResult(content="hello", total_lines=10, file_size=50, truncated=True)
|
||||||
d = r.to_dict()
|
d = r.to_dict()
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class ReadResult:
|
||||||
similar_files: List[str] = field(default_factory=list)
|
similar_files: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
return {k: v for k, v in self.__dict__.items() if v is not None and v != [] and v != ""}
|
return {k: v for k, v in self.__dict__.items() if v is not None and v != []}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue