From 459f9380a709382d29891911fc03164d1e7e7f20 Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Tue, 26 Sep 2023 17:13:15 +0100 Subject: [PATCH] update code to support python <3.10, update requirements, fix readme issues --- README.md | 24 ++++++++++++------------ pilot/utils/function_calling.py | 11 ++++++----- requirements.txt | 1 + 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 791f706..963c47f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # πŸ§‘β€βœˆοΈ GPT PILOT ### GPT Pilot helps developers build apps 20x faster -You specify what kind of an app you want to build. Then, GPT Pilot asks clarifying questions, creates the product and technical requirements, sets up the environment, and **starts coding the app step by step, like in real life while you oversee the development process**. It asks you to review each task it finishes or to help when it gets stuck. This way, GPT Pilot acts as a coder while you are a lead dev who reviews code and helps when needed. +You specify what kind of app you want to build. Then, GPT Pilot asks clarifying questions, creates the product and technical requirements, sets up the environment, and **starts coding the app step by step, like in real life while you oversee the development process**. It asks you to review each task it finishes or to help when it gets stuck. This way, GPT Pilot acts as a coder while you are a lead dev who reviews code and helps when needed. --- @@ -9,11 +9,11 @@ You specify what kind of an app you want to build. Then, GPT Pilot asks clarifyi * [πŸ”Œ Requirements](#-requirements) * [🚦How to start using gpt-pilot?](#how-to-start-using-gpt-pilot) * [🐳 How to start gpt-pilot in docker?](#-how-to-start-gpt-pilot-in-docker) -* [πŸ§‘β€πŸ’»οΈ Other arguments](#%EF%B8%8F-other-arguments) +* [πŸ§‘β€πŸ’»οΈ Other arguments](#-other-arguments) * [πŸ”Ž Examples](#-examples) * [Real-time chat app](#-real-time-chat-app) * [Markdown editor](#-markdown-editor) - * [Timer app](#%EF%B8%8F-timer-app) + * [Timer app](#-timer-app) * [πŸ› Main pillars of GPT Pilot](#-main-pillars-of-gpt-pilot) * [πŸ— How GPT Pilot works?](#-how-gpt-pilot-works) * [πŸ•΄How's GPT Pilot different from _Smol developer_ and _GPT engineer_?](#hows-gpt-pilot-different-from-smol-developer-and-gpt-engineer) @@ -51,9 +51,9 @@ https://github.com/Pythagora-io/gpt-pilot/assets/10895136/0495631b-511e-451b-93d # πŸ”Œ Requirements -- **Python >= 3.10** +- **Python 3** - **PostgreSQL** (optional, projects default is SQLite) - - DB is needed for multiple reasons like continuing app development if you had to stop at any point or app crashed, going back to specific step so you can change some later steps in development, easier debugging, for future we will add functionality to update project (change some things in existing project or add new features to the project and so on)... + - DB is needed for multiple reasons like continuing app development if you had to stop at any point or app crashed, going back to specific step so that you can change some later steps in development, easier debugging, for future we will add functionality to update project (change some things in existing project or add new features to the project and so on)... # 🚦How to start using gpt-pilot? @@ -86,7 +86,7 @@ All generated code will be stored in the folder `workspace` inside the folder na 6. `python db_init.py` (initialize the database) 7. `python main.py` (start GPT Pilot) -This will start two containers, one being a new image built by the `Dockerfile` and a postgres database. The new image also has [ttyd](https://github.com/tsl0922/ttyd) installed so you can easily interact with gpt-pilot. Node is also installed on the image and port 3000 is exposed. +This will start two containers, one being a new image built by the `Dockerfile` and a postgres database. The new image also has [ttyd](https://github.com/tsl0922/ttyd) installed so that you can easily interact with gpt-pilot. Node is also installed on the image and port 3000 is exposed. # πŸ§‘β€πŸ’»οΈ Other arguments - continue working on an existing app @@ -134,8 +134,8 @@ Here are a couple of example apps GPT Pilot created by itself:
# πŸ› Main pillars of GPT Pilot: -1. For AI to create a fully working app, **a developer needs to be involved** in the process of app creation. They need to be able to change the code at any moment and GPT Pilot needs to continue working with those changes (eg. add an API key or fix an issue if an AI gets stuck)

-2. **The app needs to be written step by step as a developer would write it** - Let's say you want to create a simple app and you know everything you need to code and have the entire architecture in your head. Even then, you won't code it out entirely, then run it for the first time and debug all the issues at once. Rather, you will implement something simple, like add routes, run it, see how it works, and then move on to the next task. This way, you can debug issues as they arise. The same should be in the case when AI codes. It will make mistakes for sure so in order for it to have an easier time debugging issues and for the developer to understand what is happening, the AI shouldn't just spit out the entire codebase at once. Rather, the app should be developed step by step just like a developer would code it - eg. setup routes, add database connection, etc.

+1. For AI to create a fully working app, **a developer needs to be involved** in the process of app creation. They need to be able to change the code at any moment and GPT Pilot needs to continue working with those changes (e.g. add an API key or fix an issue if an AI gets stuck)

+2. **The app needs to be written step by step as a developer would write it** - Let's say you want to create a simple app, and you know everything you need to code and have the entire architecture in your head. Even then, you won't code it out entirely, then run it for the first time and debug all the issues at once. Rather, you will implement something simple, like add routes, run it, see how it works, and then move on to the next task. This way, you can debug issues as they arise. The same should be in the case when AI codes. It will make mistakes for sure so in order for it to have an easier time debugging issues and for the developer to understand what is happening, the AI shouldn't just spit out the entire codebase at once. Rather, the app should be developed step by step just like a developer would code it - e.g. setup routes, add database connection, etc.

3. **The approach needs to be scalable** so that AI can create a production ready app 1. **Context rewinding** - for solving each development task, the context size of the first message to the LLM has to be relatively the same. For example, the context size of the first LLM message while implementing development task #5 has to be more or less the same as the first message while developing task #50. Because of this, the conversation needs to be rewound to the first message upon each task. [See the diagram here](https://blogpythagora.files.wordpress.com/2023/08/pythagora-product-development-frame-3-1.jpg?w=1714). 2. **Recursive conversations** are LLM conversations that are set up in a way that they can be used β€œrecursively”. For example, if GPT Pilot detects an error, it needs to debug it but let’s say that, during the debugging process, another error happens. Then, GPT Pilot needs to stop debugging the first issue, fix the second one, and then get back to fixing the first issue. This is a very important concept that, I believe, needs to work to make AI build large and scalable apps by itself. It works by rewinding the context and explaining each error in the recursion separately. Once the deepest level error is fixed, we move up in the recursion and continue fixing that error. We do this until the entire recursion is completed. @@ -155,9 +155,9 @@ Here are the steps GPT Pilot takes to create an app: 3. **Product Owner agent** writes user stories and asks you if they are all correct (this helps it create code later on) 4. **Architect agent** writes up technologies that will be used for the app 5. **DevOps agent** checks if all technologies are installed on the machine and installs them if they are not -6. **Tech Lead agent** writes up development tasks that Developer will need to implement. This is an important part because, for each step, Tech Lead needs to specify how the user (real world developer) can review if the task is done (eg. open localhost:3000 and do something) -7. **Developer agent** takes each task and writes up what needs to be done to implement it. The description is in human readable form. -8. Finally, **Code Monkey agent** takes the Developer's description and the currently implement file and implements the changes into it. We realized this works much better than giving it to Developer right away to implement changes. +6. **Tech Lead agent** writes up development tasks that Developer will need to implement. This is an important part because, for each step, Tech Lead needs to specify how the user (real world developer) can review if the task is done (e.g. open localhost:3000 and do something) +7. **Developer agent** takes each task and writes up what needs to be done to implement it. The description is in human-readable form. +8. Finally, **Code Monkey agent** takes the Developer's description and the currently implemented file and implements the changes into it. We realized this works much better than giving it to Developer right away to implement changes. ![GPT Pilot Coding Workflow](https://github.com/Pythagora-io/gpt-pilot/assets/10895136/53ea246c-cefe-401c-8ba0-8e4dd49c987b) @@ -167,7 +167,7 @@ Here are the steps GPT Pilot takes to create an app: # πŸ•΄How's GPT Pilot different from _Smol developer_ and _GPT engineer_? - **GPT Pilot works with the developer to create fully working production-ready app** - I don't think that AI can (at least in the near future) create apps without a developer being involved. So, **GPT Pilot codes the app step by step** just like a developer would in real life. This way, it can debug issues as they arise throughout the development process. If it gets stuck, you, the developer in charge, can review the code and fix the issue. Other similar tools give you the entire codebase at once - this way, bugs are much harder to fix both for AI and for you as a developer.

-- **Works at scale** - GPT Pilot isn't meant to create simple apps but rather so it can work at any scale. It has mechanisms that filter out the code so in each LLM conversation, it doesn't need to store the entire codebase in context but it shows the LLM only the code that is relevant for the current task it's working on. Once an app is finished, you can always continue working on it by writing instructions on what feature you want to add. +- **Works at scale** - GPT Pilot isn't meant to create simple apps but rather so it can work at any scale. It has mechanisms that filter out the code so in each LLM conversation, it doesn't need to store the entire codebase in context, but it shows the LLM only the code that is relevant for the current task it's working on. Once an app is finished, you can always continue working on it by writing instructions on what feature you want to add. # 🍻 Contributing If you are interested in contributing to GPT Pilot, I would be more than happy to have you on board but also help you get started. Feel free to ping [zvonimir@pythagora.ai](mailto:zvonimir@pythagora.ai) and I'll help you get started. diff --git a/pilot/utils/function_calling.py b/pilot/utils/function_calling.py index 469bc53..8aa6d3c 100644 --- a/pilot/utils/function_calling.py +++ b/pilot/utils/function_calling.py @@ -1,8 +1,9 @@ import json import re -from typing import Literal, Optional, TypedDict, Callable +from typing import Union, TypeVar, List, Dict, Literal, Optional, TypedDict, Callable -JsonType = str | int | float | bool | None | list["JsonType"] | dict[str, "JsonType"] +JsonTypeBase = Union[str, int, float, bool, None, List["JsonType"], Dict[str, "JsonType"]] +JsonType = TypeVar("JsonType", bound=JsonTypeBase) class FunctionParameters(TypedDict): @@ -33,7 +34,7 @@ class FunctionCallSet(TypedDict): functions: dict[str, Callable] -def add_function_calls_to_request(gpt_data, function_calls: FunctionCallSet | None): +def add_function_calls_to_request(gpt_data, function_calls: Union[FunctionCallSet, None]): if function_calls is None: return @@ -57,7 +58,7 @@ def add_function_calls_to_request(gpt_data, function_calls: FunctionCallSet | No }) -def parse_agent_response(response, function_calls: FunctionCallSet | None): +def parse_agent_response(response, function_calls: Union[FunctionCallSet, None]): """ Post-processes the response from the agent. @@ -177,7 +178,7 @@ class JsonPrompter: self, prompt: str, functions: list[FunctionType], - function_to_call: str | None = None, + function_to_call: Union[str, None] = None, ) -> str: """Generate the llama prompt diff --git a/requirements.txt b/requirements.txt index 7a4eeca..d0de951 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ blessed==1.20.0 certifi==2023.5.7 charset-normalizer==3.2.0 distro==1.8.0 +fabulous==0.4.0 idna==3.4 Jinja2==3.1.2 MarkupSafe==2.1.3