Merge branch 'main' into feature/gui

pull/24/head
hanchchch 1 year ago
commit 705a001114

@ -117,7 +117,7 @@ async def execute(request: ExecuteRequest) -> ExecuteResponse:
except Exception as e:
return {"answer": str(e), "files": []}
files = re.findall("image/\S*png|dataframe/\S*csv", res["output"])
files = re.findall("[file/\S*]", res["output"])
return {
"answer": res["output"],

@ -3,12 +3,9 @@ import uuid
import shutil
from pathlib import Path
from enum import Enum
from pathlib import Path
from typing import Dict
import requests
from env import settings
class FileType(Enum):
IMAGE = "image"
@ -67,7 +64,7 @@ class FileHandler:
filetype = FileType.from_url(url)
data = requests.get(url).content
local_filename = os.path.join(
filetype.value, str(uuid.uuid4())[0:8] + filetype.to_extension()
"file", str(uuid.uuid4())[0:8] + filetype.to_extension()
)
os.makedirs(os.path.dirname(local_filename), exist_ok=True)
with open(local_filename, "wb") as f:

@ -3,8 +3,7 @@ EVAL_PREFIX = """{bot_name} can execute any user's request.
{bot_name} has permission to handle one instance and can handle the environment in it at will.
You can code, run, debug, and test yourself. You can correct the code appropriately by looking at the error message.
I can understand, process, and create various types of files. Images must be stored in the ./image/, audio in the ./audio/, video in the ./video/, and dataframes must be stored in the ./dataframe/.
I can understand, process, and create various types of files. Every files except the code must be restored in file/ directory.
{bot_name} can do whatever it takes to execute the user's request. Let's think step by step.
"""
@ -38,6 +37,7 @@ EVAL_SUFFIX = """TOOLS
{bot_name} can ask the user to use tools to look up information that may be helpful in answering the users original question.
You are very strict to the filename correctness and will never fake a file name if it does not exist.
You will remember to provide the file name loyally if it's provided in the last tool observation.
If you respond with a file name, you must provide the filename in [file/FILENAME] format.
The tools the human can use are:

@ -58,11 +58,8 @@ test.py|11,16|11,16|_titles
import os
import re
from pathlib import Path
from typing import Tuple
from env import settings
from .verify import verify
@ -103,7 +100,6 @@ class PatchCommand:
@verify
def execute(self) -> Tuple[int, int]:
os.makedirs(os.path.dirname(self.filepath), exist_ok=True)
lines = self.read_lines()
before = sum([len(line) for line in lines])

@ -3,10 +3,7 @@ read protocol:
<filepath>|<start line>-<end line>
"""
from pathlib import Path
from typing import List, Optional, Tuple
from env import settings
from typing import List, Optional
from .verify import verify

@ -1,17 +1,13 @@
from pathlib import Path
from env import settings
def verify(func):
def wrapper(*args, **kwargs):
try:
filepath = args[0].filepath
except:
except AttributeError:
raise Exception("This tool doesn't have filepath. Please check your code.")
if not str(Path(filepath).resolve()).startswith(
str(Path(settings["PLAYGROUND_DIR"]).resolve())
):
if not str(Path(filepath).resolve()).startswith(str(Path().resolve())):
return "You can't access file outside of playground."
return func(*args, **kwargs)

@ -4,11 +4,6 @@ write protocol:
<filepath>
<content>
"""
import os
from pathlib import Path
from env import settings
from .verify import verify

Loading…
Cancel
Save