Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement-ready ReactJS application producing an optimized web interface with real-time Socket.IO support #860

Merged
merged 7 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GPT Engineer
# GPT Engineer + In-Browser Codegen 🚀

[![Discord Follow](https://dcbadge.vercel.app/api/server/8tcDQ89Ej2?style=flat)](https://discord.gg/8tcDQ89Ej2)
[![GitHub Repo stars](https://img.shields.io/github/stars/AntonOsika/gpt-engineer?style=social)](https://github.com/AntonOsika/gpt-engineer)
Expand All @@ -8,6 +8,12 @@

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.

**
It now comes with a real-time websocket interface between an optimized fast-loading ReactJS web app running on localhost and the Python3 agent. **

<img width="1768" alt="Screenshot 2023-11-22 at 20 09 29" src="https://github.com/zdanl/gpt-engineer/assets/114028070/25400e63-a011-45a7-927e-1fcc819b2b6c">


- [Demo](https://twitter.com/antonosika/status/1667641038104674306)

## Project philosophy
Expand All @@ -34,6 +40,14 @@ For **development**:
- `python -m pip install -e .`
- (or: `make install && source venv/bin/activate` for a venv)

For **GUI** release:

- `python3 applications/w3s/server.py &`
- `cd /app`
- `npm run build`
- `npm install`


**API Key**

Choose **one** of:
Expand Down Expand Up @@ -77,7 +91,7 @@ You can specify the "identity" of the AI agent by editing the files in the `prep

Editing the `preprompts`, and evolving how you write the project prompt, is how you make the agent remember things between projects.

You can also automatically copy all `preprompts` files into your project folder using the cli parameter `--use-custom-prepompts`. This way you can have custom preprompts for all of your projects without the need to edit the main files. If you don't want to use the project specific prepromt files, simply delete them or run `gpt-engineer` without the cli param.
You can also automatically copy all `preprompts` files into your project folder using the cli parameter `--use-custom-prepompts`. This way you can have custom preprompts for all of your projects without the need to edit the main files.

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`.

Expand Down
46 changes: 0 additions & 46 deletions gpt_engineer/applications/app/server.py

This file was deleted.

5 changes: 5 additions & 0 deletions gpt_engineer/applications/w3s/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CHANGELOG
=========

* @ATheorell implemented the agent wrapped with websockets
* @zdanl Replaced with socket.io for compatibiltiy with GUI
63 changes: 63 additions & 0 deletions gpt_engineer/applications/w3s/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Changelog
# * @ATheorell created this file
# * @zdanl here modiyfing @atheorell work from websockets to socket.io

from aiohttp import web
import aiohttp_cors
import socketio
import tempfile
import json

from gpt_engineer.core.default.lean_agent import LeanAgent
from gpt_engineer.core.preprompt_holder import PrepromptHolder

sio = socketio.AsyncServer(cors_allowed_origins="*")
app = web.Application()
sio.attach(app)

tempdir = tempfile.gettempdir()
agent = LeanAgent.with_default_config(tempdir)


class GPTEngineerNamespace(socketio.AsyncNamespace):
def on_connect(self, sid, environ):
print("Real-time socket to browser established.")

def on_disconnect(self, sid):
print("Browser disconnected.")

def on_my_event(self, sid, data):
self.emit("my_response", data)

def on_gp4_apikey(self, sid, data):
code = agent.seed(data)

async def on_init(event, sid, data):
print(f"{event}: {data}")
code = agent.init(event["prompt"])
await socketio.emit("prompt", {"payload": json.dumps(code)})

async def on_improve(event, sid, data):
print(f"{event}: {data}")
code = agent.improve(json.loads(event["code"]), event["prompt"])
await socketio.emit("improve", {"payload": json.dumps(code)})

async def on_execute(event, sid, data):
print(f"{event}: {data}")
process = agent.execution_env.execute_program(event["code"])
stdout, stderr = process.communicate()
output = stdout.decode("utf-8")
error = stderr.decode("utf-8")
payload = json.dumps({"output": output, "error": error})
await socketio.emit("execute", {"payload": payload})


sio.register_namespace(GPTEngineerNamespace("/gptengineer"))


async def main():
pass


if __name__ == "__main__":
web.run_app(app, port=4444)
7 changes: 7 additions & 0 deletions webapp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## [1.0.0] 2023-06-20

### Official Release

Added TypeScript & NextJS
21 changes: 21 additions & 0 deletions webapp/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Horizon UI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions webapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# GPT-Engineer App



## Community

Connect with the community! Feel free to ask questions, report issues, and meet new people that already use Horizon AI Template!

[Join the #HorizonUI Discord Community!](https://discord.gg/f6tEKFBd4m)

## Authors
* @zdanl https://github.com/zdanl

## Copyright and license

[Copyright 2023 GPT-Engineer](https://github.com/AntonOsika/gpt-engineer)
[Copyright 2023 Horizon UI](https://www.horizon-ui.com/?ref=readme-horizon-ai-template-free)
5 changes: 5 additions & 0 deletions webapp/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
19 changes: 19 additions & 0 deletions webapp/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @type {import('next').NextConfig} */

const nextConfig = {
reactStrictMode: false,
swcMinify: true,
basePath: process.env.NEXT_PUBLIC_BASE_PATH,
assetPrefix: process.env.NEXT_PUBLIC_BASE_PATH,
images: {
domains: [
'images.unsplash.com',
'i.ibb.co',
'scontent.fotp8-1.fna.fbcdn.net',
],
// Make ENV
unoptimized: true,
},
};

module.exports = nextConfig;
67 changes: 67 additions & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "gpt-engineer",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@chakra-ui/icons": "^1.1.5",
"@chakra-ui/react": "1.8.9",
"@chakra-ui/system": "^1.12.1",
"@chakra-ui/theme-tools": "^1.3.6",
"@codemirror/legacy-modes": "^6.3.2",
"@emotion/react": "^11.4.1",
"@emotion/styled": "^11.3.0",
"@heroicons/react": "^2.0.17",
"@material-tailwind/react": "^1.4.2",
"@tanstack/react-table": "^8.5.15",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"@uiw/codemirror-theme-tokyo-night": "^4.19.11",
"@uiw/react-codemirror": "^4.19.11",
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
"endent": "^2.1.0",
"eventsource-parser": "^1.0.0",
"framer-motion": "^4.1.17",
"next": "13.2.4",
"react": "18.2.0",
"react-build-sitemap": "^0.2.2",
"react-custom-scrollbars-2": "^4.2.1",
"react-dom": "18.2.0",
"react-icons": "^4.9.0",
"react-is": "^18.0.0",
"react-markdown": "^8.0.6",
"react-router-dom": "^5.3.0",
"react-scripts": "5.0.0",
"remark-gfm": "^3.0.1",
"sharp": "^0.32.6",
"socket.io": "^4.7.2",
"socket.io-client": "^4.7.2",
"typescript": "4.9.5",
"web-vitals": "^1.1.2"
},
"devDependencies": {
"@types/node": "18.15.11",
"@types/react": "18.0.31",
"@types/react-dom": "18.0.11",
"autoprefixer": "^10.4.14",
"eslint": "8.37.0",
"eslint-config-next": "13.2.4",
"eventsource": "^2.0.2",
"postcss": "^8.4.21",
"prettier-plugin-tailwindcss": "^0.2.6",
"tailwindcss": "^3.3.1"
},
"resolutions": {
"@types/react": "18.0.31",
"@types/react-dom": "18.0.11"
}
}
Loading
Loading