()
| 15 | cliMain(); |
| 16 | |
| 17 | async function cliMain() { |
| 18 | config.addItem('apis', apiManager); |
| 19 | |
| 20 | // The CLI interface is stateless. |
| 21 | config.inMemory = true; |
| 22 | config.initFromFileSync(); |
| 23 | |
| 24 | extensionManager.activateBuiltinExtensions(); |
| 25 | |
| 26 | let credentialName; |
| 27 | for (let i = 2; i < process.argv.length; ++i) { |
| 28 | const arg = process.argv[i]; |
| 29 | if (arg == '-h') |
| 30 | help(); |
| 31 | if (arg == '-l') |
| 32 | list(); |
| 33 | if (arg == '--credential') |
| 34 | credentialName = process.argv[i + 1]; |
| 35 | } |
| 36 | |
| 37 | // Find an credential that supports chat service. |
| 38 | const credential = apiManager.getCredentials() |
| 39 | // Only search from chatable credentials. |
| 40 | .filter(credential => { |
| 41 | try { |
| 42 | const {apiClass} = apiManager.getAPIRecord(credential.type); |
| 43 | return matchClass(ChatCompletionAPI, apiClass) || |
| 44 | matchClass(ChatConversationAPI, apiClass); |
| 45 | } catch (error) { |
| 46 | if (error.message.includes('not exist')) |
| 47 | return false; |
| 48 | else |
| 49 | throw error; |
| 50 | } |
| 51 | }) |
| 52 | // Return the one matches name. |
| 53 | .find(credential => credentialName ? credential.name == credentialName : true); |
| 54 | if (!credential) |
| 55 | throw new Error('Can not find an API credential that supports chatting.'); |
| 56 | |
| 57 | // Chat and exit. |
| 58 | await enterConversation(credential); |
| 59 | process.exit(0); |
| 60 | } |
| 61 | |
| 62 | function help() { |
| 63 | console.log(` |
no test coverage detected