* Starts the chat session and listens for user input.
()
| 72 | * Starts the chat session and listens for user input. |
| 73 | */ |
| 74 | chat() { |
| 75 | return __awaiter(this, void 0, void 0, function* () { |
| 76 | // Create a readline interface object with the standard input and output streams |
| 77 | const rl = readline.createInterface({ |
| 78 | input: process.stdin, |
| 79 | output: process.stdout |
| 80 | }); |
| 81 | // Create model and wave |
| 82 | const model = this.createModel(); |
| 83 | const wave = new alphawave_1.AlphaWave({ |
| 84 | model, |
| 85 | prompt: new promptrix_1.Prompt([ |
| 86 | new promptrix_1.SystemMessage([ |
| 87 | `You are an expert software developer.`, |
| 88 | `You are chatting with another developer who is asking for help with the project they're working on.`, |
| 89 | ].join('\n')), |
| 90 | new SourceCodeSection_1.SourceCodeSection(this._index, 0.6), |
| 91 | new promptrix_1.ConversationHistory('history', 0.4), |
| 92 | new promptrix_1.UserMessage('{{$input}}', 500) |
| 93 | ]) |
| 94 | }); |
| 95 | // Define main chat loop |
| 96 | const _that = this; |
| 97 | function respond(botMessage) { |
| 98 | return __awaiter(this, void 0, void 0, function* () { |
| 99 | function completePrompt(input) { |
| 100 | return __awaiter(this, void 0, void 0, function* () { |
| 101 | // Route users message to wave |
| 102 | const result = yield wave.completePrompt(input); |
| 103 | switch (result.status) { |
| 104 | case 'success': |
| 105 | const message = result.message; |
| 106 | if (message.function_call) { |
| 107 | // Call function and add result to history |
| 108 | const entry = _that._functions.get(message.function_call.name); |
| 109 | if (entry) { |
| 110 | const args = message.function_call.arguments ? JSON.parse(message.function_call.arguments) : {}; |
| 111 | const result = yield entry.fn(args); |
| 112 | wave.addFunctionResultToHistory(message.function_call.name, result); |
| 113 | // Call back in with the function result |
| 114 | yield completePrompt(''); |
| 115 | } |
| 116 | else { |
| 117 | respond(internals_1.Colorize.error(`Function '${message.function_call.name}' was not found.`)); |
| 118 | } |
| 119 | } |
| 120 | else { |
| 121 | // Call respond to display response and wait for user input |
| 122 | yield respond(internals_1.Colorize.output(message.content)); |
| 123 | } |
| 124 | break; |
| 125 | default: |
| 126 | if (result.message) { |
| 127 | yield respond(internals_1.Colorize.error(`${result.status}: ${result.message}`)); |
| 128 | } |
| 129 | else { |
| 130 | yield respond(internals_1.Colorize.error(`A result status of '${result.status}' was returned.`)); |
| 131 | } |
no test coverage detected