| 23 | |
| 24 | |
| 25 | const cleanUpOpenaiOutput = (suggestion, isLastLine) => { |
| 26 | if (!isLastLine){ |
| 27 | return suggestion.split("\n").length == 1 ? suggestion : suggestion.split("\n")[0] |
| 28 | } |
| 29 | |
| 30 | suggestion = suggestion.replace(/\u200B/g, '') |
| 31 | let outPutIndex = suggestion.indexOf("\n\n§ Output") |
| 32 | |
| 33 | |
| 34 | if (outPutIndex == -1) { |
| 35 | let outPutIndex = suggestion.indexOf("\n\n# Output") |
| 36 | |
| 37 | return outPutIndex == -1 ? suggestion : suggestion.substring(0, outPutIndex) |
| 38 | } else { |
| 39 | return suggestion.substring(0, outPutIndex) |
| 40 | } |
| 41 | |
| 42 | } |
| 43 | |
| 44 | // Function to send request to OpenAI API |
| 45 | api.sendToOpenAI = async (prompt, apiKey, modelType, isLastLine) => { |