Skip to content

Commit

Permalink
Merge pull request #897 from ATheorell/main
Browse files Browse the repository at this point in the history
Updates of build system with related changes to CI
  • Loading branch information
ATheorell authored Dec 13, 2023
2 parents 26a1ec7 + ec35094 commit 3996fbb
Show file tree
Hide file tree
Showing 49 changed files with 769 additions and 710 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ repos:
args: [--config, pyproject.toml]
types: [python]

# - repo: https://github.com/charliermarsh/ruff-pre-commit
# rev: "v0.0.272"
# hooks:
# - id: ruff
# args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.272"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand Down
4 changes: 0 additions & 4 deletions gpt_engineer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Adding convenience imports to the package
from gpt_engineer.core import (
ai,
chat_to_files,
)

# from gpt_engineer.tools import code_vector_repository
# from gpt_engineer.core.default import on_disk_repository
19 changes: 9 additions & 10 deletions gpt_engineer/applications/cli/cli_agent.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
from gpt_engineer.core.files_dict import FilesDict
from typing import Callable, TypeVar

# from gpt_engineer.core.default.git_version_manager import GitVersionManager
from gpt_engineer.core.ai import AI
from gpt_engineer.core.base_agent import BaseAgent
from gpt_engineer.core.base_execution_env import BaseExecutionEnv
from gpt_engineer.core.base_memory import BaseMemory
from gpt_engineer.core.default.disk_execution_env import DiskExecutionEnv
from gpt_engineer.core.default.disk_memory import DiskMemory
from gpt_engineer.core.default.paths import ENTRYPOINT_FILE, PREPROMPTS_PATH
from gpt_engineer.core.default.steps import (
execute_entrypoint,
gen_code,
gen_entrypoint,
execute_entrypoint,
improve,
)
from gpt_engineer.core.base_memory import BaseMemory
from gpt_engineer.core.default.disk_memory import DiskMemory
from gpt_engineer.core.base_execution_env import BaseExecutionEnv
from gpt_engineer.core.default.disk_execution_env import DiskExecutionEnv
from gpt_engineer.core.default.paths import memory_path, ENTRYPOINT_FILE, PREPROMPTS_PATH
from gpt_engineer.core.base_agent import BaseAgent
from gpt_engineer.core.files_dict import FilesDict
from gpt_engineer.core.preprompts_holder import PrepromptsHolder
from typing import TypeVar, Callable, Union
from pathlib import Path

CodeGenType = TypeVar("CodeGenType", bound=Callable[[AI, str, BaseMemory], FilesDict])
CodeProcessor = TypeVar(
Expand Down
14 changes: 7 additions & 7 deletions gpt_engineer/applications/cli/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@
Consent logic is in gpt_engineer/learning.py.
"""
import hashlib

from typing import List, Tuple
from typing import Tuple

from gpt_engineer.core.default.disk_memory import DiskMemory
from gpt_engineer.applications.cli.learning import (
Learning,
Review,
extract_learning,
human_review_input,
Review,
)
from gpt_engineer.core.default.disk_memory import DiskMemory


def send_learning(learning: Learning):
Expand Down Expand Up @@ -88,7 +87,7 @@ def collect_learnings(
learnings = extract_learning(prompt, model, temperature, config, memory, review)
try:
send_learning(learnings)
except RuntimeError as e:
except RuntimeError:
# try to remove some parts of learning that might be too big
# rudderstack max event size is 32kb
max_size = 32 << 10 # 32KB in bytes
Expand All @@ -100,7 +99,8 @@ def collect_learnings(
remove_length = overflow + len(f"[REMOVED {overflow} CHARACTERS]") + 100

learnings.logs = (
learnings.logs[:-remove_length] + f"\n\n[REMOVED {remove_length} CHARACTERS]"
learnings.logs[:-remove_length]
+ f"\n\n[REMOVED {remove_length} CHARACTERS]"
)

print(
Expand All @@ -109,7 +109,7 @@ def collect_learnings(
)
try:
send_learning(learnings)
except RuntimeError as e:
except RuntimeError:
print(
"Sending learnings crashed despite truncation. Progressing without saving learnings."
)
Expand Down
4 changes: 3 additions & 1 deletion gpt_engineer/applications/cli/file_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def display_name(self) -> str:
return self.path.name

@classmethod
def make_tree(cls, root: Union[str, Path], parent=None, is_last=False, criteria=None):
def make_tree(
cls, root: Union[str, Path], parent=None, is_last=False, criteria=None
):
"""
Generate a tree of DisplayablePath objects.
Expand Down
2 changes: 1 addition & 1 deletion gpt_engineer/applications/cli/learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from dataclasses import dataclass, field
from datetime import datetime
from pathlib import Path
from typing import List, Optional, Tuple
from typing import Optional, Tuple

from dataclasses_json import dataclass_json
from termcolor import colored
Expand Down
51 changes: 33 additions & 18 deletions gpt_engineer/applications/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,39 @@
"""

import logging
import os

from importlib.util import find_spec
from pathlib import Path

import openai
import toml
import typer

from dotenv import load_dotenv

from gpt_engineer.core.default.file_store import FileStore
from gpt_engineer.core.default.disk_memory import DiskMemory
from gpt_engineer.core.ai import AI
from gpt_engineer.core.default.paths import PREPROMPTS_PATH, memory_path
from gpt_engineer.applications.cli.file_selector import ask_for_files, get_all_code
from gpt_engineer.tools.custom_steps import (
lite_gen,
clarified_gen,
self_heal,
)
from gpt_engineer.tools.experimental.experimental_steps import (
improve_automatic_file_selection,
)
from gpt_engineer.core.default.steps import gen_code, execute_entrypoint, improve
from gpt_engineer.applications.cli.cli_agent import CliAgent
from gpt_engineer.applications.cli.collect import collect_and_send_human_review
from gpt_engineer.core.preprompts_holder import PrepromptsHolder
from gpt_engineer.applications.cli.file_selector import ask_for_files
from gpt_engineer.core.ai import AI
from gpt_engineer.core.default.disk_execution_env import DiskExecutionEnv
import logging
from gpt_engineer.core.default.disk_memory import DiskMemory
from gpt_engineer.core.default.file_store import FileStore
from gpt_engineer.core.default.paths import PREPROMPTS_PATH, memory_path
from gpt_engineer.core.default.steps import execute_entrypoint, gen_code, improve
from gpt_engineer.core.preprompts_holder import PrepromptsHolder
from gpt_engineer.tools.custom_steps import clarified_gen, lite_gen, self_heal

# Load the names of the optional dependencies from the pyprojecct file and determine whether
# they can be imported
with open("pyproject.toml", "r") as file:
pyproject = toml.load(file)

dependency_group = pyproject["tool"]["poetry"]["group"]["experimental"]["dependencies"]
optional_deps_importable = all(
[find_spec(dep_name.replace("-", "_")) is not None for dep_name in dependency_group]
)

app = typer.Typer() # creates a CLI app

Expand Down Expand Up @@ -105,7 +112,7 @@ def main(
),
improve_all_mode: bool = typer.Option(
False,
"--improve_all_experimental",
"--improve-all-experimental",
help="Improve files_dict from existing project, without manually choosing which files to improve, using vector store (EXPERIMENTAL).",
),
lite_mode: bool = typer.Option(
Expand Down Expand Up @@ -185,8 +192,16 @@ def main(
else:
execution_fn = execute_entrypoint

if improve_all_mode:
if improve_all_mode and optional_deps_importable:
from gpt_engineer.tools.experimental.experimental_steps import (
improve_automatic_file_selection,
)

improve_fn = improve_automatic_file_selection
elif improve_all_mode:
raise ImportError(
"The experimental improve_all_mode is selected, but the optional dependencies to use it are not installed. Please run 'poetry install --with experimental'"
)
else:
improve_fn = improve

Expand Down
12 changes: 9 additions & 3 deletions gpt_engineer/benchmark/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import importlib
from typing import Optional, Annotated

from typing import Annotated, Optional

import typer

from langchain.cache import SQLiteCache
Expand All @@ -22,7 +24,9 @@ def main(
help="python file that contains a function called 'default_config_agent'"
),
],
benchmarks: Annotated[str, typer.Argument(help="benchmark name(s) separated by ','")],
benchmarks: Annotated[
str, typer.Argument(help="benchmark name(s) separated by ','")
],
task_name: Annotated[
Optional[str], typer.Argument(help="optional task name in benchmark")
] = None,
Expand All @@ -38,7 +42,9 @@ def main(
agent = get_agent(path_to_agent)

results = run(agent, benchmark, task_name, verbose=verbose)
print(f"\n--- Results for agent {path_to_agent}, benchmark: {benchmark_name} ---")
print(
f"\n--- Results for agent {path_to_agent}, benchmark: {benchmark_name} ---"
)
print_results(results)
print()

Expand Down
7 changes: 0 additions & 7 deletions gpt_engineer/benchmark/benchmarks/gpteng/eval_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
be expanded.
"""

import subprocess

from datetime import datetime

import yaml

from tabulate import tabulate

from gpt_engineer.core.files_dict import FilesDict

Expand Down
12 changes: 7 additions & 5 deletions gpt_engineer/benchmark/benchmarks/gpteng/load.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pathlib import Path

from gpt_engineer.benchmark.benchmarks.gpteng.eval_tools import check_evaluation_component
from gpt_engineer.benchmark.types import Benchmark, Task, Assertable
from gpt_engineer.core import chat_to_files
from gpt_engineer.benchmark.benchmarks.gpteng.eval_tools import (
check_evaluation_component,
)
from gpt_engineer.benchmark.types import Assertable, Benchmark, Task
from gpt_engineer.core.chat_to_files import chat_to_files_dict
from gpt_engineer.core.files_dict import FilesDict

evaluations = [
{
Expand Down Expand Up @@ -156,4 +156,6 @@ def eval_to_task(case):


def load_gpteng():
return Benchmark(name="gpte_eval", tasks=[eval_to_task(case) for case in evaluations])
return Benchmark(
name="gpte_eval", tasks=[eval_to_task(case) for case in evaluations]
)
1 change: 0 additions & 1 deletion gpt_engineer/benchmark/benchmarks/gptme/load.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from gpt_engineer.benchmark.types import Benchmark, Task
from gpt_engineer.core.files_dict import FilesDict
from gpt_engineer.core.base_execution_env import BaseExecutionEnv


def load_gptme():
Expand Down
6 changes: 3 additions & 3 deletions gpt_engineer/benchmark/run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import time

import typer

from gpt_engineer.benchmark.types import Assertable, Benchmark, TaskResult
from gpt_engineer.core.base_agent import BaseAgent
from gpt_engineer.core.default.disk_execution_env import DiskExecutionEnv
Expand Down Expand Up @@ -67,7 +65,9 @@ def print_results(results: list[TaskResult]):
)
for task_result in results
)
total_assertions = sum(len(task_result.assertion_results) for task_result in results)
total_assertions = sum(
len(task_result.assertion_results) for task_result in results
)
print(f"Total correct assertions: {correct_assertions}/{total_assertions}")

correct_tasks = sum(
Expand Down
2 changes: 1 addition & 1 deletion gpt_engineer/benchmark/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from subprocess import Popen
from typing import Callable

from gpt_engineer.core.files_dict import FilesDict
from gpt_engineer.core.base_execution_env import BaseExecutionEnv
from gpt_engineer.core.files_dict import FilesDict


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions gpt_engineer/core/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import backoff
import openai

from gpt_engineer.core.token_usage import TokenUsageLog

from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain.chat_models import AzureChatOpenAI, ChatOpenAI
from langchain.chat_models.base import BaseChatModel
Expand All @@ -22,6 +20,8 @@
messages_to_dict,
)

from gpt_engineer.core.token_usage import TokenUsageLog

# Type hint for a chat message
Message = Union[AIMessage, HumanMessage, SystemMessage]

Expand Down
5 changes: 2 additions & 3 deletions gpt_engineer/core/base_agent.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from gpt_engineer.core.files_dict import FilesDict
from gpt_engineer.core.version_manager import BaseVersionManager
from gpt_engineer.core.ai import AI
from abc import ABC, abstractmethod

from gpt_engineer.core.files_dict import FilesDict


class BaseAgent(ABC):
"""
Expand Down
3 changes: 2 additions & 1 deletion gpt_engineer/core/base_execution_env.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from abc import ABC, abstractmethod
from gpt_engineer.core.files_dict import FilesDict
from subprocess import Popen

from gpt_engineer.core.files_dict import FilesDict


class BaseExecutionEnv(ABC):
"""
Expand Down
3 changes: 1 addition & 2 deletions gpt_engineer/core/base_memory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from typing import TypeVar, MutableMapping
from abc import ABC
from typing import MutableMapping

BaseMemory = MutableMapping[str | Path, str]
4 changes: 2 additions & 2 deletions gpt_engineer/core/chat_to_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
- apply_edits: Applies file edits to a workspace.
"""

import re
import logging
import re

from dataclasses import dataclass
from typing import List, Tuple
from typing import List

from gpt_engineer.core.files_dict import FilesDict

Expand Down
2 changes: 1 addition & 1 deletion gpt_engineer/core/default/disk_execution_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import time

from gpt_engineer.core.base_execution_env import BaseExecutionEnv
from gpt_engineer.core.files_dict import FilesDict
from gpt_engineer.core.default.file_store import FileStore
from gpt_engineer.core.files_dict import FilesDict


class DiskExecutionEnv(BaseExecutionEnv):
Expand Down
5 changes: 3 additions & 2 deletions gpt_engineer/core/default/disk_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
import json
import shutil

from gpt_engineer.core.base_memory import BaseMemory
from pathlib import Path
from typing import Any, Optional, Union, Iterator, Dict
from typing import Any, Dict, Iterator, Optional, Union

from gpt_engineer.core.base_memory import BaseMemory
from gpt_engineer.tools.experimental.supported_languages import SUPPORTED_LANGUAGES


Expand Down
Loading

0 comments on commit 3996fbb

Please sign in to comment.