Skip to content

Commit

Permalink
make the code safer
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Aug 31, 2023
1 parent 1d2b2cc commit f305c1d
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions apps/remix-ide/src/app/plugins/openaigpt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()

console.log(result)
this.call('terminal', 'log', { type: 'typewritersuccess', value: result.choices[0].message.content })
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
}

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
}
}

0 comments on commit f305c1d

Please sign in to comment.