Skip to content

Commit a6a4fc9

Browse files
author
Douglas Reid
committed
fix tests
1 parent f1b3247 commit a6a4fc9

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/steamship/agents/react/output_parser.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,39 @@ def parse(self, text: str, context: AgentContext) -> Action:
4242
def _blocks_from_text(client: Steamship, text: str) -> List[Block]:
4343
last_response = text.split("AI:")[-1].strip()
4444

45-
block_id_regex = r"(?:\[Block)?\(?([A-F0-9]{8}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{12})\)?\]?"
45+
block_id_regex = r"(?:(?:\[|\()?Block)?\(?([A-F0-9]{8}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{12})\)?(?:(\]|\)))?"
4646
remaining_text = last_response
4747
result_blocks: List[Block] = []
4848
while remaining_text is not None and len(remaining_text) > 0:
4949
match = re.search(block_id_regex, remaining_text)
5050
if match:
51-
result_blocks.append(Block(text=remaining_text[0 : match.start()]))
51+
pre_block_text = ReACTOutputParser._remove_block_prefix(
52+
candidate=remaining_text[0 : match.start()]
53+
)
54+
if len(pre_block_text) > 0:
55+
result_blocks.append(Block(text=pre_block_text))
5256
result_blocks.append(Block.get(client, _id=match.group(1)))
53-
remaining_text = remaining_text[match.end() :]
57+
remaining_text = ReACTOutputParser._remove_block_suffix(
58+
remaining_text[match.end() :]
59+
)
5460
else:
5561
result_blocks.append(Block(text=remaining_text))
5662
remaining_text = ""
5763

5864
return result_blocks
65+
66+
@staticmethod
67+
def _remove_block_prefix(candidate: str) -> str:
68+
removed = candidate
69+
if removed.endswith("(Block") or removed.endswith("[Block"):
70+
removed = removed[len("Block") + 1 :]
71+
elif removed.endswith("Block"):
72+
removed = removed[len("Block") :]
73+
return removed
74+
75+
@staticmethod
76+
def _remove_block_suffix(candidate: str) -> str:
77+
removed = candidate
78+
if removed.startswith(")") or removed.endswith("]"):
79+
removed = removed[1:]
80+
return removed

tests/steamship_tests/app/unit/test_routes_on_superclasses.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import pytest
77

88
from steamship import Steamship
9+
from steamship.agents.llms import OpenAI
10+
from steamship.agents.react import ReACTAgent
911
from steamship.experimental.package_starters.telegram_agent import TelegramAgentService
1012
from steamship.invocable import Invocable, InvocableRequest, Invocation, post
1113
from steamship.utils.url import Verb
@@ -153,7 +155,11 @@ def test_l32_routes():
153155

154156
@pytest.mark.usefixtures("client")
155157
def test_telegram_agent(client: Steamship):
156-
a = MyAgentService(client=client, config={"botToken": "foo"})
158+
a = MyAgentService(
159+
client=client,
160+
config={"botToken": "foo"},
161+
incoming_message_agent=ReACTAgent(tools=[], llm=OpenAI(client=client)),
162+
)
157163
assert a._method_mappings[Verb.POST]["/answer"] == "answer"
158164
routes = [m["path"] for m in a.__steamship_dir__()["methods"]]
159165
assert "/answer" in routes

0 commit comments

Comments
 (0)