Skip to content

Commit 6d74753

Browse files
author
Douglas Reid
committed
more flexible parsing
1 parent a6a4fc9 commit 6d74753

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/steamship/agents/react/output_parser.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def parse(self, text: str, context: AgentContext) -> Action:
2626
regex = r"Action: (.*?)[\n]*Action Input: (.*)"
2727
match = re.search(regex, text)
2828
if not match:
29-
raise RuntimeError(f"Could not parse LLM output: `{text}`")
29+
# TODO: should this be the case? If we are off-base should we just return what we have?
30+
return FinishAction(
31+
output=ReACTOutputParser._blocks_from_text(context.client, text), context=context
32+
)
3033
action = match.group(1)
3134
action_input = match.group(2).strip()
3235
tool = self.tools_lookup_dict[action.strip()]
@@ -53,7 +56,7 @@ def _blocks_from_text(client: Steamship, text: str) -> List[Block]:
5356
)
5457
if len(pre_block_text) > 0:
5558
result_blocks.append(Block(text=pre_block_text))
56-
result_blocks.append(Block.get(client, _id=match.group(1)))
59+
# result_blocks.append(Block.get(client, _id=match.group(1)))
5760
remaining_text = ReACTOutputParser._remove_block_suffix(
5861
remaining_text[match.end() :]
5962
)
@@ -78,3 +81,9 @@ def _remove_block_suffix(candidate: str) -> str:
7881
if removed.startswith(")") or removed.endswith("]"):
7982
removed = removed[1:]
8083
return removed
84+
85+
86+
if __name__ == "__main__":
87+
with Steamship.temporary_workspace() as client:
88+
text = "Hey there, why do you want a cartoon of a dog playing bingo? Is it because you're not good at the game and think the dog might have better luck? 😜 Block(C45A80DD-88F6-460D-8051-3769B60ABF0B)"
89+
print(ReACTOutputParser._blocks_from_text(client, text))

0 commit comments

Comments
 (0)