forked from AntonOsika/gpt-engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First step in making gpt-engineer learn. Rename main_prompt -> prompt (…
…AntonOsika#381) * First step in collecting learnings * Rename prompts * remove requirements, use pip install -e . instead * Add requirements * Fix tests
- Loading branch information
1 parent
bc6371b
commit f159dc4
Showing
24 changed files
with
197 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Pytest Execution | ||
name: Pip install and pytest | ||
on: | ||
pull_request: | ||
branches: [main] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
[![GitHub Repo stars](https://img.shields.io/github/stars/AntonOsika/gpt-engineer?style=social)](https://github.com/AntonOsika/gpt-engineer) | ||
[![Twitter Follow](https://img.shields.io/twitter/follow/antonosika?style=social)](https://twitter.com/AntonOsika) | ||
|
||
|
||
**Specify what you want it to build, the AI asks for clarification, and then builds it.** | ||
|
||
GPT Engineer is made to be easy to adapt, extend, and make your agent learn how you want your code to look. It generates an entire codebase based on a prompt. | ||
|
@@ -40,34 +41,43 @@ With an api key that has GPT4 access run: | |
|
||
- `export OPENAI_API_KEY=[your api key]` | ||
|
||
|
||
**Run**: | ||
|
||
- Create an empty folder. If inside the repo, you can run: | ||
- `cp -r projects/example/ projects/my-new-project` | ||
- Fill in the `main_prompt` file in your new folder | ||
- Fill in the `prompt` file in your new folder | ||
- `gpt-engineer projects/my-new-project` | ||
- (Note, `gpt-engineer --help` lets you see all available options. For example `--steps use_feedback` lets you improve/fix code in a project) | ||
|
||
**Results**: | ||
By running gpt-engineer you agree to our [ToS](https://github.com/AntonOsika/gpt-engineer/TERMS_OF_USE.md). | ||
|
||
**Results** | ||
- Check the generated files in `projects/my-new-project/workspace` | ||
|
||
|
||
## Features | ||
|
||
You can specify the "identity" of the AI agent by editing the files in the `identity` folder. | ||
You can specify the "identity" of the AI agent by editing the files in the `preprompts` folder. | ||
|
||
Editing the identity, and evolving the `main_prompt`, is currently how you make the agent remember things between projects. | ||
Editing the `preprompts`, and evolving how you write the project prompt, is currently how you make the agent remember things between projects. | ||
|
||
Each step in `steps.py` will have its communication history with GPT4 stored in the logs folder, and can be rerun with `scripts/rerun_edited_message_logs.py`. | ||
|
||
## Contributing | ||
The gpt-engineer community is building the **open platform for devs to tinker with and build their personal code-generation toolbox**. | ||
|
||
If you are interested in contributing to this, we would be interested in having you! | ||
|
||
We are building the open platform for devs to tinker with and build their personal code-generation toolbox. | ||
You can check for good first issues [here](https://github.com/AntonOsika/gpt-engineer/issues). | ||
Contributing document [here](.github/CONTRIBUTING.md). | ||
|
||
If you want to contribute, please check out the [roadmap](https://github.com/AntonOsika/gpt-engineer/blob/main/ROADMAP.md), [projects](https://github.com/AntonOsika/gpt-engineer/projects?query=is%3Aopen) or [issues tab](https://github.com/AntonOsika/gpt-engineer/issues) in the GitHub repo. You are welcome to read the [contributing document](.github/CONTRIBUTING.md) and join our [Discord 💬](https://discord.gg/4t5vXHhu). | ||
We are currently looking for more maintainers and community organisers. Email anton.osika@gmail.com if you are interested in an official role. | ||
|
||
We are currently looking for more maintainers and community organisers. Email <[email protected]> if you are interested in an official role. | ||
If you want to see our broader ambitions, check out the [roadmap](https://github.com/AntonOsika/gpt-engineer/blob/main/ROADMAP.md), and join | ||
[discord ](https://discord.gg/4t5vXHhu) | ||
to get input on how you can contribute to it. | ||
|
||
## Example | ||
|
||
<https://github.com/AntonOsika/gpt-engineer/assets/4467025/6e362e45-4a94-4b0d-973d-393a31d92d9b> | ||
https://github.com/AntonOsika/gpt-engineer/assets/4467025/6e362e45-4a94-4b0d-973d-393a31d92d9b |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import hashlib | ||
import json | ||
import os | ||
import random | ||
import tempfile | ||
|
||
from dataclasses import dataclass | ||
from pathlib import Path | ||
|
||
from dataclasses_json import dataclass_json | ||
|
||
from gpt_engineer import steps | ||
from gpt_engineer.db import DBs | ||
from gpt_engineer.steps import Step | ||
|
||
|
||
@dataclass_json | ||
@dataclass | ||
class Learning: | ||
model: str | ||
temperature: float | ||
steps: str | ||
steps_file_hash: str | ||
prompt: str | ||
feedback: str | None | ||
session: str | ||
version: str = "0.1" | ||
|
||
|
||
def steps_file_hash(): | ||
with open(steps.__file__, "r") as f: | ||
content = f.read() | ||
return hashlib.sha256(content.encode("utf-8"), usedforsecurity=False).hexdigest() | ||
|
||
|
||
def extract_learning( | ||
model: str, temperature: float, steps: list[Step], dbs: DBs | ||
) -> Learning: | ||
learning = Learning( | ||
prompt=dbs.input["prompt"], | ||
model=model, | ||
temperature=temperature, | ||
steps=json.dumps([step.__name__ for step in steps]), | ||
steps_file_hash=steps_file_hash(), | ||
feedback=dbs.input.get("feedback"), | ||
session=get_session(), | ||
) | ||
return learning | ||
|
||
|
||
def send_learnings(learning: Learning): | ||
import rudderstack.analytics as rudder_analytics | ||
|
||
rudder_analytics.write_key = "2Re4kqwL61GDp7S8ewe6K5dbogG" | ||
rudder_analytics.dataPlaneUrl = "https://gptengineerezm.dataplane.rudderstack.com" | ||
|
||
rudder_analytics.track( | ||
user_id=learning.session, | ||
event="learning", | ||
properties=learning.to_dict(), # type: ignore | ||
) | ||
|
||
|
||
def get_session(): | ||
path = Path(tempfile.gettempdir()) / "gpt_engineer_user_id.txt" | ||
|
||
try: | ||
if path.exists(): | ||
user_id = path.read_text() | ||
else: | ||
# random uuid: | ||
user_id = str(random.randint(0, 2**32)) | ||
path.write_text(user_id) | ||
return user_id | ||
except IOError: | ||
return "ephemeral_" + str(random.randint(0, 2**32)) | ||
|
||
|
||
def collect_learnings(model: str, temperature: float, steps: list[Step], dbs: DBs): | ||
if os.environ.get("COLLECT_LEARNINGS_OPT_OUT") in ["true", "1"]: | ||
print("COLLECT_LEARNINGS_OPT_OUT is set to true, not collecting learning") | ||
return | ||
|
||
learnings = extract_learning(model, temperature, steps, dbs) | ||
send_learnings(learnings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
|
||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
import rudderstack.analytics as rudder_analytics | ||
|
||
from gpt_engineer.collect import collect_learnings, extract_learning | ||
from gpt_engineer.db import DB, DBs | ||
from gpt_engineer.steps import gen_code | ||
|
||
|
||
def test_collect_learnings(monkeypatch): | ||
monkeypatch.setattr(os, "environ", {"COLLECT_LEARNINGS_OPT_OUT": "false"}) | ||
monkeypatch.setattr(rudder_analytics, "track", MagicMock()) | ||
|
||
model = "test_model" | ||
temperature = 0.5 | ||
steps = [gen_code] | ||
dbs = DBs(DB("/tmp"), DB("/tmp"), DB("/tmp"), DB("/tmp"), DB("/tmp")) | ||
dbs.input = { | ||
"prompt": "test prompt\n with newlines", | ||
"feedback": "test feedback", | ||
} | ||
dbs.logs = {gen_code.__name__: "test logs"} | ||
|
||
collect_learnings(model, temperature, steps, dbs) | ||
|
||
learnings = extract_learning(model, temperature, steps, dbs) | ||
assert rudder_analytics.track.call_count == 1 | ||
assert rudder_analytics.track.call_args[1]["event"] == "learning" | ||
assert rudder_analytics.track.call_args[1]["properties"] == learnings.to_dict() | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main(["-v"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters