Merge pull request #4809 from ethereum/ask_sol_gpt
switched open gpt to solcoder for error explainingpull/4865/head
commit
2a4235b78a
@ -1,49 +0,0 @@ |
||||
import { Plugin } from '@remixproject/engine' |
||||
import { CreateChatCompletionResponse } from 'openai' |
||||
|
||||
const _paq = (window._paq = window._paq || []) |
||||
|
||||
const profile = { |
||||
name: 'openaigpt', |
||||
displayName: 'openaigpt', |
||||
description: 'openaigpt', |
||||
methods: ['message'], |
||||
events: [], |
||||
maintainedBy: 'Remix', |
||||
} |
||||
|
||||
export class OpenAIGpt extends Plugin { |
||||
constructor() { |
||||
super(profile) |
||||
} |
||||
|
||||
async message(prompt): Promise<CreateChatCompletionResponse> { |
||||
this.call('layout', 'maximizeTerminal') |
||||
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: 'Waiting for GPT answer...' }) |
||||
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: 'aitypewriterwarning', value: result.choices[0].message.content }) |
||||
} else if (result.error) { |
||||
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result.error }) |
||||
} else { |
||||
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: 'No response...' }) |
||||
} |
||||
return result.data |
||||
} |
||||
} |
Loading…
Reference in new issue