Skip to content

Commit fdf0af3

Browse files
committed
Fixed end_of_message and end_of_code flags
1 parent ab5259d commit fdf0af3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

interpreter/core/respond.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,22 @@ def respond(interpreter):
5858
chunk_type = "code"
5959
yield {"start_of_code": True}
6060
if "code" in chunk and chunk_type != "code":
61-
# (This shouldn't happen though — ^ "language" should be emitted first)
61+
# (This shouldn't happen though — ^ "language" should be emitted first, but sometimes GPT-3.5 forgets this)
62+
# (But I'm pretty sure we handle that? If it forgets we emit Python anyway?)
6263
chunk_type = "code"
6364
yield {"start_of_code": True}
6465
elif "message" not in chunk and chunk_type == "message":
6566
chunk_type = None
6667
yield {"end_of_message": True}
67-
elif "code" not in chunk and "language" not in chunk and chunk_type == "code":
68-
chunk_type = None
69-
yield {"end_of_code": True}
7068

7169
yield chunk
70+
71+
# We don't trigger the end_of_message or end_of_code flag if we actually end on either
72+
if chunk_type == "message":
73+
yield {"end_of_message": True}
74+
elif chunk_type == "code":
75+
yield {"end_of_code": True}
76+
7277
except litellm.exceptions.BudgetExceededError:
7378
display_markdown_message(f"""> Max budget exceeded
7479

0 commit comments

Comments
 (0)