Skip to content

Commit

Permalink
Merge pull request #1355 from OpenInterpreter/development
Browse files Browse the repository at this point in the history
New `review` chunks
  • Loading branch information
KillianLucas authored Jul 24, 2024
2 parents 14ef23a + 5af6f9d commit 197d4bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 6 additions & 3 deletions interpreter/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ def _respond_and_store(self):
self.verbose = False

# Utility function
def is_active_line_chunk(chunk):
def is_ephemeral(chunk):
"""
Ephemeral = this chunk doesn't contribute to a message we want to save.
"""
if "format" in chunk and chunk["format"] == "active_line":
return True
if chunk["type"] == "review":
Expand Down Expand Up @@ -358,7 +361,7 @@ def is_active_line_chunk(chunk):
):
# If they match, append the chunk's content to the current message's content
# (Except active_line, which shouldn't be stored)
if not is_active_line_chunk(chunk):
if not is_ephemeral(chunk):
self.messages[-1]["content"] += chunk["content"]
else:
# If they don't match, yield a end message for the last message type and a start message for the new one
Expand All @@ -374,7 +377,7 @@ def is_active_line_chunk(chunk):
yield {**last_flag_base, "start": True}

# Add the chunk as a new message
if not is_active_line_chunk(chunk):
if not is_ephemeral(chunk):
self.messages.append(chunk)

# Yield the chunk itself
Expand Down
18 changes: 17 additions & 1 deletion interpreter/core/llm/run_function_calling_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,23 @@ def run_function_calling_llm(llm, request_params):
if "content" in delta and delta["content"]:
if function_call_detected:
# More content after a code block? This is a code review by a judge layer.
yield {"type": "review", "content": delta["content"]}
if delta["content"].strip() == "<SAFE>":
yield {"type": "review", "format": "safe", "content": ""}
elif "<UNSAFE>" in delta["content"]:
content = (
delta["content"]
.replace("<UNSAFE>", "")
.replace("</UNSAFE>", "")
)
yield {"type": "review", "format": "unsafe", "content": content}
else:
content = (
delta["content"]
.replace("<WARNING>", "")
.replace("</WARNING>", "")
)
yield {"type": "review", "format": "warning", "content": content}

else:
yield {"type": "message", "content": delta["content"]}

Expand Down

0 comments on commit 197d4bc

Please sign in to comment.