mirror of
https://github.com/StarCitizenToolBox/app.git
synced 2026-02-06 15:10:20 +00:00
feat: [rust] add Opus-MT
This commit is contained in:
72
lib/common/rust/api/ort_api.dart
Normal file
72
lib/common/rust/api/ort_api.dart
Normal file
@@ -0,0 +1,72 @@
|
||||
// This file is automatically generated, so please do not edit it.
|
||||
// @generated by `flutter_rust_bridge`@ 2.11.1.
|
||||
|
||||
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
|
||||
|
||||
import '../frb_generated.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
|
||||
|
||||
/// 加载 ONNX 翻译模型
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `model_path` - 模型文件夹路径
|
||||
/// * `model_key` - 模型缓存键(用于标识模型,如 "zh-en")
|
||||
/// * `quantization_suffix` - 量化后缀(如 "_q4", "_q8",空字符串表示使用默认模型)
|
||||
///
|
||||
Future<void> loadTranslationModel({
|
||||
required String modelPath,
|
||||
required String modelKey,
|
||||
required String quantizationSuffix,
|
||||
}) => RustLib.instance.api.crateApiOrtApiLoadTranslationModel(
|
||||
modelPath: modelPath,
|
||||
modelKey: modelKey,
|
||||
quantizationSuffix: quantizationSuffix,
|
||||
);
|
||||
|
||||
/// 翻译文本
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `model_key` - 模型缓存键(如 "zh-en")
|
||||
/// * `text` - 要翻译的文本
|
||||
///
|
||||
/// # Returns
|
||||
/// * `Result<String>` - 翻译后的文本
|
||||
Future<String> translateText({
|
||||
required String modelKey,
|
||||
required String text,
|
||||
}) => RustLib.instance.api.crateApiOrtApiTranslateText(
|
||||
modelKey: modelKey,
|
||||
text: text,
|
||||
);
|
||||
|
||||
/// 批量翻译文本
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `model_key` - 模型缓存键(如 "zh-en")
|
||||
/// * `texts` - 要翻译的文本列表
|
||||
///
|
||||
/// # Returns
|
||||
/// * `Result<Vec<String>>` - 翻译后的文本列表
|
||||
Future<List<String>> translateTextBatch({
|
||||
required String modelKey,
|
||||
required List<String> texts,
|
||||
}) => RustLib.instance.api.crateApiOrtApiTranslateTextBatch(
|
||||
modelKey: modelKey,
|
||||
texts: texts,
|
||||
);
|
||||
|
||||
/// 卸载模型
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `model_key` - 模型缓存键(如 "zh-en")
|
||||
///
|
||||
Future<void> unloadTranslationModel({required String modelKey}) => RustLib
|
||||
.instance
|
||||
.api
|
||||
.crateApiOrtApiUnloadTranslationModel(modelKey: modelKey);
|
||||
|
||||
/// 清空所有已加载的模型
|
||||
///
|
||||
/// # Returns
|
||||
Future<void> clearAllModels() =>
|
||||
RustLib.instance.api.crateApiOrtApiClearAllModels();
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import 'api/asar_api.dart';
|
||||
import 'api/http_api.dart';
|
||||
import 'api/ort_api.dart';
|
||||
import 'api/rs_process.dart';
|
||||
import 'api/win32_api.dart';
|
||||
import 'dart:async';
|
||||
@@ -68,7 +69,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
|
||||
String get codegenVersion => '2.11.1';
|
||||
|
||||
@override
|
||||
int get rustContentHash => 1832496273;
|
||||
int get rustContentHash => -706588047;
|
||||
|
||||
static const kDefaultExternalLibraryLoaderConfig =
|
||||
ExternalLibraryLoaderConfig(
|
||||
@@ -79,6 +80,8 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
|
||||
}
|
||||
|
||||
abstract class RustLibApi extends BaseApi {
|
||||
Future<void> crateApiOrtApiClearAllModels();
|
||||
|
||||
Future<List<String>> crateApiHttpApiDnsLookupIps({required String host});
|
||||
|
||||
Future<List<String>> crateApiHttpApiDnsLookupTxt({required String host});
|
||||
@@ -96,6 +99,12 @@ abstract class RustLibApi extends BaseApi {
|
||||
required String asarPath,
|
||||
});
|
||||
|
||||
Future<void> crateApiOrtApiLoadTranslationModel({
|
||||
required String modelPath,
|
||||
required String modelKey,
|
||||
required String quantizationSuffix,
|
||||
});
|
||||
|
||||
Future<void> crateApiAsarApiRsiLauncherAsarDataWriteMainJs({
|
||||
required RsiLauncherAsarData that,
|
||||
required List<int> content,
|
||||
@@ -122,6 +131,18 @@ abstract class RustLibApi extends BaseApi {
|
||||
required String workingDirectory,
|
||||
});
|
||||
|
||||
Future<String> crateApiOrtApiTranslateText({
|
||||
required String modelKey,
|
||||
required String text,
|
||||
});
|
||||
|
||||
Future<List<String>> crateApiOrtApiTranslateTextBatch({
|
||||
required String modelKey,
|
||||
required List<String> texts,
|
||||
});
|
||||
|
||||
Future<void> crateApiOrtApiUnloadTranslationModel({required String modelKey});
|
||||
|
||||
Future<void> crateApiRsProcessWrite({
|
||||
required int rsPid,
|
||||
required String data,
|
||||
@@ -136,6 +157,27 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
required super.portManager,
|
||||
});
|
||||
|
||||
@override
|
||||
Future<void> crateApiOrtApiClearAllModels() {
|
||||
return handler.executeNormal(
|
||||
NormalTask(
|
||||
callFfi: (port_) {
|
||||
return wire.wire__crate__api__ort_api__clear_all_models(port_);
|
||||
},
|
||||
codec: DcoCodec(
|
||||
decodeSuccessData: dco_decode_unit,
|
||||
decodeErrorData: dco_decode_AnyhowException,
|
||||
),
|
||||
constMeta: kCrateApiOrtApiClearAllModelsConstMeta,
|
||||
argValues: [],
|
||||
apiImpl: this,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
TaskConstMeta get kCrateApiOrtApiClearAllModelsConstMeta =>
|
||||
const TaskConstMeta(debugName: "clear_all_models", argNames: []);
|
||||
|
||||
@override
|
||||
Future<List<String>> crateApiHttpApiDnsLookupIps({required String host}) {
|
||||
return handler.executeNormal(
|
||||
@@ -268,6 +310,42 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
argNames: ["asarPath"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> crateApiOrtApiLoadTranslationModel({
|
||||
required String modelPath,
|
||||
required String modelKey,
|
||||
required String quantizationSuffix,
|
||||
}) {
|
||||
return handler.executeNormal(
|
||||
NormalTask(
|
||||
callFfi: (port_) {
|
||||
var arg0 = cst_encode_String(modelPath);
|
||||
var arg1 = cst_encode_String(modelKey);
|
||||
var arg2 = cst_encode_String(quantizationSuffix);
|
||||
return wire.wire__crate__api__ort_api__load_translation_model(
|
||||
port_,
|
||||
arg0,
|
||||
arg1,
|
||||
arg2,
|
||||
);
|
||||
},
|
||||
codec: DcoCodec(
|
||||
decodeSuccessData: dco_decode_unit,
|
||||
decodeErrorData: dco_decode_AnyhowException,
|
||||
),
|
||||
constMeta: kCrateApiOrtApiLoadTranslationModelConstMeta,
|
||||
argValues: [modelPath, modelKey, quantizationSuffix],
|
||||
apiImpl: this,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
TaskConstMeta get kCrateApiOrtApiLoadTranslationModelConstMeta =>
|
||||
const TaskConstMeta(
|
||||
debugName: "load_translation_model",
|
||||
argNames: ["modelPath", "modelKey", "quantizationSuffix"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> crateApiAsarApiRsiLauncherAsarDataWriteMainJs({
|
||||
required RsiLauncherAsarData that,
|
||||
@@ -443,6 +521,102 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
argNames: ["executable", "arguments", "workingDirectory", "streamSink"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<String> crateApiOrtApiTranslateText({
|
||||
required String modelKey,
|
||||
required String text,
|
||||
}) {
|
||||
return handler.executeNormal(
|
||||
NormalTask(
|
||||
callFfi: (port_) {
|
||||
var arg0 = cst_encode_String(modelKey);
|
||||
var arg1 = cst_encode_String(text);
|
||||
return wire.wire__crate__api__ort_api__translate_text(
|
||||
port_,
|
||||
arg0,
|
||||
arg1,
|
||||
);
|
||||
},
|
||||
codec: DcoCodec(
|
||||
decodeSuccessData: dco_decode_String,
|
||||
decodeErrorData: dco_decode_AnyhowException,
|
||||
),
|
||||
constMeta: kCrateApiOrtApiTranslateTextConstMeta,
|
||||
argValues: [modelKey, text],
|
||||
apiImpl: this,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
TaskConstMeta get kCrateApiOrtApiTranslateTextConstMeta =>
|
||||
const TaskConstMeta(
|
||||
debugName: "translate_text",
|
||||
argNames: ["modelKey", "text"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<List<String>> crateApiOrtApiTranslateTextBatch({
|
||||
required String modelKey,
|
||||
required List<String> texts,
|
||||
}) {
|
||||
return handler.executeNormal(
|
||||
NormalTask(
|
||||
callFfi: (port_) {
|
||||
var arg0 = cst_encode_String(modelKey);
|
||||
var arg1 = cst_encode_list_String(texts);
|
||||
return wire.wire__crate__api__ort_api__translate_text_batch(
|
||||
port_,
|
||||
arg0,
|
||||
arg1,
|
||||
);
|
||||
},
|
||||
codec: DcoCodec(
|
||||
decodeSuccessData: dco_decode_list_String,
|
||||
decodeErrorData: dco_decode_AnyhowException,
|
||||
),
|
||||
constMeta: kCrateApiOrtApiTranslateTextBatchConstMeta,
|
||||
argValues: [modelKey, texts],
|
||||
apiImpl: this,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
TaskConstMeta get kCrateApiOrtApiTranslateTextBatchConstMeta =>
|
||||
const TaskConstMeta(
|
||||
debugName: "translate_text_batch",
|
||||
argNames: ["modelKey", "texts"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> crateApiOrtApiUnloadTranslationModel({
|
||||
required String modelKey,
|
||||
}) {
|
||||
return handler.executeNormal(
|
||||
NormalTask(
|
||||
callFfi: (port_) {
|
||||
var arg0 = cst_encode_String(modelKey);
|
||||
return wire.wire__crate__api__ort_api__unload_translation_model(
|
||||
port_,
|
||||
arg0,
|
||||
);
|
||||
},
|
||||
codec: DcoCodec(
|
||||
decodeSuccessData: dco_decode_unit,
|
||||
decodeErrorData: dco_decode_AnyhowException,
|
||||
),
|
||||
constMeta: kCrateApiOrtApiUnloadTranslationModelConstMeta,
|
||||
argValues: [modelKey],
|
||||
apiImpl: this,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
TaskConstMeta get kCrateApiOrtApiUnloadTranslationModelConstMeta =>
|
||||
const TaskConstMeta(
|
||||
debugName: "unload_translation_model",
|
||||
argNames: ["modelKey"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> crateApiRsProcessWrite({
|
||||
required int rsPid,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import 'api/asar_api.dart';
|
||||
import 'api/http_api.dart';
|
||||
import 'api/ort_api.dart';
|
||||
import 'api/rs_process.dart';
|
||||
import 'api/win32_api.dart';
|
||||
import 'dart:async';
|
||||
@@ -614,6 +615,18 @@ class RustLibWire implements BaseWire {
|
||||
late final _store_dart_post_cobject = _store_dart_post_cobjectPtr
|
||||
.asFunction<void Function(DartPostCObjectFnType)>();
|
||||
|
||||
void wire__crate__api__ort_api__clear_all_models(int port_) {
|
||||
return _wire__crate__api__ort_api__clear_all_models(port_);
|
||||
}
|
||||
|
||||
late final _wire__crate__api__ort_api__clear_all_modelsPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
|
||||
'frbgen_starcitizen_doctor_wire__crate__api__ort_api__clear_all_models',
|
||||
);
|
||||
late final _wire__crate__api__ort_api__clear_all_models =
|
||||
_wire__crate__api__ort_api__clear_all_modelsPtr
|
||||
.asFunction<void Function(int)>();
|
||||
|
||||
void wire__crate__api__http_api__dns_lookup_ips(
|
||||
int port_,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict> host,
|
||||
@@ -733,6 +746,44 @@ class RustLibWire implements BaseWire {
|
||||
void Function(int, ffi.Pointer<wire_cst_list_prim_u_8_strict>)
|
||||
>();
|
||||
|
||||
void wire__crate__api__ort_api__load_translation_model(
|
||||
int port_,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict> model_path,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict> model_key,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict> quantization_suffix,
|
||||
) {
|
||||
return _wire__crate__api__ort_api__load_translation_model(
|
||||
port_,
|
||||
model_path,
|
||||
model_key,
|
||||
quantization_suffix,
|
||||
);
|
||||
}
|
||||
|
||||
late final _wire__crate__api__ort_api__load_translation_modelPtr =
|
||||
_lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(
|
||||
ffi.Int64,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
)
|
||||
>
|
||||
>(
|
||||
'frbgen_starcitizen_doctor_wire__crate__api__ort_api__load_translation_model',
|
||||
);
|
||||
late final _wire__crate__api__ort_api__load_translation_model =
|
||||
_wire__crate__api__ort_api__load_translation_modelPtr
|
||||
.asFunction<
|
||||
void Function(
|
||||
int,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
)
|
||||
>();
|
||||
|
||||
void wire__crate__api__asar_api__rsi_launcher_asar_data_write_main_js(
|
||||
int port_,
|
||||
ffi.Pointer<wire_cst_rsi_launcher_asar_data> that,
|
||||
@@ -898,6 +949,95 @@ class RustLibWire implements BaseWire {
|
||||
)
|
||||
>();
|
||||
|
||||
void wire__crate__api__ort_api__translate_text(
|
||||
int port_,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict> model_key,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict> text,
|
||||
) {
|
||||
return _wire__crate__api__ort_api__translate_text(port_, model_key, text);
|
||||
}
|
||||
|
||||
late final _wire__crate__api__ort_api__translate_textPtr =
|
||||
_lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(
|
||||
ffi.Int64,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
)
|
||||
>
|
||||
>('frbgen_starcitizen_doctor_wire__crate__api__ort_api__translate_text');
|
||||
late final _wire__crate__api__ort_api__translate_text =
|
||||
_wire__crate__api__ort_api__translate_textPtr
|
||||
.asFunction<
|
||||
void Function(
|
||||
int,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
)
|
||||
>();
|
||||
|
||||
void wire__crate__api__ort_api__translate_text_batch(
|
||||
int port_,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict> model_key,
|
||||
ffi.Pointer<wire_cst_list_String> texts,
|
||||
) {
|
||||
return _wire__crate__api__ort_api__translate_text_batch(
|
||||
port_,
|
||||
model_key,
|
||||
texts,
|
||||
);
|
||||
}
|
||||
|
||||
late final _wire__crate__api__ort_api__translate_text_batchPtr =
|
||||
_lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(
|
||||
ffi.Int64,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
ffi.Pointer<wire_cst_list_String>,
|
||||
)
|
||||
>
|
||||
>(
|
||||
'frbgen_starcitizen_doctor_wire__crate__api__ort_api__translate_text_batch',
|
||||
);
|
||||
late final _wire__crate__api__ort_api__translate_text_batch =
|
||||
_wire__crate__api__ort_api__translate_text_batchPtr
|
||||
.asFunction<
|
||||
void Function(
|
||||
int,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
ffi.Pointer<wire_cst_list_String>,
|
||||
)
|
||||
>();
|
||||
|
||||
void wire__crate__api__ort_api__unload_translation_model(
|
||||
int port_,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict> model_key,
|
||||
) {
|
||||
return _wire__crate__api__ort_api__unload_translation_model(
|
||||
port_,
|
||||
model_key,
|
||||
);
|
||||
}
|
||||
|
||||
late final _wire__crate__api__ort_api__unload_translation_modelPtr =
|
||||
_lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(
|
||||
ffi.Int64,
|
||||
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
|
||||
)
|
||||
>
|
||||
>(
|
||||
'frbgen_starcitizen_doctor_wire__crate__api__ort_api__unload_translation_model',
|
||||
);
|
||||
late final _wire__crate__api__ort_api__unload_translation_model =
|
||||
_wire__crate__api__ort_api__unload_translation_modelPtr
|
||||
.asFunction<
|
||||
void Function(int, ffi.Pointer<wire_cst_list_prim_u_8_strict>)
|
||||
>();
|
||||
|
||||
void wire__crate__api__rs_process__write(
|
||||
int port_,
|
||||
int rs_pid,
|
||||
|
||||
Reference in New Issue
Block a user