Skip to content

Commit 30c3c34

Browse files
authored
bugfix: Parse output in FunctionsBasedOutputParser (#462)
There was a missed call to `_blocks_from_text` when creating the FinishAction in `FunctionsBasedOutputParser`. This resulted in returning text instead of Blocks for multimedia.
1 parent f97e411 commit 30c3c34

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/steamship/agents/functional/output_parser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def parse(self, text: str, context: AgentContext) -> Action:
8484
if "function_call" in text:
8585
return self._extract_action_from_function_call(text, context)
8686

87-
finish_block = Block(text=text)
88-
finish_block.set_chat_role(RoleTag.ASSISTANT)
89-
return FinishAction(output=[finish_block], context=context)
87+
finish_blocks = FunctionsBasedOutputParser._blocks_from_text(context.client, text)
88+
for finish_block in finish_blocks:
89+
finish_block.set_chat_role(RoleTag.ASSISTANT)
90+
return FinishAction(output=finish_blocks, context=context)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
3+
from steamship import Block, File, Steamship
4+
from steamship.agents.functional import FunctionsBasedOutputParser
5+
from steamship.agents.schema import AgentContext, FinishAction
6+
7+
8+
@pytest.mark.usefixtures("client")
9+
def test_output_block_ids_are_converted(client: Steamship):
10+
context = AgentContext()
11+
context.client = client
12+
block_id = File.create(client, blocks=[Block(text="test")]).blocks[0].id
13+
test_text = f"Here is an image of an anteater: Block({block_id})."
14+
15+
output_formatter = FunctionsBasedOutputParser()
16+
result = output_formatter.parse(test_text, context)
17+
18+
assert isinstance(result, FinishAction)
19+
assert len(result.output) == 3
20+
assert result.output[1].id == block_id

0 commit comments

Comments
 (0)