make the code safer

pull/5370/head
yann300 2 years ago committed by Aniket
parent 36c3b53e11
commit f9853aab73
  1. 13
      apps/remix-ide/src/app/plugins/openaigpt.tsx

@ -19,7 +19,9 @@ export class OpenAIGpt extends Plugin {
async message(prompt): Promise<CreateChatCompletionResponse> { async message(prompt): Promise<CreateChatCompletionResponse> {
this.call('terminal', 'log', 'Waiting for GPT answer...') this.call('terminal', 'log', 'Waiting for GPT answer...')
const result = await ( let result
try {
result = await (
await fetch('https://openai-gpt.remixproject.org', { await fetch('https://openai-gpt.remixproject.org', {
method: 'POST', method: 'POST',
headers: { headers: {
@ -29,9 +31,16 @@ export class OpenAIGpt extends Plugin {
body: JSON.stringify({ prompt }), body: JSON.stringify({ prompt }),
}) })
).json() ).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 }) 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 return result.data
} }
} }

Loading…
Cancel
Save