Skip to content

Commit cc2226b

Browse files
authored
fix: type error when constructing RepublicError on error (#167)
1 parent d288aa8 commit cc2226b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/bub/framework.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from dotenv import load_dotenv
1212
from loguru import logger
1313
from republic import AsyncTapeStore, RepublicError, TapeContext
14+
from republic.core.errors import ErrorKind
1415
from republic.tape import TapeStore
1516

1617
from bub.envelope import content_of, field_of, unpack_batch
@@ -146,8 +147,13 @@ async def _run_model(
146147
if event.kind == "text":
147148
parts.append(str(event.data.get("delta", "")))
148149
elif event.kind == "error":
150+
# Turn "kind" to enum type otherwise the RepublicError's __str__ won't work well
151+
data = {
152+
**event.data,
153+
"kind": ErrorKind(event.data.get("kind", "unknown")),
154+
}
149155
await self._hook_runtime.notify_error(
150-
stage="run_model", error=RepublicError(**event.data), message=inbound
156+
stage="run_model", error=RepublicError(**data), message=inbound
151157
)
152158
return "".join(parts)
153159

0 commit comments

Comments
 (0)