Skip to content

Commit

Permalink
removed unnecessary pocedures
Browse files Browse the repository at this point in the history
Signed-off-by: cbh778899 <[email protected]>
  • Loading branch information
cbh778899 committed Sep 17, 2024
1 parent 7b17040 commit e7441bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
39 changes: 11 additions & 28 deletions src/components/settings/AwsSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
})
}
Expand All @@ -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
Expand All @@ -73,37 +56,37 @@ export default function AwsSettings({ trigger, platform_setting, updatePlatformS
<SettingSection title={'AWS Bedrock Settings'}>
<TrueFalseComponent
title={"Use AWS Bedrock For Completion"}
value={aws_enabled} cb={setEnabled}
value={enabled} cb={updateEnabled}
/>
<PasswordComponent
title={"Set Access Key ID"}
value={aws_key_id} cb={setAwsKeyID}
description={'Please input your AWS Access Key ID.'}
disabled={!aws_enabled}
disabled={!enabled}
/>
<PasswordComponent
title={"Set Secret Access Key"}
value={aws_secret_key} cb={setAwsSecretKey}
description={'Please input your AWS Secret Access Key.'}
disabled={!aws_enabled}
disabled={!enabled}
/>
<PasswordComponent
title={"Set Session Token"}
value={aws_session_token} cb={setAwsSessionToken}
description={'Please input your AWS Session Token.'}
disabled={!aws_enabled}
disabled={!enabled}
/>
<TextComponent
title={"Set AWS Region"}
value={aws_region} cb={setAwsRegion}
description={'Please input your AWS Bedrock Region.'}
disabled={!aws_enabled}
disabled={!enabled}
/>
<TextComponent
title={"Set Bedrock Model ID"}
value={aws_model_id} cb={setAwsModelID}
description={'Please input the Redrock Model ID you want to use.'}
disabled={!aws_enabled}
disabled={!enabled}
/>
</SettingSection>
)
Expand Down
18 changes: 11 additions & 7 deletions src/utils/workers/aws-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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 };
Expand Down

0 comments on commit e7441bf

Please sign in to comment.