From a5c5ba358fc3c836744c48c1699cb58604f86064 Mon Sep 17 00:00:00 2001 From: adldotori Date: Fri, 7 Apr 2023 21:51:28 +0900 Subject: [PATCH] fix: input file path --- api/main.py | 1 - core/handlers/base.py | 12 +++++++----- core/prompts/input.py | 4 ++-- core/tools/editor/__init__.py | 34 +++++++++++++++++----------------- core/upload/static.py | 1 + 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/api/main.py b/api/main.py index 8cd667f..5126f80 100644 --- a/api/main.py +++ b/api/main.py @@ -9,7 +9,6 @@ from fastapi import FastAPI, Request, UploadFile from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates - from pydantic import BaseModel from core.agents.manager import AgentManager diff --git a/core/handlers/base.py b/core/handlers/base.py index 497ea6e..17f29dc 100644 --- a/core/handlers/base.py +++ b/core/handlers/base.py @@ -1,9 +1,10 @@ import os -import uuid import shutil -from pathlib import Path +import uuid from enum import Enum +from pathlib import Path from typing import Dict + import requests from env import settings @@ -77,8 +78,9 @@ class FileHandler: def handle(self, url: str) -> str: try: if url.startswith(settings["SERVER"]): - local_filename = url[len(settings["SERVER"]) + 1 :] - src = self.path / local_filename + local_filepath = url[len(settings["SERVER"]) + 1 :] + local_filename = Path("file") / local_filepath.split("/")[-1] + src = self.path / local_filepath dst = self.path / settings["PLAYGROUND_DIR"] / local_filename os.makedirs(os.path.dirname(dst), exist_ok=True) shutil.copy(src, dst) @@ -86,4 +88,4 @@ class FileHandler: local_filename = self.download(url) return self.handlers[FileType.from_url(url)].handle(local_filename) except Exception as e: - return "Error: " + str(e) + raise e diff --git a/core/prompts/input.py b/core/prompts/input.py index 8e6e128..cfd5f9d 100644 --- a/core/prompts/input.py +++ b/core/prompts/input.py @@ -3,7 +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. Every files except the code must be restored in file/ directory. +I can understand, process, and create various types of files. Every image, dataframe, audio, video 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. """ @@ -37,7 +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 have to include files in your response, you must move the files into file/ directory and provide the filename in [file/FILENAME] format. +If you have to include files in your response, you must move the files into file/ directory and provide the filename in [file/FILENAME] format. It must be wrapped in square brackets. The tools the human can use are: diff --git a/core/tools/editor/__init__.py b/core/tools/editor/__init__.py index 506a8d0..14ad4da 100644 --- a/core/tools/editor/__init__.py +++ b/core/tools/editor/__init__.py @@ -90,23 +90,23 @@ class CodeEditor(BaseToolSet): ) return output - @tool( - name="CodeEditor.PATCH", - description="Patch the code to correct the error if an error occurs or to improve it. " - "Input is a list of patches. The patch is separated by {seperator}. ".format( - seperator=CodePatcher.separator.replace("\n", "\\n") - ) - + "Each patch has to be formatted like below.\n" - "|,|,|" - "Here is an example. If the original code is:\n" - "print('hello world')\n" - "and you want to change it to:\n" - "print('hi corca')\n" - "then the patch should be:\n" - "test.py|1,8|1,19|hi corca\n" - "Code between start and end will be replaced with new_code. " - "The output will be written/deleted bytes or error message. ", - ) + # @tool( + # name="CodeEditor.PATCH", + # description="Patch the code to correct the error if an error occurs or to improve it. " + # "Input is a list of patches. The patch is separated by {seperator}. ".format( + # seperator=CodePatcher.separator.replace("\n", "\\n") + # ) + # + "Each patch has to be formatted like below.\n" + # "|,|,|" + # "Here is an example. If the original code is:\n" + # "print('hello world')\n" + # "and you want to change it to:\n" + # "print('hi corca')\n" + # "then the patch should be:\n" + # "test.py|1,8|1,19|hi corca\n" + # "Code between start and end will be replaced with new_code. " + # "The output will be written/deleted bytes or error message. ", + # ) def patch(self, patches: str) -> str: try: w, d = CodePatcher.patch(patches) diff --git a/core/upload/static.py b/core/upload/static.py index 247c9ad..cbafa70 100644 --- a/core/upload/static.py +++ b/core/upload/static.py @@ -1,6 +1,7 @@ import os import shutil from pathlib import Path + from env import DotEnv from .base import AbstractUploader