make the code safer

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

@ -19,19 +19,28 @@ export class OpenAIGpt extends Plugin {
async message(prompt): Promise<CreateChatCompletionResponse> {
this.call('terminal', 'log', 'Waiting for GPT answer...')
const result = await (
await fetch('https://openai-gpt.remixproject.org', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt }),
})
).json()
let result
try {
result = await (
await fetch('https://openai-gpt.remixproject.org', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
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)
this.call('terminal', 'log', { type: 'typewritersuccess', value: result.choices[0].message.content })
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