diff --git a/examples/llama.android/app/src/main/java/com/example/llama/MainActivity.kt b/examples/llama.android/app/src/main/java/com/example/llama/MainActivity.kt index 872ec2b98ab..5708a7c9f36 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/MainActivity.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/MainActivity.kt @@ -17,6 +17,7 @@ import com.arm.aichat.AiChat import com.arm.aichat.InferenceEngine import com.arm.aichat.gguf.GgufMetadata import com.arm.aichat.gguf.GgufMetadataReader +import com.arm.aichat.gguf.create import com.google.android.material.floatingactionbutton.FloatingActionButton import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job diff --git a/examples/llama.android/lib/src/main/java/com/arm/aichat/gguf/GgufMetadataReader.kt b/examples/llama.android/lib/src/main/java/com/arm/aichat/gguf/GgufMetadataReader.kt index 264a6c0bda1..9bb1883d66d 100644 --- a/examples/llama.android/lib/src/main/java/com/arm/aichat/gguf/GgufMetadataReader.kt +++ b/examples/llama.android/lib/src/main/java/com/arm/aichat/gguf/GgufMetadataReader.kt @@ -2,7 +2,6 @@ package com.arm.aichat.gguf import android.content.Context import android.net.Uri -import com.arm.aichat.internal.gguf.GgufMetadataReaderImpl import java.io.File import java.io.IOException import java.io.InputStream @@ -42,35 +41,12 @@ interface GgufMetadataReader { suspend fun readStructuredMetadata(input: InputStream): GgufMetadata companion object { - private val DEFAULT_SKIP_KEYS = setOf( + val DEFAULT_SKIP_KEYS = setOf( "tokenizer.chat_template", "tokenizer.ggml.scores", "tokenizer.ggml.tokens", "tokenizer.ggml.token_type" ) - - /** - * Creates a default GgufMetadataReader instance - */ - fun create(): GgufMetadataReader = GgufMetadataReaderImpl( - skipKeys = DEFAULT_SKIP_KEYS, - arraySummariseThreshold = 1_000 - ) - - /** - * Creates a GgufMetadataReader with custom configuration - * - * @param skipKeys Keys whose value should be skipped entirely (not kept in the result map) - * @param arraySummariseThreshold If ≥0, arrays longer get summarised, not materialised; - * If -1, never summarise. - */ - fun create( - skipKeys: Set = DEFAULT_SKIP_KEYS, - arraySummariseThreshold: Int = 1_000 - ): GgufMetadataReader = GgufMetadataReaderImpl( - skipKeys = skipKeys, - arraySummariseThreshold = arraySummariseThreshold - ) } } diff --git a/examples/llama.android/lib/src/main/java/com/arm/aichat/gguf/GgufMetadataReaderFactory.kt b/examples/llama.android/lib/src/main/java/com/arm/aichat/gguf/GgufMetadataReaderFactory.kt new file mode 100644 index 00000000000..bb26008fc40 --- /dev/null +++ b/examples/llama.android/lib/src/main/java/com/arm/aichat/gguf/GgufMetadataReaderFactory.kt @@ -0,0 +1,26 @@ +package com.arm.aichat.gguf + +import com.arm.aichat.internal.gguf.GgufMetadataReaderImpl + +/** + * Creates a default GgufMetadataReader instance + */ +fun GgufMetadataReader.Companion.create(): GgufMetadataReader = GgufMetadataReaderImpl( + skipKeys = DEFAULT_SKIP_KEYS, + arraySummariseThreshold = 1_000 +) + +/** + * Creates a GgufMetadataReader with custom configuration + * + * @param skipKeys Keys whose value should be skipped entirely (not kept in the result map) + * @param arraySummariseThreshold If ≥0, arrays longer get summarised, not materialised; + * If -1, never summarise. + */ +fun GgufMetadataReader.Companion.create( + skipKeys: Set = DEFAULT_SKIP_KEYS, + arraySummariseThreshold: Int = 1_000 +): GgufMetadataReader = GgufMetadataReaderImpl( + skipKeys = skipKeys, + arraySummariseThreshold = arraySummariseThreshold +)