Giter Club home page Giter Club logo

tdd-gpt-agent's Introduction

Autonomous Agent for Test-Driven Development (TDD)

"Programmers have programmed themselves out of jobs" - Unknown

tddGPT: ReactJS Counter App with GPT3.5

tddGPT is an autonomous coding agent that builds applications in ReactJS, Flask, Express, and more, all while adhering to the Test-Driven Development (TDD) methodology. It operates entirely without human intervention. Beginning with a project plan, tddGPT translates requirements into tests, develops code based on those tests, and debugs until all tests pass. The TDD framework keeps the agent focused and goal-oriented.

The core architecture is elegantly simple, utilizing just three tools: CLI, ReadFile, and WriteFile. It has been adpated from Langchain's AutoGPT example. Most enhancements were performed by ChatGPT Plus itself over the course of a month-long chat. The initially aim was to test the limits of GPT-4's capabilities in building ReactJS apps end-to-end. In the process, it gained an understanding of temporal concepts like past, present, and future, as well as cause and effect.

Utilizing GPT-4 Turbo and GPT-4 Vision, the system is capable of transforming wireframes or screenshots, in conjunction with detailed user stories, into fully functional applications, complete with all necessary tests. The expanded context window of GPT-4 Turbo facilitates its functioning as an integrated team comprising a Product Owner, Programmer, and Tester. This enhanced capacity allows for the handling of significantly more intricate and detailed user stories.

The agent is not just a code generator; it’s also a learner. It evaluates its mistakes and areas for improvement as a final step, and some of these insights have already been incorporated into its operating prompts.

This project is in early alpha stage. GPT-4 API key is required.

Setup Instructions

  1. Setup a virtual environment:
python3 -m venv env
  1. Activate the virtual environment:
  • On macOS and Linux:
    source env/bin/activate
    
  • On Windows:
    .\env\Scripts\activate
    
  1. Clone the repository to your local machine:
git clone https://github.com/sankethchebbi/tddGPT.git

  1. Navigate to the project directory:
cd tddGPT
  1. Run the following command to install the package and its dependencies:
python setup.py install
  1. Set up your GPT-4 API keys as environment variables.
export OPENAI_API_KEY="sk-..."
  1. Run the main.py
cd tdd-gpt
python main.py --model gpt-4-1106-preview or gpt-3.5-turbo --prompt "Your prompt here" --temperature 0.2 --context_window 128000

Check the counter-app directory for the generated app.

Example apps

The following are some apps have been built by this agent.

Similar Projects

Contributing

We welcome contributions to this project. Please feel free to submit issues and pull requests. For major changes, please open an issue first to discuss what you would like to change.

License

This project is open source, under the MIT license.

Contact

If you have any questions or comments, please feel free to reach out to us on GitHub.

tdd-gpt-agent's People

Contributors

prthkms avatar rajivpoddar avatar sankethchebbi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tdd-gpt-agent's Issues

Edit Tool

Add diff and patch based editing of file so that the agent does not have to generate the code for the full file each time it has to update the code

Relevant Plan

  • store the detailed plan in the vector db
  • add the relevant plan to the prompt at each step

Design Tool

  • saves the design markdown file to a vectorestore
  • retrieves the relevant design and adds it to the prompt

Debate

Change the human prompt to debate the plan/tbds instead.

AST Support

Experiment with abstract syntax tree to give more context about code

Handle missing keys in assistant reply

Step Number: 15
Missing key: 'thoughts'
Traceback (most recent call last):
  File "/Users/rajiv/Downloads/projects/tdd-gpt-agent/tdd_gpt/main.py", line 74, in <module>
    main()
  File "/Users/rajiv/Downloads/projects/tdd-gpt-agent/tdd_gpt/main.py", line 71, in main
    agent.run([prompt])
  File "/Users/rajiv/Downloads/projects/tdd-gpt-agent/tdd_gpt/agent.py", line 195, in run
    f"Thought: {parsed['thoughts']['text']}",
                ~~~~~~^^^^^^^^^^^^
KeyError: 'thoughts'

Self-Reward

Prompt the agent to reward itself with a point whenever tests pass.

Save plan to markdown file

To handle cases where there is no command

Missing key: 'command'
{
    "thoughts": {
        "text": "Now that the basic structure of the app is set up, I need to plan the structure of the app and break it down into smaller components. For this todo app, I can have the following components: App, TodoList, TodoItem, and TodoForm. The App component will be the main component that contains all other components. The TodoList component will render a list of TodoItem components. The TodoItem component will represent a single todo item. The TodoForm component will contain the form for adding new todo items.",
        "reasoning": "Breaking down the app into smaller components makes the code more manageable and reusable. Each component should have a single responsibility and do it well.",
        "this_step_plan": "- Plan the structure of the app\n- Break down the app into smaller components",
        "next_step_plan": "- Write test cases for each component",
        "criticism": "I am following the best practices of React development by breaking down the app into smaller components. Each component will have a single responsibility, which makes the code more manageable and reusable."
    }
}

Multi File Write

Update the WriteFile tool to support multiple file writes at the same time

QA Subagent

Subagent for integration and end-to-end testing

Relevant Code Context

  • store all code written to a dict indexed by path
  • retrieve as per the next step tbd
  • add it to the prompt

JSON parse error

The next command to use is "write_file" to create the TodoList component.

Here is the response in the specified format:

{
    "thoughts": {
        "text": "Now that the TodoItem component is created, I need to create the TodoList component. This component will display a list of TodoItem components. It will also contain a form for adding new todos.",
        "reasoning": "The TodoList component is necessary for displaying the list of todos and for adding new todos. It will use the TodoItem component to display individual todos.",
        "this_step_plan": "- Create a new file for the TodoList component in the src/components directory\n- Write the basic structure of the TodoList component\n- Include a form for adding new todos",
        "next_step_plan": "- Write tests for the TodoList and TodoItem components\n- Implement the main App component",
        "criticism": "I am following the plan and breaking down the application into smaller components. This will make it easier to manage and test the code."
    },
    "command": {
        "name": "write_file",
        "args": {
            "file_path": "/Users/rajiv/Downloads/projects/todo-app/src/components/TodoList.js",
            "text": "import React, { useState } from 'react';\nimport TodoItem from './TodoItem';\n\nconst TodoList = () => {\n  const [todos, setTodos] = useState([]);\n  const [newTodo, setNewTodo] = useState('');\n\n  const addTodo = (event) => {\n    event.preventDefault();\n    setTodos([...todos, { text: newTodo }]);\n    setNewTodo('');\n  };\n\n  return (\n    <div>\n      <form onSubmit={addTodo}>\n        <input type='text' value={newTodo} onChange={(e) => setNewTodo(e.target.value)} />\n        <button type='submit'>Add Todo</button>\n      </form>\n      <ul>\n        {todos.map((todo, index) => <TodoItem key={index} todo={todo} />)}\n      </ul>\n    </div>\n  );\n};\n\nexport default TodoList;"
        }
    }
}

Framework Instructions

  • index best practices for React/Vue/Flask/Express/Laravel etc.
  • save them to a vectorestore
  • retrieve relevant best practice and add it to the prompt

Ctags

Experiment for ctags to provide more context about the code

Search Tool

Add a search tool to help it research issues and find resolutions to issues (search engine for AI?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.