added context to code explaining

pull/5370/head
Stéphane Tetsing 10 months ago committed by Aniket
parent 8bc21c290a
commit 416d237b64
  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.emit("aiInfering")
this.call('layout', 'maximizeTerminal') this.call('layout', 'maximizeTerminal')
let result let result
@ -98,7 +98,7 @@ export class SolCoder extends Plugin {
Accept: 'application/json', Accept: 'application/json',
'Content-Type': '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() ).json()
if (result) { if (result) {

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

Loading…
Cancel
Save