Skip to content

Commit 0c6c57f

Browse files
authored
Merge branch 'master' into ai_setting
2 parents 7d1e738 + 13cec16 commit 0c6c57f

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

apps/remix-ide/src/app/plugins/solcoderAI.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,32 @@ const profile = {
1919
events: [],
2020
maintainedBy: 'Remix',
2121
}
22+
type ChatEntry = [string, string];
23+
24+
enum BackendOPModel{
25+
DeeSeek,
26+
CodeLLama,
27+
Mistral
28+
}
29+
30+
const PromptBuilder = (inst, answr, modelop) => {
31+
if (modelop === BackendOPModel.CodeLLama) return "\n### INSTRUCTION:\n" + inst + "\n### RESPONSE:\n" + answr
32+
if (modelop === BackendOPModel.DeeSeek) return ""
33+
if (modelop === BackendOPModel.Mistral) return ""
34+
}
2235

2336
export class SolCoder extends Plugin {
2437
api_url: string
2538
completion_url: string
39+
solgpt_chat_history:ChatEntry[]
40+
max_history = 7
41+
model_op = BackendOPModel.CodeLLama
42+
2643
constructor() {
2744
super(profile)
2845
this.api_url = "https://solcoder.remixproject.org"
2946
this.completion_url = "https://completion.remixproject.org"
47+
this.solgpt_chat_history = []
3048
}
3149

3250
async code_generation(prompt): Promise<any> {
@@ -62,24 +80,29 @@ export class SolCoder extends Plugin {
6280
this.call('layout', 'maximizeTerminal')
6381
let result
6482
try {
83+
const main_prompt = this._build_solgpt_promt(prompt)
6584
result = await(
6685
await fetch(this.api_url, {
6786
method: 'POST',
6887
headers: {
6988
Accept: 'application/json',
7089
'Content-Type': 'application/json',
7190
},
72-
body: JSON.stringify({ "data":[prompt, "solidity_answer", false,1000,0.9,0.8,50]}),
91+
body: JSON.stringify({ "data":[main_prompt, "solidity_answer", false,1000,0.9,0.8,50]}),
7392
})
7493
).json()
7594
} catch (e) {
7695
this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` })
96+
this.solgpt_chat_history = []
7797
return
7898
} finally {
7999
this.emit("aiInferingDone")
80100
}
81101
if (result) {
82102
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result.data[0] })
103+
const chat:ChatEntry = [prompt, result.data[0]]
104+
this.solgpt_chat_history.push(chat)
105+
if (this.solgpt_chat_history.length >this.max_history){this.solgpt_chat_history.shift()}
83106
} else if (result.error) {
84107
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "Error on request" })
85108
}
@@ -195,4 +218,18 @@ export class SolCoder extends Plugin {
195218
}
196219
}
197220

221+
_build_solgpt_promt(user_promt:string){
222+
if (this.solgpt_chat_history.length === 0){
223+
return user_promt
224+
} else {
225+
let new_promt = ""
226+
for (const [question, answer] of this.solgpt_chat_history) {
227+
new_promt += PromptBuilder(question.split('sol-gpt')[1], answer, this.model_op)
228+
}
229+
// finaly
230+
new_promt = "sol-gpt " + new_promt + PromptBuilder(user_promt.split('sol-gpt')[1], "", this.model_op)
231+
return new_promt
232+
}
233+
}
234+
198235
}

libs/remix-ui/run-tab/src/lib/components/environment.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export function EnvironmentUI(props: EnvironmentProps) {
1515
const currentProvider = props.providers.providerList.find((exEnv) => exEnv.name === props.selectedEnv)
1616
const bridges = {
1717
'L2 - Optimism': 'https://app.optimism.io/bridge/deposit',
18-
'L2 - Arbitrum One': 'https://bridge.arbitrum.io/'
18+
'L2 - Arbitrum': 'https://bridge.arbitrum.io/'
1919
}
2020

21-
const isL2 = (providerDisplayName: string) => providerDisplayName === 'Optimism Provider' || providerDisplayName === 'Arbitrum One Provider'
21+
const isL2 = (providerDisplayName: string) => providerDisplayName === 'L2 - Optimism' || providerDisplayName === 'L2 - Arbitrum'
2222
return (
2323
<div className="udapp_crow">
2424
<label id="selectExEnv" className="udapp_settingsLabel">
@@ -38,16 +38,16 @@ export function EnvironmentUI(props: EnvironmentProps) {
3838
<div className="udapp_environment">
3939
<Dropdown id="selectExEnvOptions" data-id="settingsSelectEnvOptions" className="udapp_selectExEnvOptions">
4040
<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}>
41-
{isL2(currentProvider && currentProvider.displayName) && 'L2 - '}
41+
{isL2(currentProvider && currentProvider.displayName)}
4242
{currentProvider && currentProvider.displayName}
43-
{currentProvider && bridges[currentProvider.name] && (
43+
{currentProvider && bridges[currentProvider.displayName] && (
4444
<CustomTooltip placement={'right'} tooltipClasses="text-nowrap" tooltipId="info-recorder" tooltipText={<FormattedMessage id="udapp.tooltipText3" />}>
4545
<i
4646
style={{ fontSize: 'medium' }}
4747
className={'ml-2 fa fa-rocket-launch'}
4848
aria-hidden="true"
4949
onClick={() => {
50-
window.open(bridges[currentProvider.name], '_blank')
50+
window.open(bridges[currentProvider.displayName], '_blank')
5151
}}
5252
></i>
5353
</CustomTooltip>
@@ -63,7 +63,7 @@ export function EnvironmentUI(props: EnvironmentProps) {
6363
data-id={`dropdown-item-${name}`}
6464
>
6565
<span className="">
66-
{isL2(displayName) && 'L2 - '}
66+
{isL2(displayName)}
6767
{displayName}
6868
</span>
6969
</Dropdown.Item>

0 commit comments

Comments
 (0)