fix: build errors and minor issues

feature/stdout-breaker
adldotori 1 year ago
parent 318c4781de
commit 0f4669ea36

@ -1,37 +1,27 @@
import re import re
from typing import Dict, List, TypedDict from typing import Dict, List, TypedDict
import torch
import uvicorn import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
from core.agents.manager import AgentManager from core.agents.manager import AgentManager
from core.handlers.base import BaseHandler, FileHandler, FileType from core.handlers.base import BaseHandler, FileHandler, FileType
from core.handlers.dataframe import CsvToDataframe from core.handlers.dataframe import CsvToDataframe
from core.handlers.image import ImageCaptioning
from core.prompts.error import ERROR_PROMPT from core.prompts.error import ERROR_PROMPT
from core.tools.base import BaseToolSet from core.tools.base import BaseToolSet
from core.tools.cpu import ExitConversation, RequestsGet, WineDB from core.tools.cpu import ExitConversation, RequestsGet
from core.tools.editor import CodeEditor from core.tools.editor import CodeEditor
from core.tools.gpu import (
ImageEditing,
InstructPix2Pix,
Text2Image,
VisualQuestionAnswering,
)
from core.tools.terminal import Terminal from core.tools.terminal import Terminal
from core.upload import StaticUploader from core.upload import StaticUploader
from env import settings from env import settings
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from logger import logger from logger import logger
from pydantic import BaseModel
app = FastAPI() app = FastAPI()
app.mount("/static", StaticFiles(directory=StaticUploader.STATIC_DIR), name="static") app.mount("/static", StaticFiles(directory=StaticUploader.STATIC_DIR), name="static")
uploader = StaticUploader.from_settings(settings) uploader = StaticUploader.from_settings(settings)
use_gpu = settings["USE_GPU"] and torch.cuda.is_available()
toolsets: List[BaseToolSet] = [ toolsets: List[BaseToolSet] = [
Terminal(), Terminal(),
@ -39,24 +29,28 @@ toolsets: List[BaseToolSet] = [
RequestsGet(), RequestsGet(),
ExitConversation(), ExitConversation(),
] ]
handlers: Dict[FileType, BaseHandler] = {FileType.DATAFRAME: CsvToDataframe()}
if use_gpu:
toolsets.extend( if settings["USE_GPU"]:
[ import torch
Text2Image("cuda"), from core.handlers.image import ImageCaptioning
ImageEditing("cuda"), from core.tools.gpu import (
InstructPix2Pix("cuda"), ImageEditing,
VisualQuestionAnswering("cuda"), InstructPix2Pix,
] Text2Image,
VisualQuestionAnswering,
) )
handlers: Dict[FileType, BaseHandler] = {} if torch.cuda.is_available():
handlers[FileType.DATAFRAME] = CsvToDataframe() toolsets.extend(
if use_gpu: [
handlers[FileType.IMAGE] = ImageCaptioning("cuda") Text2Image("cuda"),
ImageEditing("cuda"),
if settings["WINEDB_HOST"] and settings["WINEDB_PASSWORD"]: InstructPix2Pix("cuda"),
toolsets.append(WineDB()) VisualQuestionAnswering("cuda"),
]
)
handlers[FileType.IMAGE] = ImageCaptioning("cuda")
agent_manager = AgentManager.create(toolsets=toolsets) agent_manager = AgentManager.create(toolsets=toolsets)
file_handler = FileHandler(handlers=handlers) file_handler = FileHandler(handlers=handlers)

@ -8,16 +8,19 @@ RUN \
apt-get install -y software-properties-common && \ apt-get install -y software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \ add-apt-repository ppa:deadsnakes/ppa && \
apt-get install -y python3.10 python3-pip curl && \ apt-get install -y python3.10 python3-pip curl && \
curl -sSL https://install.python-poetry.org | python3 - curl -sSL https://install.python-poetry.org | python3 - && \
apt-get install -y nodejs npm
ENV PATH "/root/.local/bin:$PATH" ENV PATH "/root/.local/bin:$PATH"
COPY pyproject.toml . COPY pyproject.toml .
COPY poetry.lock . COPY poetry.lock .
COPY api api COPY api/__init__.py api/__init__.py
RUN poetry env use 3.10 RUN poetry config virtualenvs.in-project true
RUN poetry config virtualenvs.path .venv
RUN poetry config installer.max-workers 10 RUN poetry config installer.max-workers 10
RUN poetry env use 3.10
RUN poetry install --with tools RUN poetry install --with tools
COPY . . COPY . .

@ -8,17 +8,20 @@ RUN \
apt-get install -y software-properties-common && \ apt-get install -y software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \ add-apt-repository ppa:deadsnakes/ppa && \
apt-get install -y python3.10 python3-pip curl && \ apt-get install -y python3.10 python3-pip curl && \
curl -sSL https://install.python-poetry.org | python3 - curl -sSL https://install.python-poetry.org | python3 - && \
apt-get install -y nodejs npm
ENV PATH "/root/.local/bin:$PATH" ENV PATH "/root/.local/bin:$PATH"
COPY pyproject.toml . COPY pyproject.toml .
COPY poetry.lock . COPY poetry.lock .
COPY api api COPY api/__init__.py api/__init__.py
RUN poetry env use 3.10 RUN poetry config virtualenvs.in-project true
RUN poetry config virtualenvs.path .venv
RUN poetry config installer.max-workers 10 RUN poetry config installer.max-workers 10
RUN poetry install --with tools RUN poetry env use 3.10
RUN poetry install --with tools,gpu
COPY . . COPY . .

@ -18,7 +18,7 @@ Use this if you want the human to use a tool.
Your response should be in the following schema: Your response should be in the following schema:
Action: the action to take, should be one of [{tool_names}] Action: the action to take, should be one of [{tool_names}]
Plan: All remaining detailed plans after this action in bullet points. Plan: All remaining detailed plans after this action in check box. Each plan should be concise and clear to achieve the goal. Write it in the following schema: - [ ] plan
Action Input: the input to the action Action Input: the input to the action
**Option #2:** **Option #2:**

@ -1,4 +1,7 @@
from pathlib import Path
from core.tools.base import BaseToolSet, tool from core.tools.base import BaseToolSet, tool
from env import settings
from logger import logger from logger import logger
from .patch import CodePatcher from .patch import CodePatcher
@ -127,9 +130,9 @@ class CodeEditor(BaseToolSet):
"Output will be success or error message.", "Output will be success or error message.",
) )
def delete(self, inputs: str) -> str: def delete(self, inputs: str) -> str:
filename = inputs filepath: str = str(Path(settings["PLAYGROUND_DIR"]) / Path(inputs))
try: try:
with open(filename, "w") as f: with open(filepath, "w") as f:
f.write("") f.write("")
output = "success" output = "success"
except Exception as e: except Exception as e:

@ -73,7 +73,7 @@ class Position:
@staticmethod @staticmethod
def from_str(pos: str) -> "Position": def from_str(pos: str) -> "Position":
line, col = pos.split(Position.separator) line, col = pos.split(Position.separator)
return Position(int(line) - 1, int(col) - 1) return Position(int(line), int(col))
class PatchCommand: class PatchCommand:

@ -3,8 +3,11 @@ read protocol:
<filepath>|<start line>-<end line> <filepath>|<start line>-<end line>
""" """
from pathlib import Path
from typing import List, Optional, Tuple from typing import List, Optional, Tuple
from env import settings
class Line: class Line:
def __init__(self, content: str, line_number: int, depth: int): def __init__(self, content: str, line_number: int, depth: int):
@ -101,11 +104,16 @@ class ReadCommand:
separator = "|" separator = "|"
def __init__(self, filepath: str, start: int, end: int): def __init__(self, filepath: str, start: int, end: int):
self.filepath: str = filepath self.filepath: str = str(Path(settings["PLAYGROUND_DIR"]) / Path(filepath))
self.start: int = start self.start: int = start
self.end: int = end self.end: int = end
def execute(self) -> str: def execute(self) -> str:
if not str(Path(self.filepath).resolve()).startswith(
str(Path(settings["PLAYGROUND_DIR"]).resolve())
):
return "You can't write file outside of current directory."
with open(self.filepath, "r") as f: with open(self.filepath, "r") as f:
code = f.readlines() code = f.readlines()
@ -126,11 +134,16 @@ class SummaryCommand:
separator = "|" separator = "|"
def __init__(self, filepath: str, depth: int, parent_content: Optional[str] = None): def __init__(self, filepath: str, depth: int, parent_content: Optional[str] = None):
self.filepath: str = filepath self.filepath: str = str(Path(settings["PLAYGROUND_DIR"]) / Path(filepath))
self.depth: int = depth self.depth: int = depth
self.parent_content: Optional[str] = parent_content self.parent_content: Optional[str] = parent_content
def execute(self) -> str: def execute(self) -> str:
if not str(Path(self.filepath).resolve()).startswith(
str(Path(settings["PLAYGROUND_DIR"]).resolve())
):
return "You can't write file outside of current directory."
with open(self.filepath, "r") as f: with open(self.filepath, "r") as f:
code = f.readlines() code = f.readlines()

@ -9,6 +9,7 @@ services:
context: . context: .
volumes: volumes:
- ./static/:/app/static/ - ./static/:/app/static/
- ./playground/:/app/playground/
ports: ports:
- "4500:4500" - "4500:4500"
- "7000:7000" - "7000:7000"

760
poetry.lock generated

File diff suppressed because it is too large Load Diff

@ -15,17 +15,22 @@ langchain = "^0.0.115"
diffusers = "^0.14.0" diffusers = "^0.14.0"
pydantic = "^1.10.6" pydantic = "^1.10.6"
tenacity = "^8.2.2" tenacity = "^8.2.2"
llama-index = "^0.4.29" llama-index = "0.4.29"
python-dotenv = "^1.0.0" python-dotenv = "^1.0.0"
torch = "^2.0.0"
pillow = "^9.4.0" pillow = "^9.4.0"
boto3 = "^1.26.94" boto3 = "^1.26.94"
uvicorn = "^0.21.1" uvicorn = "^0.21.1"
python-ptrace = "^0.9.8"
[tool.poetry.group.gpu]
optional = true
[tool.poetry.group.gpu.dependencies]
torch = "^2.0.0"
accelerate = "^0.17.1" accelerate = "^0.17.1"
transformers = {git = "https://github.com/huggingface/transformers.git", rev = "main"} transformers = {git = "https://github.com/huggingface/transformers.git", rev = "main"}
sentencepiece = "^0.1.97" sentencepiece = "^0.1.97"
bitsandbytes = "^0.37.2" bitsandbytes = "^0.37.2"
python-ptrace = "^0.9.8"
[tool.poetry.group.tools] [tool.poetry.group.tools]
optional = true optional = true

Loading…
Cancel
Save