make the code safer

pull/3850/head
yann300 1 year ago committed by Aniket
parent 142a1381fa
commit f7e0ae3ce2
  1. 13
      apps/remix-ide/src/app/plugins/openaigpt.tsx

@ -19,7 +19,9 @@ export class OpenAIGpt extends Plugin {
async message(prompt): Promise<CreateChatCompletionResponse> {
this.call('terminal', 'log', 'Waiting for GPT answer...')
const result = await (
let result
try {
result = await (
await fetch('https://openai-gpt.remixproject.org', {
method: 'POST',
headers: {
@ -29,9 +31,16 @@ export class OpenAIGpt extends Plugin {
body: JSON.stringify({ prompt }),
})
).json()
} catch (e) {
this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` })
return
}
console.log(result)
if (result && result.choices && result.choices.length) {
this.call('terminal', 'log', { type: 'typewritersuccess', value: result.choices[0].message.content })
} else {
this.call('terminal', 'log', { type: 'typewritersuccess', value: 'No response...' })
}
return result.data
}
}

Loading…
Cancel
Save