config update

This commit is contained in:
gcw_4spBpAfv
2026-03-05 14:41:25 +08:00
parent bd07a7526a
commit ef2bada800
2 changed files with 33 additions and 15 deletions

View File

@@ -83,13 +83,13 @@ object FileHelper {
// @JvmStatic
// 当前使用的模型文件名
private const val MODEL_FILE_NAME = "Qwen3-0.6B-rk3588-w8a8.rkllm"
private val MODEL_FILE_NAME = com.digitalperson.config.AppConfig.LLM.MODEL_FILE_NAME
fun getLLMModelPath(context: Context): String {
Log.d(TAG, "=== getLLMModelPath START ===")
// 从应用内部存储目录加载模型
val llmDir = ensureDir(File(context.filesDir, "llm"))
val llmDir = ensureDir(File(context.filesDir, AppConfig.LLM.MODEL_DIR))
Log.d(TAG, "Loading models from: ${llmDir.absolutePath}")
@@ -122,7 +122,7 @@ object FileHelper {
) {
Log.d(TAG, "=== downloadModelFilesWithProgress START ===")
val llmDir = ensureDir(File(context.filesDir, "llm"))
val llmDir = ensureDir(File(context.filesDir, AppConfig.LLM.MODEL_DIR))
// 模型文件列表 - 使用 DeepSeek-R1-Distill-Qwen-1.5B 模型
val modelFiles = listOf(
@@ -137,19 +137,20 @@ object FileHelper {
var totalSize: Long = 0
// 首先计算总大小
val downloadUrl = AppConfig.LLM.DOWNLOAD_SERVER + AppConfig.LLM.DOWNLOAD_PATH
Log.i(TAG, "Using download server: ${AppConfig.LLM.DOWNLOAD_SERVER}")
for (fileName in modelFiles) {
val modelFile = File(llmDir, fileName)
if (!modelFile.exists() || modelFile.length() == 0L) {
val size = getFileSizeFromServer("http://192.168.1.19:5000/download/$fileName")
val size = getFileSizeFromServer("$downloadUrl/$fileName")
if (size > 0) {
totalSize += size
} else {
// 如果无法获取文件大小,使用估计值
when (fileName) {
MODEL_FILE_NAME -> totalSize += 1L * 1024 * 1024 * 1024 // 1.5B模型约1GB
else -> totalSize += 1L * 1024 * 1024 * 1024 // 1GB 默认
}
Log.i(TAG, "Using estimated size for $fileName: ${totalSize / (1024*1024)} MB")
val estimatedSize = AppConfig.LLM.MODEL_SIZE_ESTIMATE
totalSize += estimatedSize
Log.i(TAG, "Using estimated size for $fileName: ${estimatedSize / (1024*1024)} MB")
}
}
}
@@ -160,7 +161,7 @@ object FileHelper {
Log.i(TAG, "Downloading model file: $fileName")
try {
downloadFileWithProgress(
"http://192.168.1.19:5000/download/$fileName",
"$downloadUrl/$fileName",
modelFile
) { downloaded, total ->
val progress = if (totalSize > 0) {
@@ -199,8 +200,8 @@ object FileHelper {
return try {
val connection = java.net.URL(url).openConnection() as java.net.HttpURLConnection
connection.requestMethod = "HEAD"
connection.connectTimeout = 15000
connection.readTimeout = 15000
connection.connectTimeout = AppConfig.LLM.DOWNLOAD_CONNECT_TIMEOUT
connection.readTimeout = AppConfig.LLM.DOWNLOAD_READ_TIMEOUT
// 从响应头获取 Content-Length避免 int 溢出
val contentLengthStr = connection.getHeaderField("Content-Length")
@@ -245,8 +246,8 @@ object FileHelper {
onProgress: (Long, Long) -> Unit
) {
val connection = java.net.URL(url).openConnection() as java.net.HttpURLConnection
connection.connectTimeout = 30000
connection.readTimeout = 6000000
connection.connectTimeout = AppConfig.LLM.DOWNLOAD_CONNECT_TIMEOUT
connection.readTimeout = AppConfig.LLM.DOWNLOAD_READ_TIMEOUT
// 从响应头获取 Content-Length避免 int 溢出
val contentLengthStr = connection.getHeaderField("Content-Length")
@@ -286,7 +287,7 @@ object FileHelper {
*/
@JvmStatic
fun isLocalLLMAvailable(context: Context): Boolean {
val llmDir = File(context.filesDir, "llm")
val llmDir = File(context.filesDir, AppConfig.LLM.MODEL_DIR)
val rkllmFile = File(llmDir, MODEL_FILE_NAME)