Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Cleanup

Tomas Valenta1f5773a4e846
diff --git a/api-service/.gitignore b/api-service/.gitignore
index 671894279..69023ffbd 100644
--- a/api-service/.gitignore
+++ b/api-service/.gitignore
@@ -1,3 +1,4 @@
__pycache__
dist
.venv
+out.txt
\ No newline at end of file
diff --git a/api-service/out.txt b/api-service/out.txt
deleted file mode 100644
index e69de29bb..000000000
diff --git a/api-service/test/test_simple_format_action_parsing.py b/api-service/test/test_simple_format_action_parsing.py
new file mode 100644
index 000000000..51f8a34f4
--- /dev/null
+++ b/api-service/test/test_simple_format_action_parsing.py
@@ -0,0 +1,104 @@
+"""Test LLM incomplete action parsing"""
+
+# import pytest
+
+from typing import Dict, List, NamedTuple, Any
+from codegen.agent.base import (
+ parse_text,
+ separate_thought_and_action,
+ parse_action_string,
+)
+
+
+class Action(NamedTuple):
+ tool: str
+ input: str
+
+
+llm_outputs: List[Dict[str, Any]] = [
+ {
+ "llm_output": """
+This is a thought:
+Action:
+<action tool="AskHuman">
+What should the post request handler do?
+</
+""",
+ "expected_actions": [
+ Action("AskHuman", "What should the post request handler do?")
+ ],
+ },
+ {
+ "llm_output": """
+<action tool="AskHuman">
+What should the post request handler do?
+</action>
+This is a thought:
+Action:
+""",
+ "expected_actions": [
+ Action("AskHuman", "What should the post request handler do?")
+ ],
+ },
+ {
+ "llm_output": """
+<action tool="AskHuman">
+What should the post request handler do?
+</action>
+This is a thought:
+
+<?
+<action tool="AskHuman">
+What
+</action>
+
+This is a thought:
+
+<?
+""",
+ "expected_actions": [
+ Action("AskHuman", "What should the post request handler do?"),
+ Action("AskHuman", "What"),
+ ],
+ },
+ {
+ "llm_output": """
+This is a thought
+Greater <?
+And action:
+
+<action tool="AskHuman">
+What should the post request handler do?
+</action>
+<action tool="AskHuman">
+What
+</action>
+thought after?
+""",
+ "expected_actions": [
+ Action("AskHuman", "What should the post request handler do?"),
+ Action("AskHuman", "What"),
+ ],
+ },
+]
+
+
+def test_parsing_llm_simple_format_action_output():
+ """Test LLM action parsing."""
+
+ for output in llm_outputs:
+ # _, action_string = separate_thought_and_action(output["llm_output"])
+ # parsed_actions = parse_action_string(output["llm_output"])
+
+ thought, parsed_actions = parse_text(output["llm_output"])
+
+ # print("Thought", thought)
+
+ for parsed_action, expected_action in zip(
+ parsed_actions, output["expected_actions"]
+ ):
+ # print("Action", parsed_action.text.strip())
+ assert parsed_action.attrib["tool"] == expected_action.tool
+ assert parsed_action.text.strip().startswith(expected_action.input.strip())
+
+ print("-----------")