Skip to content

Commit

Permalink
Fix issue in PromptSummaryEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
vachillo committed Aug 27, 2024
1 parent ef61c53 commit 853dd2b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Parsing streaming response with some OpenAi compatible services.
- Issue in `PromptSummaryEngine` if there are no artifacts during recursive summarization.

**Note**: This release includes breaking changes. Please refer to the [Migration Guide](./MIGRATION.md#030x-to-031x) for details.

Expand Down
5 changes: 5 additions & 0 deletions griptape/engines/summary/prompt_summary_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def summarize_artifacts_rec(
summary: Optional[str] = None,
rulesets: Optional[list[Ruleset]] = None,
) -> TextArtifact:
if not artifacts:
if summary is None:
raise ValueError("No artifacts to summarize")
return TextArtifact(summary)

artifacts_text = self.chunk_joiner.join([a.to_text() for a in artifacts])

system_prompt = self.system_template_generator.render(
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/engines/summary/test_prompt_summary_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ def copy_test_resource(resource_path: str):
return Path(full_path).read_text()

assert engine.summarize_text(copy_test_resource("test.txt") * 50)

def test_summarize_artifacts_rec_no_artifacts(self, engine):
with pytest.raises(ValueError):
engine.summarize_artifacts_rec([])

output = engine.summarize_artifacts_rec([], "summary")
assert output.value == "summary"

0 comments on commit 853dd2b

Please sign in to comment.