From e7441bfffdffd7ab37cdb9fd350818f79cdc591a Mon Sep 17 00:00:00 2001 From: cbh778899 Date: Tue, 17 Sep 2024 16:48:03 +1000 Subject: [PATCH] removed unnecessary pocedures Signed-off-by: cbh778899 --- src/components/settings/AwsSettings.jsx | 39 +++++++------------------ src/utils/workers/aws-worker.js | 18 +++++++----- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/components/settings/AwsSettings.jsx b/src/components/settings/AwsSettings.jsx index b0ed73f..aa7de91 100644 --- a/src/components/settings/AwsSettings.jsx +++ b/src/components/settings/AwsSettings.jsx @@ -4,29 +4,16 @@ import SettingSection from "./SettingSection"; import TextComponent from "./components/TextComponent"; import PasswordComponent from "./components/PasswordComponent"; import { getJSONCredentials, storeCredentials } from "../../utils/workers/aws-worker"; -import { getPlatformSettings } from "../../utils/general_settings"; +import { getPlatformSettings, updatePlatformSettings } from "../../utils/general_settings"; -export default function AwsSettings({ trigger, platform_setting, updatePlatformSetting }) { +export default function AwsSettings({ trigger, enabled, updateEnabled }) { - const [ aws_enabled, setAwsEnabled ] = useState(false); const [ aws_region, setAwsRegion ] = useState(''); const [ aws_key_id, setAwsKeyID ] = useState(''); const [ aws_secret_key, setAwsSecretKey ] = useState(''); const [ aws_session_token, setAwsSessionToken ] = useState(''); const [ aws_model_id, setAwsModelID ] = useState(''); - - function setEnabled(is_enabled) { - if(aws_enabled && !is_enabled) { - updatePlatformSetting({ - enabled_platform: null - }) - } else if(!aws_enabled && is_enabled) { - updatePlatformSetting({ - enabled_platform: 'AWS' - }) - } - } - + function saveSettings() { const credentials = { key_id: aws_key_id, secret_key: aws_secret_key @@ -36,9 +23,9 @@ export default function AwsSettings({ trigger, platform_setting, updatePlatformS } storeCredentials( credentials, aws_key_id && aws_secret_key, - platform_setting.enabled_platform === 'AWS' + enabled ) - updatePlatformSetting({ + updatePlatformSettings({ aws_model_id, aws_region }) } @@ -60,10 +47,6 @@ export default function AwsSettings({ trigger, platform_setting, updatePlatformS })() }, []) - useEffect(()=>{ - setAwsEnabled(platform_setting.enabled_platform === 'AWS'); - }, [platform_setting]) - useEffect(()=>{ trigger && saveSettings(); // eslint-disable-next-line @@ -73,37 +56,37 @@ export default function AwsSettings({ trigger, platform_setting, updatePlatformS ) diff --git a/src/utils/workers/aws-worker.js b/src/utils/workers/aws-worker.js index 1e9c148..1248e43 100644 --- a/src/utils/workers/aws-worker.js +++ b/src/utils/workers/aws-worker.js @@ -16,10 +16,8 @@ export async function getCredentials(json_credentials = null) { return obj } -export async function storeCredentials(credentials, all_filled, enabled = false) { - const update_result = await instance.updateByID('credentials', 'AWS', {json: credentials}) - if(all_filled && enabled) await initBedrockClient(); - return !!update_result +export async function storeCredentials(credentials) { + return !!(await instance.updateByID('credentials', 'AWS', {json: credentials})) } export async function getJSONCredentials() { @@ -34,7 +32,7 @@ export async function getJSONCredentials() { let bedrock_client = null; export async function setClient(client) { - if(!client) { + if(!client || !(client instanceof BedrockRuntimeClient)) { await initBedrockClient(); return bedrock_client; } else { @@ -153,7 +151,12 @@ export async function chatCompletions(messages, cb = null) { if(system.length) input.system = system; let response_text = '', usage = {} - abort_signal = false; + if(abort_signal) { + abort_signal = false; + cb && cb('', true); + return null; + } + try { const command = new ConverseStreamCommand(input); const response = await bedrock_client.send(command); @@ -168,11 +171,12 @@ export async function chatCompletions(messages, cb = null) { if(abort_signal) break; } cb && cb(response_text, true); - abort_signal = false; } catch(error) { console.error(error); cb && cb(`**${error.name}**:\n\`\`\`\n${error.message}\n\`\`\``, true); return null; + } finally { + abort_signal = false; } return { content: response_text, usage };