aider icon indicating copy to clipboard operation
aider copied to clipboard

Implement API mode in Aider tool

Open nathansenn opened this issue 2 years ago • 2 comments

This introduces an API mode for the Aider tool. The following changes are made:

An api.py file is created to define the API endpoints. Endpoints such as '/message', '/add', and '/drop' are created, which respectively handle messaging, adding and dropping of files.

The base_coder.py file is updated to include and initiate the API. A Flask application is created and its instance is passed to the API class.

Changes are made to commands.py file to accommodate the API mode. Depending on whether the API mode is enabled or not, responses are returned as API responses or are logged using the I/O tool.

The io.py file is modified to include an 'api' argument in the InputOutput class, which is used to indicate whether the tool is running in API mode.

The main.py file is also updated to include a new argument '--api' to start the tool in API mode.

The overall changes aim at providing a means to interact with the Aider tool using API requests, in addition to the existing CLI mode.

nathansenn avatar Jul 07 '23 22:07 nathansenn

Thanks for trying out aider and for putting together this pull request. I definitely want to add this sort of an API to the tool at some point, but I think I need to refactor the main coder class before it makes sense to do that.

I'm curious though, do you have a specific use case in mind for an API?

paul-gauthier avatar Jul 11 '23 18:07 paul-gauthier

@paul-gauthier I thought about it at somepoint too... i thought about modifying aider to set up an API or an alternative CLI for some automated actions remotely. Example add a step of code review in the pipeline by setting up some coding rules ... etc.. But I believe, anything else you gonna do in a non-interactive way it's risky. Because even if there was a GPT 10, you would always need to validate the actions.

GreazySpoon avatar Jul 13 '23 17:07 GreazySpoon

Thanks for trying out aider and for putting together this pull request. I definitely want to add this sort of an API to the tool at some point, but I think I need to refactor the main coder class before it makes sense to do that.

I'm curious though, do you have a specific use case in mind for an API?

Im building a browser UI for this tool and need an API to interact with it

nathansenn avatar Jul 17 '23 09:07 nathansenn

That sounds awesome. I do hope to package up aider into a clean library and api. So you should be able to plug into that when it's ready.

paul-gauthier avatar Jul 17 '23 13:07 paul-gauthier

I'm going to close this PR as it has drifted pretty far from the main branch.

paul-gauthier avatar Jul 31 '23 12:07 paul-gauthier

@nathansenn I've implemented a REST API to interface with Aider, taking an alternative approach than yours.

Given the complexity of the Aider codebase, and having reviewed your previous pull request, I shied away from direct modifications to the aider source for this feature.

Instead, I chose to leverage Aider's existing command-line system, specifically utilizing the --message option. This approach ensures that my addition remains decoupled from any future updates to Aider, requiring no changes to the core codebase. It's also worth noting that the command-line interface provides a remarkably stable API.

Here's the relevant code: aider REST API - the idea and execution is very simple.

I've included both serve.py and serve.sh in my Aider code base, but they could just as easily be maintained separately. Aider itself doesn't need adjusted or be aware of the service. The requirements are fastapi and uvicorn.

I see this implementation as proof-of-concept. It has many limitations, particularly concerning security (auth, ssl and protection against injection of unwanted commands is completely missing). Also concurrency (e.g., the system may not handle multiple simultaneous REST calls well). And most of Aider's advanced features cannot be used with this implementation.

Finally, I'd recommend against using other elements from my fork of Aider. It has significantly diverged from the main project and has been customized for specific use-cases that may not be universally applicable.

kwmiebach avatar Aug 21 '23 17:08 kwmiebach