fix: build errors and minor issues

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

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

@ -8,16 +8,19 @@ RUN \
apt-get install -y software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \
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"
COPY pyproject.toml .
COPY poetry.lock .
COPY api api
RUN poetry env use 3.10
COPY api/__init__.py api/__init__.py
RUN poetry config virtualenvs.in-project true
RUN poetry config virtualenvs.path .venv
RUN poetry config installer.max-workers 10
RUN poetry env use 3.10
RUN poetry install --with tools
COPY . .

@ -8,17 +8,20 @@ RUN \
apt-get install -y software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \
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"
COPY pyproject.toml .
COPY poetry.lock .
COPY api api
RUN poetry env use 3.10
COPY api/__init__.py api/__init__.py
RUN poetry config virtualenvs.in-project true
RUN poetry config virtualenvs.path .venv
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 . .

@ -18,7 +18,7 @@ Use this if you want the human to use a tool.
Your response should be in the following schema:
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
**Option #2:**

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

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

@ -3,8 +3,11 @@ read protocol:
<filepath>|<start line>-<end line>
"""
from pathlib import Path
from typing import List, Optional, Tuple
from env import settings
class Line:
def __init__(self, content: str, line_number: int, depth: int):
@ -101,11 +104,16 @@ class ReadCommand:
separator = "|"
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.end: int = end
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:
code = f.readlines()
@ -126,11 +134,16 @@ class SummaryCommand:
separator = "|"
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.parent_content: Optional[str] = parent_content
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:
code = f.readlines()

@ -9,6 +9,7 @@ services:
context: .
volumes:
- ./static/:/app/static/
- ./playground/:/app/playground/
ports:
- "4500:4500"
- "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"
pydantic = "^1.10.6"
tenacity = "^8.2.2"
llama-index = "^0.4.29"
llama-index = "0.4.29"
python-dotenv = "^1.0.0"
torch = "^2.0.0"
pillow = "^9.4.0"
boto3 = "^1.26.94"
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"
transformers = {git = "https://github.com/huggingface/transformers.git", rev = "main"}
sentencepiece = "^0.1.97"
bitsandbytes = "^0.37.2"
python-ptrace = "^0.9.8"
[tool.poetry.group.tools]
optional = true

Loading…
Cancel
Save