added context to code explaining

pull/4705/head
Stéphane Tetsing 7 months ago committed by Aniket
parent acb0de6b5c
commit f3777b5137
  1. 4
      apps/remix-ide/src/app/plugins/solcoderAI.tsx
  2. 7
      libs/remix-ui/editor/src/lib/remix-ui-editor.tsx

@ -86,7 +86,7 @@ export class SolCoder extends Plugin {
}
async code_explaining(prompt): Promise<any> {
async code_explaining(prompt, context:string=""): Promise<any> {
this.emit("aiInfering")
this.call('layout', 'maximizeTerminal')
let result
@ -98,7 +98,7 @@ export class SolCoder extends Plugin {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({"data":[prompt, "code_explaining", false,2000,0.9,0.8,50]}),
body: JSON.stringify({"data":[prompt, "code_explaining", context, false,2000,0.9,0.8,50]}),
})
).json()
if (result) {

@ -753,7 +753,7 @@ export const EditorUI = (props: EditorUIProps) => {
const content = await props.plugin.call('fileManager', 'readFile', file)
const selectedCode = editor.getModel().getValueInRange(editor.getSelection())
await props.plugin.call('solcoder', 'code_explaining', selectedCode)
await props.plugin.call('solcoder', 'code_explaining', selectedCode, content)
_paq.push(['trackEvent', 'ai', 'solcoder', 'explainFunction'])
},
}
@ -823,12 +823,15 @@ export const EditorUI = (props: EditorUIProps) => {
freeFunctionCondition.set(false)
return
}
const { nodesAtPosition } = await retrieveNodesAtPosition(props.editorAPI, props.plugin)
const freeFunctionNode = nodesAtPosition.find((node) => node.kind === 'freeFunction')
if (freeFunctionNode) {
executeFreeFunctionAction.label = intl.formatMessage({id: 'editor.executeFreeFunction2'}, {name: freeFunctionNode.name})
freeFunctionAction = editor.addAction(executeFreeFunctionAction)
}
const functionImpl = nodesAtPosition.find((node) => node.kind === 'function')
if (functionImpl) {
currentFunction.current = functionImpl.name
@ -839,6 +842,8 @@ export const EditorUI = (props: EditorUIProps) => {
executeSolgptExplainFunctionAction.label = intl.formatMessage({id: 'editor.explainFunctionSol'})
solgptExplainFunctionAction = editor.addAction(executeSolgptExplainFunctionAction)
}else{
// do not allow single character explaining
if (editor.getModel().getValueInRange(editor.getSelection()).length <=1){ return}
executeSolgptExplainFunctionAction.label = intl.formatMessage({id: 'editor.explainFunctionSol'})
solgptExplainFunctionAction = editor.addAction(executeSolgptExplainFunctionAction)
}

Loading…
Cancel
Save