()
| 10 | * Defines the commands supported by the Codepilot CLI. |
| 11 | */ |
| 12 | export async function run() { |
| 13 | // prettier-ignore |
| 14 | const args = await yargs(hideBin(process.argv)) |
| 15 | .scriptName('codepilot') |
| 16 | .command('$0', 'chat mode', {}, async () => { |
| 17 | // Ensure index exists and has keys |
| 18 | const index = new CodeIndex(); |
| 19 | if (!await index.isCreated()) { |
| 20 | console.log(Colorize.output([ |
| 21 | `We need to first create an index before you can chat with Codepilot.`, |
| 22 | `You'll need to provide an OpenAI API key and a source folder to index.`, |
| 23 | `You can create an OpenAI API key at https://platform.openai.com/account/api-keys.`, |
| 24 | `A paid account is recommended but OpenAI will give you $5 in free credits to get started.`, |
| 25 | `Once you have your OpenAI API key, you can create a new index by running:\n`, |
| 26 | `codepilot create --key <api key> --source <source folder> [--source <additional source folder>]\n`, |
| 27 | `By default, all files under your source folders will be included in the index.`, |
| 28 | `If you'd only like certain file extensions to be indexed, you can add the "--extension <included extensions> [--extension <additional extension>]" option.`, |
| 29 | `Once the index has finished building, you can start chatting with Codepilot by running:\n`, |
| 30 | `codepilot\n`, |
| 31 | ].join(`\n`))); |
| 32 | return; |
| 33 | } |
| 34 | if (!await index.hasKeys()) { |
| 35 | console.log(Colorize.output([ |
| 36 | `A Codepilot index was found but you haven't configured your personal OpenAI key.`, |
| 37 | `You'll need to provide an OpenAI API key before you can continue.`, |
| 38 | `You can create an OpenAI API key at https://platform.openai.com/account/api-keys.`, |
| 39 | `A paid account is recommended but OpenAI will give you $5 in free credits to get started.`, |
| 40 | `Once you have your OpenAI API key, you can configure your local index to use that key by running:\n`, |
| 41 | `codepilot set --key <api key>\n`, |
| 42 | `Once you've configured your personal key, you can start chatting with Codepilot by running:\n`, |
| 43 | `codepilot\n`, |
| 44 | ].join(`\n`))); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | // Load index |
| 49 | await index.load(); |
| 50 | |
| 51 | // Start a Codepilot chat session |
| 52 | const codepilot = new Codepilot(index); |
| 53 | registerFunctions(codepilot); |
| 54 | await codepilot.chat(); |
| 55 | }) |
| 56 | .command('create', `creates a new code index`, (yargs) => { |
| 57 | return yargs |
| 58 | .option('key', { |
| 59 | alias: 'k', |
| 60 | describe: 'OpenAI API key to use for generating embeddings and querying the model.', |
| 61 | type: 'string' |
| 62 | }) |
| 63 | .option('model', { |
| 64 | alias: 'm', |
| 65 | describe: 'OpenAI model to use for queries. Defaults to "gpt-3.5-turbo-16k".', |
| 66 | type: 'string', |
| 67 | default: 'gpt-3.5-turbo-16k' |
| 68 | }) |
| 69 | .option('source', { |
nothing calls this directly
no test coverage detected