finish askGpt implementation. cleanup

pull/4585/head
Joseph Izang 9 months ago
parent 061455e8f4
commit df3f54c16a
  1. 2
      apps/vyper/src/app/app.tsx
  2. 9
      apps/vyper/src/app/components/CompileErrorCard.tsx
  3. 4
      apps/vyper/src/app/utils/compiler.tsx
  4. 11
      apps/vyper/src/app/utils/remix-client.tsx

@ -170,7 +170,7 @@ const App = () => {
<VyperResult output={output} plugin={remixClient} /> <VyperResult output={output} plugin={remixClient} />
</> </>
) : output.status === 'failed' ? ( ) : output.status === 'failed' ? (
<CompileErrorCard output={output} askGpt={remixClient.askGpt} /> <CompileErrorCard output={output} plugin={remixClient} />
) : null} ) : null}
</article> </article>
</section> </section>

@ -1,7 +1,8 @@
import {CopyToClipboard} from '@remix-ui/clipboard' import {CopyToClipboard} from '@remix-ui/clipboard'
import Reaact from 'react' import Reaact from 'react'
import { RemixClient } from '../utils'
export function CompileErrorCard(props: any) { export function CompileErrorCard(props: { output: any, plugin: RemixClient }) {
return ( return (
<div <div
id="vyperErrorResult" id="vyperErrorResult"
@ -18,16 +19,16 @@ export function CompileErrorCard(props: any) {
> >
{props.output.message.trim()} {props.output.message.trim()}
</span> </span>
{/* <div className="d-flex flex-column pt-3 align-items-end mb-2"> <div className="d-flex flex-column pt-3 align-items-end mb-2">
<div> <div>
<span className="border border-success text-success btn-sm" onClick={() => props.askGpt(props.output.message)}> <span className="border border-success text-success btn-sm" onClick={async () => await props.plugin.askGpt(props.output.message)}>
Ask GPT Ask GPT
</span> </span>
<span className="ml-3 pt-1 py-1"> <span className="ml-3 pt-1 py-1">
<CopyToClipboard content={props.output.message} className={`p-0 m-0 far fa-copy alert alert-danger`} direction={'top'} /> <CopyToClipboard content={props.output.message} className={`p-0 m-0 far fa-copy alert alert-danger`} direction={'top'} />
</span> </span>
</div> </div>
</div> */} </div>
</div> </div>
) )
} }

@ -50,12 +50,10 @@ function parseErrorString(errorString) {
// Split the string into lines // Split the string into lines
let lines = errorString.trim().split('\n') let lines = errorString.trim().split('\n')
// Extract the line number and message // Extract the line number and message
console.log(lines)
let message = errorString.trim() let message = errorString.trim()
let targetLine = lines[2].split(',') let targetLine = lines[2].split(',')
let tline = lines[2].trim().split(' ')[1].split(':') let tline = lines[2].trim().split(' ')[1].split(':')
console.log('tline', tline)
const errorObject = { const errorObject = {
status: 'failed', status: 'failed',
message: message, message: message,
@ -192,7 +190,6 @@ export async function compile(url: string, contract: Contract): Promise<any> {
method: 'Get' method: 'Get'
})).data })).data
result = parseErrorString(intermediate[0]) result = parseErrorString(intermediate[0])
console.log('error payload', intermediate)
return result return result
} }
await new Promise((resolve) => setTimeout(() => resolve({}), 3000)) await new Promise((resolve) => setTimeout(() => resolve({}), 3000))
@ -273,7 +270,6 @@ export async function compileContract(contract: string, compilerUrl: string, set
// try { // try {
output = await compile(compilerUrl, _contract) output = await compile(compilerUrl, _contract)
if (output.status === 'failed') { if (output.status === 'failed') {
console.log('possible error', output)
remixClient.changeStatus({ remixClient.changeStatus({
key: 'failed', key: 'failed',
type: 'error', type: 'error',

@ -61,8 +61,16 @@ export class RemixClient extends PluginClient {
} }
async askGpt(message: string) { async askGpt(message: string) {
if (message.length === 0) {
this.client.call('terminal', 'log', { type: 'log', value: 'kindly send a proper message so I can respond please' })
return
}
try { try {
await this.client.call('openaigpt', 'message', message) const formattedMessage = `
${message}
can you explain why this error occurred and how to fix it?
`
await this.client.call('openaigpt' as any, 'message', formattedMessage)
} catch (err) { } catch (err) {
console.error('unable to askGpt') console.error('unable to askGpt')
console.error(err) console.error(err)
@ -153,4 +161,3 @@ export class RemixClient extends PluginClient {
} }
export const remixClient = new RemixClient() export const remixClient = new RemixClient()
// export const RemixClientContext = React.createContext(new RemixClient())

Loading…
Cancel
Save