set and use settings

pull/5370/head
yann300 1 year ago
parent 7fb1cd12b8
commit e5aedc242b
  1. 13
      apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts
  2. 29
      libs/remix-ui/settings/src/lib/remix-ui-settings.tsx

@ -6,7 +6,7 @@ const profile = {
name: 'copilot-suggestion',
displayName: 'copilot-suggestion',
description: 'copilot-suggestion',
methods: ['suggest']
methods: ['suggest', 'init', 'uninstall']
}
export class CopilotSuggestion extends Plugin {
@ -26,11 +26,16 @@ export class CopilotSuggestion extends Plugin {
}
async suggest(content: string) {
if (!await this.call('settings', 'get', 'settings/copilot/suggest/activate')) return { output: [{ generated_text: ''}]}
const max_new_tokens = await this.call('settings', 'get', 'settings/copilot/suggest/max_new_tokens')
const temperature = await this.call('settings', 'get', 'settings/copilot/suggest/temperature')
console.log('suggest', max_new_tokens, temperature)
const options: SuggestOptions = {
do_sample: false,
top_k: 0,
temperature: await this.call('settings', 'get', 'settings/copilot/suggest/temperature'),
max_new_tokens: await this.call('settings', 'get', 'settings/copilot/suggest/max_new_tokens')
temperature,
max_new_tokens
}
return this.service.suggest(content, options)
}
@ -40,5 +45,5 @@ export class CopilotSuggestion extends Plugin {
}
async uninstall() {
}
}
}

@ -135,11 +135,11 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
}
const onchangeCopilotMaxNewToken = (event) => {
copilotMaxNewToken(props.config, event.target.value, dispatch)
copilotMaxNewToken(props.config, parseInt(event.target.value), dispatch)
}
const onchangeCopilotTemperature = (event) => {
copilotTemperature(props.config, event.target.value, dispatch)
copilotTemperature(props.config, parseInt(event.target.value) / 100, dispatch)
}
const onchangePersonal = (event) => {
@ -399,12 +399,13 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const isCopilotActivated = props.config.get('settings/copilot/suggest/activate') || false
const copilotMaxnewToken = props.config.get('settings/copilot/suggest/max_new_tokens') || 5
const copilotTemperatureValue = props.config.get('settings/copilot/suggest/temperature') || 0.5
const copilotTemperatureValue = (props.config.get('settings/copilot/suggest/temperature') || 0.5) * 100
if (isCopilotActivated) props.plugin.call('copilot-suggestion', 'init')
const copilotSettings = () => (
<div className="border-top">
<div className="card-body pt-3 pb-2">
<h6 className="card-title">
<FormattedMessage id="settings.copilot.activate" />
<FormattedMessage id="settings.copilot" />
</h6>
<div className="pt-2 mb-0">
@ -423,11 +424,11 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
<div className="pt-2 mb-0">
<div className="text-secondary mb-0 h6">
<div>
<div className="custom-control custom-checkbox mb-1">
<input onChange={onchangeCopilotMaxNewToken} id="copilot-max-new-token" value={copilotMaxnewToken} min='1' max='150' type="range" className="custom-control-input" />
<label className={`form-check-label custom-control-label align-middle ${getTextClass('settings/copilot/suggest/max_new_tokens')}`} htmlFor="copilot-activate">
<FormattedMessage id="settings.copilot.activate" />
<div className="mb-1">
<label className={`align-middle ${getTextClass('settings/copilot/suggest/max_new_tokens')}`} htmlFor="copilot-activate">
<FormattedMessage id="settings.copilot.max_new_tokens" />
</label>
<input onChange={onchangeCopilotMaxNewToken} id="copilot-max-new-token" value={copilotMaxnewToken} min='1' max='150' type="range" className="custom-range" />
</div>
</div>
</div>
@ -436,11 +437,11 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
<div className="pt-2 mb-0">
<div className="text-secondary mb-0 h6">
<div>
<div className="custom-control custom-checkbox mb-1">
<input onChange={onchangeCopilotTemperature} id="copilot-temperature" value={copilotTemperatureValue} min='0' max='1' type="range" className="custom-control-input" />
<label className={`form-check-label custom-control-label align-middle ${getTextClass('settings/copilot/suggest/temperature')}`} htmlFor="copilot-activate">
<FormattedMessage id="settings.copilot.activate" />
<div className="mb-1">
<label className={`align-middle ${getTextClass('settings/copilot/suggest/temperature')}`} htmlFor="copilot-activate">
<FormattedMessage id="settings.copilot.temperature" />
</label>
<input onChange={onchangeCopilotTemperature} id="copilot-temperature" value={copilotTemperatureValue} min='0' max='100' type="range" className="custom-range" />
</div>
</div>
</div>
@ -528,6 +529,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
<div>
{state.message ? <Toaster message={state.message} /> : null}
{generalConfig()}
{copilotSettings()}
<GithubSettings
saveToken={(githubToken: string, githubUserName: string, githubEmail: string) => {
saveTokenToast(props.config, dispatchToast, githubToken, 'gist-access-token')
@ -553,8 +555,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
{swarmSettings()}
{ipfsSettings()}
<RemixUiThemeModule themeModule={props._deps.themeModule} />
<RemixUiLocaleModule localeModule={props._deps.localeModule} />
{copilotSettings()}
<RemixUiLocaleModule localeModule={props._deps.localeModule} />
</div>
)
}

Loading…
Cancel
Save