Add full report context for askGPT

pull/5370/head
ioedeveloper 1 year ago
parent 32748bdc95
commit b4b124ec48
  1. 51
      apps/circuit-compiler/src/app/components/container.tsx
  2. 8
      apps/circuit-compiler/src/app/components/feedback.tsx
  3. 2
      apps/circuit-compiler/src/app/types/index.ts

@ -10,7 +10,7 @@ import { CircuitActions } from './actions'
import { WitnessToggler } from './witnessToggler'
import { WitnessSection } from './witness'
import { CompilerFeedback } from './feedback'
import { PrimeValue } from '../types'
import { CompilerReport, PrimeValue } from '../types'
export function Container () {
const circuitApp = useContext(CircuitAppContext)
@ -58,26 +58,41 @@ export function Container () {
circuitApp.dispatch({ type: 'SET_HIDE_WARNINGS', payload: value })
}
const askGPT = async (error: string, location?: string) => {
if (location) {
const fullPathLocation = await circuitApp.plugin.resolveReportPath(location)
const content = await circuitApp.plugin.call('fileManager', 'readFile', fullPathLocation)
const message = `
solidity code: ${content}
error message: ${error}
explain why the error occurred and how to fix it.
`
// @ts-ignore
await circuitApp.plugin.call('openaigpt', 'message', message)
} else if(error) {
const askGPT = async (report: CompilerReport) => {
circuitApp.appState.filePathToId[report.labels[0].file_id], circuitApp.appState.filePathToId[report.labels[0].message]
if (report.labels.length > 0) {
const location = circuitApp.appState.filePathToId[report.labels[0].file_id]
const error = report.labels[0].message
if (location) {
const fullPathLocation = await circuitApp.plugin.resolveReportPath(location)
const content = await circuitApp.plugin.call('fileManager', 'readFile', fullPathLocation)
const message = `
solidity code: ${content}
error message: ${error}
context: ${JSON.stringify(report, null, 2)}
explain why the error occurred and how to fix it.
`
// @ts-ignore
await circuitApp.plugin.call('openaigpt', 'message', message)
} else {
const message = `
error message: ${error}
context: ${JSON.stringify(report, null, 2)}
explain why the error occurred and how to fix it.
`
// @ts-ignore
await circuitApp.plugin.call('openaigpt', 'message', message)
}
} else {
const error = report.message
const message = `
error message: ${error}
explain why the error occurred and how to fix it.
`
error message: ${error}
context: ${JSON.stringify(report, null, 2)}
explain why the error occurred and how to fix it.
`
// @ts-ignore
await circuitApp.plugin.call('openaigpt', 'message', message)
} else {
console.error('unable to askGtp, no message provided')
}
}

@ -17,8 +17,8 @@ export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openEr
}
}
const handleAskGPT = (message: string, location?: string) => {
askGPT(message, location)
const handleAskGPT = (report: CompilerReport) => {
askGPT(report)
}
return (
@ -47,7 +47,7 @@ export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openEr
<FeedbackAlert
message={response.message}
location={ response.labels[0] ? response.labels[0].message + ` ${filePathToId[response.labels[0].file_id]}:${response.labels[0].range.start}:${response.labels[0].range.end}` : null}
askGPT={ () => handleAskGPT(filePathToId[response.labels[0].file_id], filePathToId[response.labels[0].message]) } />
askGPT={ () => handleAskGPT(response) } />
</div>
</RenderIf>
<RenderIf condition={(response.type === 'Warning') && !hideWarnings}>
@ -55,7 +55,7 @@ export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openEr
<FeedbackAlert
message={response.message}
location={null}
askGPT={() => { handleAskGPT(response.message) }} />
askGPT={() => { handleAskGPT(response) }} />
</div>
</RenderIf>
</div>

@ -52,7 +52,7 @@ export type CompilerFeedbackProps = {
filePathToId: Record<string, string>,
openErrorLocation: (location: string, startRange: string) => void,
hideWarnings: boolean,
askGPT: (message: string, location?: string) => void
askGPT: (report: CompilerReport) => void
}
export type CompilerReport = {

Loading…
Cancel
Save