fix: input file path

pull/26/head
adldotori 1 year ago
parent a15ba07eca
commit a5c5ba358f

@ -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

@ -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

@ -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:

@ -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"
"<filepath>|<start_line>,<start_col>|<end_line>,<end_col>|<new_code>"
"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"
# "<filepath>|<start_line>,<start_col>|<end_line>,<end_col>|<new_code>"
# "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)

@ -1,6 +1,7 @@
import os
import shutil
from pathlib import Path
from env import DotEnv
from .base import AbstractUploader

Loading…
Cancel
Save