Merge branch 'master' into ai_setting

pull/5370/head
Aniket 6 months ago committed by GitHub
commit 7e9207f9a6
  1. 39
      apps/remix-ide/src/app/plugins/solcoderAI.tsx
  2. 12
      libs/remix-ui/run-tab/src/lib/components/environment.tsx

@ -19,14 +19,32 @@ const profile = {
events: [], events: [],
maintainedBy: 'Remix', maintainedBy: 'Remix',
} }
type ChatEntry = [string, string];
enum BackendOPModel{
DeeSeek,
CodeLLama,
Mistral
}
const PromptBuilder = (inst, answr, modelop) => {
if (modelop === BackendOPModel.CodeLLama) return "\n### INSTRUCTION:\n" + inst + "\n### RESPONSE:\n" + answr
if (modelop === BackendOPModel.DeeSeek) return ""
if (modelop === BackendOPModel.Mistral) return ""
}
export class SolCoder extends Plugin { export class SolCoder extends Plugin {
api_url: string api_url: string
completion_url: string completion_url: string
solgpt_chat_history:ChatEntry[]
max_history = 7
model_op = BackendOPModel.CodeLLama
constructor() { constructor() {
super(profile) super(profile)
this.api_url = "https://solcoder.remixproject.org" this.api_url = "https://solcoder.remixproject.org"
this.completion_url = "https://completion.remixproject.org" this.completion_url = "https://completion.remixproject.org"
this.solgpt_chat_history = []
} }
async code_generation(prompt): Promise<any> { async code_generation(prompt): Promise<any> {
@ -62,6 +80,7 @@ export class SolCoder extends Plugin {
this.call('layout', 'maximizeTerminal') this.call('layout', 'maximizeTerminal')
let result let result
try { try {
const main_prompt = this._build_solgpt_promt(prompt)
result = await( result = await(
await fetch(this.api_url, { await fetch(this.api_url, {
method: 'POST', method: 'POST',
@ -69,17 +88,21 @@ export class SolCoder extends Plugin {
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ "data":[prompt, "solidity_answer", false,1000,0.9,0.8,50]}), body: JSON.stringify({ "data":[main_prompt, "solidity_answer", false,1000,0.9,0.8,50]}),
}) })
).json() ).json()
} catch (e) { } catch (e) {
this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` }) this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` })
this.solgpt_chat_history = []
return return
} finally { } finally {
this.emit("aiInferingDone") this.emit("aiInferingDone")
} }
if (result) { if (result) {
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result.data[0] }) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result.data[0] })
const chat:ChatEntry = [prompt, result.data[0]]
this.solgpt_chat_history.push(chat)
if (this.solgpt_chat_history.length >this.max_history){this.solgpt_chat_history.shift()}
} else if (result.error) { } else if (result.error) {
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "Error on request" }) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "Error on request" })
} }
@ -195,4 +218,18 @@ export class SolCoder extends Plugin {
} }
} }
_build_solgpt_promt(user_promt:string){
if (this.solgpt_chat_history.length === 0){
return user_promt
} else {
let new_promt = ""
for (const [question, answer] of this.solgpt_chat_history) {
new_promt += PromptBuilder(question.split('sol-gpt')[1], answer, this.model_op)
}
// finaly
new_promt = "sol-gpt " + new_promt + PromptBuilder(user_promt.split('sol-gpt')[1], "", this.model_op)
return new_promt
}
}
} }

@ -15,10 +15,10 @@ export function EnvironmentUI(props: EnvironmentProps) {
const currentProvider = props.providers.providerList.find((exEnv) => exEnv.name === props.selectedEnv) const currentProvider = props.providers.providerList.find((exEnv) => exEnv.name === props.selectedEnv)
const bridges = { const bridges = {
'L2 - Optimism': 'https://app.optimism.io/bridge/deposit', 'L2 - Optimism': 'https://app.optimism.io/bridge/deposit',
'L2 - Arbitrum One': 'https://bridge.arbitrum.io/' 'L2 - Arbitrum': 'https://bridge.arbitrum.io/'
} }
const isL2 = (providerDisplayName: string) => providerDisplayName === 'Optimism Provider' || providerDisplayName === 'Arbitrum One Provider' const isL2 = (providerDisplayName: string) => providerDisplayName === 'L2 - Optimism' || providerDisplayName === 'L2 - Arbitrum'
return ( return (
<div className="udapp_crow"> <div className="udapp_crow">
<label id="selectExEnv" className="udapp_settingsLabel"> <label id="selectExEnv" className="udapp_settingsLabel">
@ -38,16 +38,16 @@ export function EnvironmentUI(props: EnvironmentProps) {
<div className="udapp_environment"> <div className="udapp_environment">
<Dropdown id="selectExEnvOptions" data-id="settingsSelectEnvOptions" className="udapp_selectExEnvOptions"> <Dropdown id="selectExEnvOptions" data-id="settingsSelectEnvOptions" className="udapp_selectExEnvOptions">
<Dropdown.Toggle as={CustomToggle} id="dropdown-custom-components" className="btn btn-light btn-block w-100 d-inline-block border border-dark form-control" icon={null}> <Dropdown.Toggle as={CustomToggle} id="dropdown-custom-components" className="btn btn-light btn-block w-100 d-inline-block border border-dark form-control" icon={null}>
{isL2(currentProvider && currentProvider.displayName) && 'L2 - '} {isL2(currentProvider && currentProvider.displayName)}
{currentProvider && currentProvider.displayName} {currentProvider && currentProvider.displayName}
{currentProvider && bridges[currentProvider.name] && ( {currentProvider && bridges[currentProvider.displayName] && (
<CustomTooltip placement={'right'} tooltipClasses="text-nowrap" tooltipId="info-recorder" tooltipText={<FormattedMessage id="udapp.tooltipText3" />}> <CustomTooltip placement={'right'} tooltipClasses="text-nowrap" tooltipId="info-recorder" tooltipText={<FormattedMessage id="udapp.tooltipText3" />}>
<i <i
style={{ fontSize: 'medium' }} style={{ fontSize: 'medium' }}
className={'ml-2 fa fa-rocket-launch'} className={'ml-2 fa fa-rocket-launch'}
aria-hidden="true" aria-hidden="true"
onClick={() => { onClick={() => {
window.open(bridges[currentProvider.name], '_blank') window.open(bridges[currentProvider.displayName], '_blank')
}} }}
></i> ></i>
</CustomTooltip> </CustomTooltip>
@ -63,7 +63,7 @@ export function EnvironmentUI(props: EnvironmentProps) {
data-id={`dropdown-item-${name}`} data-id={`dropdown-item-${name}`}
> >
<span className=""> <span className="">
{isL2(displayName) && 'L2 - '} {isL2(displayName)}
{displayName} {displayName}
</span> </span>
</Dropdown.Item> </Dropdown.Item>

Loading…
Cancel
Save