fix: prompt

pull/12/head
adldotori 1 year ago
parent 199c5ebca2
commit 7726e33506

@ -2,6 +2,10 @@ import re
from typing import Dict, List, TypedDict
import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
from ansi import ANSI, Color, Style, dim_multiline
from core.agents.manager import AgentManager
from core.handlers.base import BaseHandler, FileHandler, FileType
@ -13,10 +17,7 @@ from core.tools.editor import CodeEditor
from core.tools.terminal import Terminal
from core.upload import StaticUploader
from env import settings
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from logger import logger
from pydantic import BaseModel
app = FastAPI()
@ -34,6 +35,7 @@ handlers: Dict[FileType, BaseHandler] = {FileType.DATAFRAME: CsvToDataframe()}
if settings["USE_GPU"]:
import torch
from core.handlers.image import ImageCaptioning
from core.tools.gpu import (
ImageEditing,
@ -87,11 +89,6 @@ async def command(request: Request) -> Response:
try:
res = executor({"input": promptedQuery})
except Exception as e:
logger.error(
ANSI("error while processing request").to(Color.red)
+ ": "
+ dim_multiline(str(e))
)
return {"response": str(e), "files": []}
files = re.findall("(image/\S*png)|(dataframe/\S*csv)", res["output"])

@ -1,8 +1,9 @@
from typing import Any, Dict, List, Optional, Union
from ansi import ANSI, Color, Style, dim_multiline
from langchain.callbacks.base import BaseCallbackHandler
from langchain.schema import AgentAction, AgentFinish, LLMResult
from ansi import ANSI, Color, Style, dim_multiline
from logger import logger
@ -35,7 +36,9 @@ class EVALCallbackHandler(BaseCallbackHandler):
def on_chain_error(
self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any
) -> None:
logger.error(ANSI(f"Chain Error").to(Color.red()) + f": {error}")
logger.error(
ANSI(f"Chain Error").to(Color.red()) + ": " + dim_multiline(str(error))
)
def on_tool_start(
self,

@ -2,9 +2,10 @@ import re
import time
from typing import Dict
from langchain.output_parsers.base import BaseOutputParser
from ansi import ANSI, Color, Style, dim_multiline
from core.prompts.input import EVAL_FORMAT_INSTRUCTIONS
from langchain.output_parsers.base import BaseOutputParser
from logger import logger
@ -13,7 +14,7 @@ class EvalOutputParser(BaseOutputParser):
return EVAL_FORMAT_INSTRUCTIONS
def parse(self, text: str) -> Dict[str, str]:
regex = r"Plan:(.*)[\n]What I Did: (.*)[\n]What Should I Do: (.*)[\n]Action: (.*?)[\n]Action Input: (.*)"
regex = r"Plan:(.*)[\n]What I Did: (.*)[\n]What Should I Do: (.*)[\n]Action: (.*?)[\n]Action Input:[ |\n](.*)"
match = re.search(regex, text, re.DOTALL)
if not match:
raise Exception("parse error")

@ -1,19 +1,40 @@
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.
Never give up even if it doesn't work out as you think. {bot_name} can do anything.
{bot_name} can code, run, debug, and test yourself. {bot_name} can correct the code appropriately by looking at the error message.
Never give up even if it doesn't work out as {bot_name} think. {bot_name} can do anything.
Let's think step by step.
"""
EVAL_FORMAT_INSTRUCTIONS = """
EVAL_FORMAT_INSTRUCTIONS = """RESPONSE FORMAT INSTRUCTIONS
----------------------------
When responding to me please, please output a response in following format:
When responding to me please, please output a response in one of two formats.:
**Option #1:**
Use this if you want the human to use a tool.
Your response should be in the following schema:
Plan: Details of current progress and remaining TODO in checkbox format.
What I Did: What you just did to achieve the goal.
What Should I Do: What you should do next to achieve the goal.
Action: Should be one of [Final Answer, {tool_names}]
Action Input: The input to the action
Action: Should be one of [{tool_names}]
Action Input: The input to the action.
**Option #2:**
Use this if you want to respond directly to the human.
You should replace sensitive data or encrypted data with "d1dy0uth1nk7hat1t1s7haAAat3aSy?" in action_input.
Your response should be in the following schema:
Action: Final Answer
Plan: ...
What I Did: ...
What Should I Do: ...
Action Input: string \\ You should put what you want to return to use here.
"""
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.

@ -50,12 +50,11 @@ class CodeEditor(BaseToolSet):
@tool(
name="CodeEditor.APPEND",
description="Append code to the existing file. "
"If the code is completed, use the Terminal tool to execute it, if not, append the code through the CodeEditor.APPEND tool. "
"Input should be filename and code to append. "
"Input code must be the code that should be appended, NOT whole code. "
description="Append text to the existing file. "
"Input should be filename and text to append. "
"Input text must be the text that should be appended, NOT whole text. "
"ex. test.py\nprint('hello world')\n "
"and the output will be code. ",
"and the output will be your input text. ",
)
def append(self, inputs: str) -> str:
try:
@ -72,11 +71,10 @@ class CodeEditor(BaseToolSet):
@tool(
name="CodeEditor.WRITE",
description="Write code to create a new tool. "
"If the code is completed, use the Terminal tool to execute it, if not, append the code through the CodeEditor.APPEND tool. "
description="Write text to create a new tool. "
"Input should be filename and text. "
"ex. test.py\nprint('hello world')\n "
"Input should be filename and code. "
"and the output will be code. ",
"and the output will be your input text. ",
)
def write(self, inputs: str) -> str:
try:
@ -116,7 +114,7 @@ class CodeEditor(BaseToolSet):
@tool(
name="CodeEditor.DELETE",
description="Delete code in file for a new start. "
description="Delete text in file for a new start. "
"Input should be filename."
"ex. test.py "
"Output will be success or error message.",

Loading…
Cancel
Save