[Update/Chore] Config Page: Add 'CTranslate2 Compute Type' Selection.

UI: Rename 'CTranslate2 compute device' to 'Translation compute device'.
This commit is contained in:
Sakamoto Shiina
2025-09-19 14:43:13 +09:00
parent 5f0f918642
commit 4808dcbc96
9 changed files with 148 additions and 56 deletions

View File

@@ -18,7 +18,8 @@ export const Translation = () => {
return (
<>
<CTranslate2WeightType_Box />
<CTranslation2ComputeDevice_Box />
<CTranslate2ComputeType_Box />
<TranslationComputeDevice_Box />
<DeeplAuthKey_Box />
</>
);
@@ -62,7 +63,7 @@ const CTranslate2WeightType_Box = () => {
"config_page.translation.ctranslate2_weight_type.desc",
{ctranslate2: "CTranslate2"}
)}
name="ctransalte2_weight_type"
name="ctranslate2_weight_type"
options={c_translate2_weight_types}
checked_variable={currentSelectedCTranslate2WeightType}
selectFunction={selectFunction}
@@ -72,47 +73,72 @@ const CTranslate2WeightType_Box = () => {
);
};
// Duplicate
import { useComputeMode } from "@logics_common";
const CTranslation2ComputeDevice_Box = () => {
const CTranslate2ComputeType_Box = () => {
const { t } = useI18n();
const { currentSelectedCTranslate2ComputeDevice, setSelectedCTranslate2ComputeDevice } = useTranslation();
const { currentSelectableCTranslate2ComputeDeviceList } = useTranslation();
const { currentSelectableCTranslate2ComputeTypeList } = useTranslation();
const { currentSelectedCTranslate2ComputeType, setSelectedCTranslate2ComputeType } = useTranslation();
const selectFunction = (selected_data) => {
const target_obj = currentSelectableCTranslate2ComputeDeviceList.data[selected_data.selected_id];
setSelectedCTranslate2ComputeDevice(target_obj);
setSelectedCTranslate2ComputeType(selected_data.selected_id);
};
const list_for_ui = transformDeviceArray(currentSelectableCTranslate2ComputeDeviceList.data);
const ctranslate2_compute_type_label = t("config_page.translation.ctranslate2_compute_type.label", {
ctranslate2: "CTranslate2"
});
const target_index = findKeyByDeviceValue(currentSelectableCTranslate2ComputeDeviceList.data, currentSelectedCTranslate2ComputeDevice.data);
return (
<DropdownMenuContainer
dropdown_id="ctranslate2_compute_type"
label={ctranslate2_compute_type_label}
selected_id={currentSelectedCTranslate2ComputeType.data}
list={currentSelectableCTranslate2ComputeTypeList.data}
selectFunction={selectFunction}
state={currentSelectedCTranslate2ComputeType.state}
/>
);
};
// Duplicate
import { useComputeMode } from "@logics_common";
const TranslationComputeDevice_Box = () => {
const { t } = useI18n();
const { currentSelectedTranslationComputeDevice, setSelectedTranslationComputeDevice } = useTranslation();
const { currentSelectableTranslationComputeDeviceList } = useTranslation();
const selectFunction = (selected_data) => {
const target_obj = currentSelectableTranslationComputeDeviceList.data[selected_data.selected_id];
setSelectedTranslationComputeDevice(target_obj);
};
const list_for_ui = transformDeviceArray(currentSelectableTranslationComputeDeviceList.data);
const target_index = findKeyByDeviceValue(currentSelectableTranslationComputeDeviceList.data, currentSelectedTranslationComputeDevice.data);
const { currentComputeMode } = useComputeMode();
const ctranslate2_compute_device_label = t("config_page.translation.ctranslate2_compute_device.label", {
ctranslate2: "Ctranslate2"
const translation_compute_device_label = t("config_page.translation.translation_compute_device.label", {
ctranslate2: "CTranslate2"
});
if (currentComputeMode.data === "cpu") {
return (
<ComputeDeviceContainer
label={ctranslate2_compute_device_label}
label={translation_compute_device_label}
selected_id={target_index}
list={list_for_ui}
selectFunction={selectFunction}
state={currentSelectedCTranslate2ComputeDevice.state}
state={currentSelectedTranslationComputeDevice.state}
/>
)
}
return (
<DropdownMenuContainer
dropdown_id="ctranslate2_compute_device"
label={ctranslate2_compute_device_label}
dropdown_id="translation_compute_device"
label={translation_compute_device_label}
selected_id={target_index}
list={list_for_ui}
selectFunction={selectFunction}
state={currentSelectedCTranslate2ComputeDevice.state}
state={currentSelectedTranslationComputeDevice.state}
/>
);
};

View File

@@ -1,13 +1,15 @@
import {
useStore_CTranslate2WeightTypeStatus,
useStore_SelectedCTranslate2WeightType,
useStore_SelectableCTranslate2ComputeDeviceList,
useStore_SelectedCTranslate2ComputeDevice,
useStore_SelectableCTranslate2ComputeTypeList,
useStore_SelectedCTranslate2ComputeType,
useStore_SelectableTranslationComputeDeviceList,
useStore_SelectedTranslationComputeDevice,
useStore_DeepLAuthKey,
} from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
import { useI18n } from "@useI18n";
import { transformToIndexedArray } from "@utils";
import { transformToIndexedArray, arrayToObject } from "@utils";
import { useNotificationStatus } from "@logics_common";
export const useTranslation = () => {
@@ -17,8 +19,13 @@ export const useTranslation = () => {
const { currentCTranslate2WeightTypeStatus, updateCTranslate2WeightTypeStatus, pendingCTranslate2WeightTypeStatus } = useStore_CTranslate2WeightTypeStatus();
const { currentSelectedCTranslate2WeightType, updateSelectedCTranslate2WeightType, pendingSelectedCTranslate2WeightType } = useStore_SelectedCTranslate2WeightType();
const { currentSelectableCTranslate2ComputeDeviceList, updateSelectableCTranslate2ComputeDeviceList, pendingSelectableCTranslate2ComputeDeviceList } = useStore_SelectableCTranslate2ComputeDeviceList();
const { currentSelectedCTranslate2ComputeDevice, updateSelectedCTranslate2ComputeDevice, pendingSelectedCTranslate2ComputeDevice } = useStore_SelectedCTranslate2ComputeDevice();
const { currentSelectableCTranslate2ComputeTypeList, updateSelectableCTranslate2ComputeTypeList, pendingSelectableCTranslate2ComputeTypeList } = useStore_SelectableCTranslate2ComputeTypeList();
const { currentSelectedCTranslate2ComputeType, updateSelectedCTranslate2ComputeType, pendingSelectedCTranslate2ComputeType } = useStore_SelectedCTranslate2ComputeType();
const { currentSelectableTranslationComputeDeviceList, updateSelectableTranslationComputeDeviceList, pendingSelectableTranslationComputeDeviceList } = useStore_SelectableTranslationComputeDeviceList();
const { currentSelectedTranslationComputeDevice, updateSelectedTranslationComputeDevice, pendingSelectedTranslationComputeDevice } = useStore_SelectedTranslationComputeDevice();
const { currentDeepLAuthKey, updateDeepLAuthKey, pendingDeepLAuthKey } = useStore_DeepLAuthKey();
@@ -80,28 +87,56 @@ export const useTranslation = () => {
};
const getSelectableCTranslate2ComputeDeviceList = () => {
pendingSelectableCTranslate2ComputeDeviceList();
const getSelectableCTranslate2ComputeTypeList = () => {
pendingSelectableCTranslate2ComputeTypeList();
asyncStdoutToPython("/get/data/ctranslate2_compute_type_list");
};
const updateSelectableCTranslate2ComputeTypeList_FromBackend = (payload) => {
updateSelectableCTranslate2ComputeTypeList(arrayToObject(payload));
};
const getSelectedCTranslate2ComputeType = () => {
pendingSelectedCTranslate2ComputeType();
asyncStdoutToPython("/get/data/ctranslate2_compute_type");
};
const setSelectedCTranslate2ComputeType = (selected_ctranslate2_compute_type) => {
pendingSelectedCTranslate2ComputeType();
asyncStdoutToPython("/set/data/ctranslate2_compute_type", selected_ctranslate2_compute_type);
};
const setSuccessSelectedCTranslate2ComputeType = (selected_ctranslate2_compute_type) => {
updateSelectedCTranslate2ComputeType(selected_ctranslate2_compute_type);
showNotification_SaveSuccess();
};
const getSelectableTranslationComputeDeviceList = () => {
pendingSelectableTranslationComputeDeviceList();
asyncStdoutToPython("/get/data/translation_compute_device_list");
};
const updateSelectableCTranslate2ComputeDeviceList_FromBackend = (payload) => {
updateSelectableCTranslate2ComputeDeviceList(transformToIndexedArray(payload));
const updateSelectableTranslationComputeDeviceList_FromBackend = (payload) => {
updateSelectableTranslationComputeDeviceList(transformToIndexedArray(payload));
};
const getSelectedCTranslate2ComputeDevice = () => {
pendingSelectedCTranslate2ComputeDevice();
const getSelectedTranslationComputeDevice = () => {
pendingSelectedTranslationComputeDevice();
asyncStdoutToPython("/get/data/selected_translation_compute_device");
};
const setSelectedCTranslate2ComputeDevice = (selected_translation_compute_device) => {
pendingSelectedCTranslate2ComputeDevice();
const setSelectedTranslationComputeDevice = (selected_translation_compute_device) => {
pendingSelectedTranslationComputeDevice();
asyncStdoutToPython("/set/data/selected_translation_compute_device", selected_translation_compute_device);
};
const setSuccessSelectedCTranslate2ComputeDevice = (selected_translation_compute_device) => {
updateSelectedCTranslate2ComputeDevice(selected_translation_compute_device);
const setSuccessSelectedTranslationComputeDevice = (selected_translation_compute_device) => {
updateSelectedTranslationComputeDevice(selected_translation_compute_device);
showNotification_SaveSuccess();
};
@@ -146,16 +181,29 @@ export const useTranslation = () => {
setSelectedCTranslate2WeightType,
setSuccessSelectedCTranslate2WeightType,
currentSelectableCTranslate2ComputeDeviceList,
getSelectableCTranslate2ComputeDeviceList,
updateSelectableCTranslate2ComputeDeviceList,
updateSelectableCTranslate2ComputeDeviceList_FromBackend,
currentSelectedCTranslate2ComputeDevice,
getSelectedCTranslate2ComputeDevice,
updateSelectedCTranslate2ComputeDevice,
setSelectedCTranslate2ComputeDevice,
setSuccessSelectedCTranslate2ComputeDevice,
currentSelectableCTranslate2ComputeTypeList,
getSelectableCTranslate2ComputeTypeList,
updateSelectableCTranslate2ComputeTypeList,
updateSelectableCTranslate2ComputeTypeList_FromBackend,
currentSelectedCTranslate2ComputeType,
getSelectedCTranslate2ComputeType,
updateSelectedCTranslate2ComputeType,
setSelectedCTranslate2ComputeType,
setSuccessSelectedCTranslate2ComputeType,
currentSelectableTranslationComputeDeviceList,
getSelectableTranslationComputeDeviceList,
updateSelectableTranslationComputeDeviceList,
updateSelectableTranslationComputeDeviceList_FromBackend,
currentSelectedTranslationComputeDevice,
getSelectedTranslationComputeDevice,
updateSelectedTranslationComputeDevice,
setSelectedTranslationComputeDevice,
setSuccessSelectedTranslationComputeDevice,
currentDeepLAuthKey,
getDeepLAuthKey,

View File

@@ -168,19 +168,22 @@ export const ROUTE_META_LIST = [
{ endpoint: "/delete/data/deepl_auth_key", ns: configs, hook_name: "useTranslation", method_name: "deleteSuccessDeepLAuthKey" },
// Translation (AI Models)
{ endpoint: "/get/data/selectable_ctranslate2_weight_type_dict", ns: configs, hook_name: "useTranslation", method_name: "updateDownloadedCTranslate2WeightTypeStatus" },
{ endpoint: "/get/data/ctranslate2_weight_type", ns: configs, hook_name: "useTranslation", method_name: "updateSelectedCTranslate2WeightType" },
{ endpoint: "/set/data/ctranslate2_weight_type", ns: configs, hook_name: "useTranslation", method_name: "setSuccessSelectedCTranslate2WeightType" },
{ endpoint: "/get/data/selectable_ctranslate2_weight_type_dict", ns: configs, hook_name: "useTranslation", method_name: "updateDownloadedCTranslate2WeightTypeStatus" },
{ endpoint: "/get/data/ctranslate2_compute_type_list", ns: configs, hook_name: "useTranslation", method_name: "updateSelectableCTranslate2ComputeTypeList_FromBackend" },
{ endpoint: "/get/data/ctranslate2_compute_type", ns: configs, hook_name: "useTranslation", method_name: "updateSelectedCTranslate2ComputeType" },
{ endpoint: "/set/data/ctranslate2_compute_type", ns: configs, hook_name: "useTranslation", method_name: "setSuccessSelectedCTranslate2ComputeType" },
{ endpoint: "/run/downloaded_ctranslate2_weight", ns: configs, hook_name: "useTranslation", method_name: "downloadedCTranslate2WeightType" },
{ endpoint: "/run/download_ctranslate2_weight", ns: null, hook_name: null, method_name: null },
{ endpoint: "/run/download_progress_ctranslate2_weight", ns: configs, hook_name: "useTranslation", method_name: "updateDownloadProgressCTranslate2WeightTypeStatus" },
{ endpoint: "/get/data/translation_compute_device_list", ns: configs, hook_name: "useTranslation", method_name: "updateSelectableCTranslate2ComputeDeviceList_FromBackend" },
{ endpoint: "/get/data/translation_compute_device_list", ns: configs, hook_name: "useTranslation", method_name: "updateSelectableTranslationComputeDeviceList_FromBackend" },
{ endpoint: "/get/data/selected_translation_compute_device", ns: configs, hook_name: "useTranslation", method_name: "updateSelectedCTranslate2ComputeDevice" },
{ endpoint: "/set/data/selected_translation_compute_device", ns: configs, hook_name: "useTranslation", method_name: "setSuccessSelectedCTranslate2ComputeDevice" },
{ endpoint: "/get/data/selected_translation_compute_device", ns: configs, hook_name: "useTranslation", method_name: "updateSelectedTranslationComputeDevice" },
{ endpoint: "/set/data/selected_translation_compute_device", ns: configs, hook_name: "useTranslation", method_name: "setSuccessSelectedTranslationComputeDevice" },
// Transcription

View File

@@ -218,10 +218,15 @@ export const { atomInstance: Atom_MicWordFilterList, useHook: useStore_MicWordFi
// Translation
export const { atomInstance: Atom_DeepLAuthKey, useHook: useStore_DeepLAuthKey } = createAtomWithHook(null, "DeepLAuthKey");
export const { atomInstance: Atom_SelectedCTranslate2WeightType, useHook: useStore_SelectedCTranslate2WeightType } = createAtomWithHook("", "SelectedCTranslate2WeightType");
export const { atomInstance: Atom_SelectableCTranslate2ComputeDeviceList, useHook: useStore_SelectableCTranslate2ComputeDeviceList } = createAtomWithHook({}, "SelectableCTranslate2ComputeDeviceList");
export const { atomInstance: Atom_SelectedCTranslate2ComputeDevice, useHook: useStore_SelectedCTranslate2ComputeDevice } = createAtomWithHook("", "SelectedCTranslate2ComputeDevice");
export const { atomInstance: Atom_CTranslate2WeightTypeStatus, useHook: useStore_CTranslate2WeightTypeStatus } = createAtomWithHook(ctranslate2_weight_type_status, "CTranslate2WeightTypeStatus");
export const { atomInstance: Atom_SelectableCTranslate2ComputeTypeList, useHook: useStore_SelectableCTranslate2ComputeTypeList } = createAtomWithHook({}, "SelectableCTranslate2ComputeTypeList");
export const { atomInstance: Atom_SelectedCTranslate2ComputeType, useHook: useStore_SelectedCTranslate2ComputeType } = createAtomWithHook("", "SelectedCTranslate2ComputeType");
export const { atomInstance: Atom_SelectableTranslationComputeDeviceList, useHook: useStore_SelectableTranslationComputeDeviceList } = createAtomWithHook({}, "SelectableTranslationComputeDeviceList");
export const { atomInstance: Atom_SelectedTranslationComputeDevice, useHook: useStore_SelectedTranslationComputeDevice } = createAtomWithHook("", "SelectedTranslationComputeDevice");
// Transcription
export const { atomInstance: Atom_MicRecordTimeout, useHook: useStore_MicRecordTimeout } = createAtomWithHook(0, "MicRecordTimeout");
export const { atomInstance: Atom_MicPhraseTimeout, useHook: useStore_MicPhraseTimeout } = createAtomWithHook(0, "MicPhraseTimeout");