| 95 | } |
| 96 | |
| 97 | async function sendCodeToServer(code, mode) { |
| 98 | const url = vscode.workspace.getConfiguration().get('codexpert.serverurl') |
| 99 | await vscode.window.withProgress({ |
| 100 | location: vscode.ProgressLocation.Notification, |
| 101 | title: `${mode} Let me think...`, |
| 102 | cancellable: false |
| 103 | }, async (progress, token) => { |
| 104 | try { |
| 105 | const headers = { |
| 106 | 'Content-Type': 'application/json', |
| 107 | }; |
| 108 | const requestData = { |
| 109 | prompt: code, |
| 110 | mode: mode // Use the mode provided as an argument |
| 111 | }; |
| 112 | const response = await axios.post(url, requestData, { |
| 113 | headers: headers |
| 114 | }); |
| 115 | |
| 116 | const content = response.data['responses'][0]['text']; |
| 117 | const editor = vscode.window.activeTextEditor; |
| 118 | if (editor) { |
| 119 | editor.edit(editBuilder => { |
| 120 | editBuilder.insert(editor.document.positionAt(code.length), content); |
| 121 | }); |
| 122 | } |
| 123 | vscode.window.showInformationMessage('I wrote the code!'); |
| 124 | } catch (error) { |
| 125 | vscode.window.showErrorMessage('Error : ' + error.message); |
| 126 | } |
| 127 | }); |
| 128 | } |
| 129 | |
| 130 | function deactivate() {} |
| 131 | |