This repository has been archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from slashbaseide/develop
Release v.0.10.2
- Loading branch information
Showing
30 changed files
with
341 additions
and
164 deletions.
There are no files selected for viewing
117 changes: 80 additions & 37 deletions
117
frontend/desktop/src/components/settingfragments/advanced.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,94 @@ | ||
import React, { FunctionComponent, useEffect, useState } from 'react' | ||
import Constants from '../../constants' | ||
import eventService from '../../events/eventService' | ||
import toast from 'react-hot-toast' | ||
|
||
const AdvancedSettings: FunctionComponent<{}> = () => { | ||
|
||
const [openAIKey, setOpenAIKey] = useState<string>("") | ||
const [openAIModel, setOpenAIModel] = useState<string>("") | ||
const [modelOptions, setModelOptions] = useState<{ value: string }[]>([]) | ||
|
||
const [openAIKey, setOpenAIKey] = useState<string>("") | ||
useEffect(() => { | ||
(async () => { | ||
const result = await eventService.listSupportedAIModels() | ||
setModelOptions(result.data.map(model => ({ value: model }))) | ||
})(); | ||
(async () => { | ||
const result = await eventService.getSingleSetting(Constants.SETTING_KEYS.OPENAI_KEY) | ||
setOpenAIKey(result.data) | ||
})(); | ||
(async () => { | ||
const result = await eventService.getSingleSetting(Constants.SETTING_KEYS.OPENAI_MODEL) | ||
setOpenAIModel(result.data) | ||
})(); | ||
}, []) | ||
|
||
useEffect(() => { | ||
(async () => { | ||
let result = await eventService.getSingleSetting(Constants.SETTING_KEYS.OPENAI_KEY) | ||
setOpenAIKey(result.data) | ||
})() | ||
}, []) | ||
|
||
const updateOpenAIKey = async () => { | ||
const result = await eventService.updateSingleSetting(Constants.SETTING_KEYS.OPENAI_KEY, openAIKey) | ||
if (result.success) | ||
setOpenAIKey(openAIKey) | ||
const updateOpenAIKey = async () => { | ||
const result = await eventService.updateSingleSetting(Constants.SETTING_KEYS.OPENAI_KEY, openAIKey) | ||
if (result.success) { | ||
setOpenAIKey(openAIKey) | ||
toast.success("saved") | ||
} | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
<h1>Advanced Settings</h1> | ||
<br /> | ||
<h2>OpenAI Key</h2> | ||
<p>Update OpenAI API key to enable Generate SQL tool.</p> | ||
<div className="buttons has-addons"> | ||
<div className="field has-addons"> | ||
<p className="control is-expanded"> | ||
<input | ||
className="input" | ||
type="text" | ||
value={openAIKey} | ||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { setOpenAIKey(e.target.value) }} | ||
placeholder="Enter API key" /> | ||
</p> | ||
<p className="control"> | ||
<a className="button" onClick={updateOpenAIKey}> | ||
<i className="fas fa-check" /> | ||
</a> | ||
</p> | ||
</div> | ||
</div> | ||
<br /> | ||
</React.Fragment> | ||
) | ||
const updateOpenAIModel = async () => { | ||
const result = await eventService.updateSingleSetting(Constants.SETTING_KEYS.OPENAI_MODEL, openAIModel) | ||
if (result.success) | ||
setOpenAIModel(openAIModel) | ||
toast.success("saved") | ||
} | ||
|
||
const handleModelChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => { | ||
const value = e.target.value | ||
setOpenAIModel(value) | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
<h1>Advanced Settings</h1> | ||
<br /> | ||
<h2>OpenAI Key</h2> | ||
<p>Update OpenAI API key to enable Generate SQL tool.</p> | ||
<div className="buttons has-addons"> | ||
<div className="field has-addons" style={{ minWidth: 550 }}> | ||
<p className="control is-expanded"> | ||
<input | ||
className="input" | ||
type="text" | ||
value={openAIKey} | ||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { setOpenAIKey(e.target.value) }} | ||
placeholder="Enter API key" /> | ||
</p> | ||
<p className="control"> | ||
<a className="button" onClick={updateOpenAIKey}> | ||
<i className="fas fa-check" /> | ||
</a> | ||
</p> | ||
</div> | ||
</div> | ||
<h2>OpenAI Model</h2> | ||
<p>Update OpenAI Model to enable Generate SQL tool.</p> | ||
<div className="field has-addons"> | ||
<p className="control"> | ||
<span className="select"> | ||
<select value={openAIModel} onChange={e => handleModelChange(e)}> | ||
{modelOptions.map((e, idx) => { | ||
return <option value={e.value} key={idx}> {e.value} </option> | ||
})} | ||
</select> | ||
</span> | ||
</p> | ||
<p className="control"> | ||
<button className="button" onClick={() => updateOpenAIModel()}> | ||
<i className="fas fa-check" /> | ||
</button> | ||
</p> | ||
</div> | ||
<br /> | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
export default AdvancedSettings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.