-
Notifications
You must be signed in to change notification settings - Fork 63
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
Move OPENAI_API_KEY into a user home directory ~/.autopilot/.env file #163
Comments
🤖 This is my suggestion: File: modules/gpt.js
Here's the updated code: const chalk = require('chalk');
const os = require('os');
const path = require('path');
require('dotenv').config()
const { Configuration, OpenAIApi } = require("openai");
const {saveLog} = require('./fsOutput');
let totalTokensUsed = 0
let completionTokens = 0
let promptTokens = 0
let cost = 0
const modelCostMap = {
"gpt-4": {"promptTokensCost": 0.03, "completionTokensCost": 0.06},
"gpt-3.5-turbo": {"tokensCost": 0.002},
};
function loadEnvVariables() {
const envPath = path.join(os.homedir(), '.autopilot', '.env');
require('dotenv').config({ path: envPath });
}
loadEnvVariables();
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
// ... rest of the code This code will load the environment variables from the File: .env.template .env.template
File: README.md Changes to be made in this file
Updated README.mdNote: This project is currently operating autonomously on a server. Whenever an issue is created, it will automatically generate a comment reply suggesting how to fix the issue. Please ensure that any issues created are clear and comprehensible for the autopilot system to process effectively. 🙇♂️
<h1 align="center">Autopilot - An AI developer</h1>
<p align="center">
<strong>Autopilot</strong> is an AI tool that utilizes GPT to read a codebase, create context, and solve tasks that you request.
</p>
<p align="center">
<img src="public/demo.gif" alt="Autopilot Demo" width="800"/>
</p>
# How it works
1. You point AutoPilot at a codebase with a task.
1. AutoPilot generates and upkeeps a DB with metadata on the codebase files. (within the codebase directory)
1. AutoPilot decides which existing files it needs for the task by using the metadata DB.
1. AutoPilot tries to implement the requested task on each relevant file.
## Features
- 📚 - Pre-processes codebase files.
- 🤖 - Implements code changes for you.
- 🚀 - Parallel calls to agents where possible.
- 📝 - Shows you what was updated. (Full process log with each AI interaction also produced)
- 🕹️ - Interactive mode - see the process with retry, continue, abort options.
### Tasks expectations
- Referencing current code:
- ✅ Referencing a specific file by project relative path.
- ✅ Referencing a specific file by file name only, ignoring the subdirectories path.
- ✅ Referencing a specific function within a file without the filename.
- ✅ Referencing a major business concept that is exclusively used in one file.
- ✅ Referencing all project files.
- 🤔 General logical requests. Your milage would differ by model, codebase and task. Some work. (Should introduce task scoring)
- Changes executed:
- ✅Create a new file based on an existing file.
- ❌Start a new file from scratch.
- ✅Update an existing file.
- ✅Update multiple existing files.
- ❌Delete existing files. (It might empty them out, but not delete them currently)
- ❌Start using new 3rd party libraries. (Needs arbitrary code execution to install the library)
- ❌Cascade updating related files like tests. (Coming soon)
- ❌Test the code it wrote and self fix.
## 🛠️ Installation
1. Clone the repository: `git clone https://github.com/fjrdomingues/autopilot.git`
2. Do `cd autopilot` to install dependencies: `npm ci`
3. Set up the environment variables:
1. Create a directory in your home folder named `.autopilot`: `mkdir ~/.autopilot`
2. Create a `.env` file inside the `.autopilot` directory: `touch ~/.autopilot/.env`
3. Open the `.env` file and add the following variables:
- `OPENAI_API_KEY=<your-api-key>` [Create openAI API key](https://platform.openai.com/account/api-keys)
- `CODE_DIR=<path-to-your-code>` (or use `-d path-to-your-code` later)
- `IGNORE_LIST=node_modules,coverage,public,__tests__`
- `FILE_EXTENSIONS_TO_PROCESS=.js,.tsx,.ts,.jsx`
## Running
* `node ui -t "YOUR_TASK"` - is the easiest way to start.
* Solutions will be auto applied on your code and a git diff shown if possible.
* Alternatively you may specify `--auto-apply=false`.
* `node ui -h` - will show you all the options.
## Interactive mode
Use `node ui -i` for an interactive mode, here you can review the output of each step before proceeding.
## 🤝 Contributing
**We are running autopilot on a server connected to the https://github.com/fjrdomingues/autopilot repository. New issues created will trigger autopilot and create a new Pull Request with a proposal. Running with gpt-4**
We welcome contributions! Please submit pull requests to the repository, and ensure your changes align with the project's goals and guidelines. Together, we can make **Autopilot** an even more powerful and efficient tool for developers!
### Running tests - all
`npm run test` - runs all the tests
### Running tests - Unit test
`npm run unit-test` - runs the unit tests
### Running tests - Benchmarks
`npm run e2e-test` - runs the end to end tests
### Code structure
- agents - interactions with language models.
- modules - most other internal libs.
- ui.js - The main().
- logs - document a task run.
|
Background story explaining the current situation:
Currently, the OPENAI_API_KEY is read from the local .env file inside autopilot code directory.
This is not forward-thinking to user experience.
Desired new situation:
OPENAI_API_KEY should be configured in the users home directory
Implementation details:
OPENAI_API_KEY should be validated to exist if
gpt-3.5-turbo
orgpt-4
models are used in one of the models env variables.OPENAI_API_KEY should either come from the user's environment variable or the file in the ~/.autopilot/.env
the
~
should be the home directory across different OSs (windows, max, *nix)Other env variables should also be loaded from the user's .env file.
re: #86
re: #76
The text was updated successfully, but these errors were encountered: