edited text

pull/5370/head
Stéphane Tetsing 9 months ago
parent e2260d44ad
commit 7d9933457a
  1. 29
      apps/remix-ide/src/app/plugins/solcoderAI.tsx
  2. 2
      apps/remix-ide/src/app/tabs/locales/en/remixUiTabs.json
  3. 27
      libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx

@ -7,7 +7,7 @@ const profile = {
name: 'solcoder',
displayName: 'solcoder',
description: 'solcoder',
methods: ['code_generation', 'code_completion', "solidity_answer"],
methods: ['code_generation', 'code_completion', "solidity_answer", "code_explaining"],
events: [],
maintainedBy: 'Remix',
}
@ -74,6 +74,33 @@ export class SolCoder extends Plugin {
}
async code_explaining(prompt): Promise<any> {
this.emit("aiInfering")
this.call('layout', 'maximizeTerminal')
this.call('terminal', 'log', 'Waiting for Solcoder answer...')
let result
try {
result = await(
await fetch(this.api_url.concat("code_explaining"), {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({"data":[prompt,false,2000,0.9,0.8,50]}),
})
).json()
if (result) {
this.call('terminal', 'log', { type: 'typewriterwarning', value: result.data[0]})
}
return result.data[0]
} catch (e) {
this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` })
return
}finally {
this.emit("aiInferingDone")
}
}
async code_completion(prompt, options:SuggestOptions=null): Promise<any> {
this.emit("aiInfering")

@ -2,6 +2,8 @@
"remixUiTabs.tooltipText1": "Run script (CTRL + SHIFT + S)",
"remixUiTabs.tooltipText2": "Compile CTRL + S",
"remixUiTabs.tooltipText3": "Select .sol or .yul file to compile or a .ts or .js file and run it",
"remixUiTabs.tooltipText4": "Select .sol file",
"remixUiTabs.tooltipText5": "Explain the contract/s in current file",
"remixUiTabs.zoomOut": "Zoom out",
"remixUiTabs.zoomIn": "Zoom in"
}

@ -204,19 +204,20 @@ export const TabsUI = (props: TabsUIProps) => {
</CustomTooltip>
</button>
<button
data-id="play-editor"
data-id="explain-editor"
id='explain_btn'
className="btn text-success py-0"
disabled={!(tabsState.currentExt === 'sol' )}
onClick={async () => {
const path = active().substr(active().indexOf('/') + 1, active().length)
const content = await props.plugin.call('fileManager', 'readFile', path)
if (tabsState.currentExt === 'js' || tabsState.currentExt === 'ts') {
await props.plugin.call('scriptRunner', 'execute', content, path)
_paq.push(['trackEvent', 'editor', 'clickRunFromEditor', tabsState.currentExt])
} else if (tabsState.currentExt === 'sol') {
await props.plugin.call('solcoder', 'solidity_answer', content)
if (tabsState.currentExt === 'sol') {
(document.getElementById('explain_btn') as HTMLButtonElement).disabled = true;
const result = await props.plugin.call('solcoder', 'code_explaining', content)
_paq.push(['trackEvent', 'ai', 'solcoder', 'explain_file'])
}
(document.getElementById('explain_btn') as HTMLButtonElement).disabled = false;
}}
>
<CustomTooltip
@ -224,19 +225,21 @@ export const TabsUI = (props: TabsUIProps) => {
tooltipId="overlay-tooltip-run-script"
tooltipText={
<span>
{tabsState.currentExt === 'js' || tabsState.currentExt === 'ts' ? (
<FormattedMessage id="remixUiTabs.tooltipText1" />
) : tabsState.currentExt === 'sol' || tabsState.currentExt === 'yul' || tabsState.currentExt === 'circom' ? (
<FormattedMessage id="remixUiTabs.tooltipText2" />
{tabsState.currentExt === 'sol'? (
<FormattedMessage id="remixUiTabs.tooltipText5" />
) : (
<FormattedMessage id="remixUiTabs.tooltipText3" />
<FormattedMessage id="remixUiTabs.tooltipText4" />
)}
</span>
}
>
<i className="fad fa-play"></i>
<i className="fa-solid fa-message-exclamation"></i>
</CustomTooltip>
</button>
<script>
const button = document.querySelector('#button');
</script>
<CustomTooltip placement="bottom" tooltipId="overlay-tooltip-zoom-out" tooltipText={<FormattedMessage id="remixUiTabs.zoomOut" />}>
<span data-id="tabProxyZoomOut" className="btn btn-sm px-2 fas fa-search-minus text-dark" onClick={() => props.onZoomOut()}></span>
</CustomTooltip>

Loading…
Cancel
Save