Skip to content

Commit

Permalink
Streaming Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
kssteven418 committed Mar 14, 2024
1 parent a2b1bd3 commit bbbbcd0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/llm_compiler/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def _match_buffer_and_generate_task(self, suffix: str) -> Optional[Task]:
if match := re.match(THOUGHT_PATTERN, self.buffer):
# Optionally, action can be preceded by a thought
self.thought = match.group(1)
self.buffer = suffix
elif match := re.match(ACTION_PATTERN, self.buffer):
# if action is parsed, return the task, and clear the buffer
idx, tool_name, args, _ = match.groups()
Expand All @@ -119,9 +118,9 @@ def _match_buffer_and_generate_task(self, suffix: str) -> Optional[Task]:
args=args,
thought=self.thought,
)
self.buffer = suffix
self.thought = ""
return task

return None

def ingest_token(self, token: str) -> Optional[Task]:
Expand All @@ -130,7 +129,9 @@ def ingest_token(self, token: str) -> Optional[Task]:
prefix, suffix = token.split("\n", 1)
prefix = prefix.strip()
self.buffer += prefix + "\n"
return self._match_buffer_and_generate_task(suffix)
matched_item = self._match_buffer_and_generate_task(suffix)
self.buffer = suffix
return matched_item
else:
self.buffer += token

Expand Down

0 comments on commit bbbbcd0

Please sign in to comment.