Skip to content

Commit 81991d7

Browse files
author
Varun Khare
committed
add tool-calling with qwen wip
Signed-off-by: Varun Khare <varun.khare@nimbledgehq.ai>
1 parent 417c835 commit 81991d7

File tree

8 files changed

+70
-40
lines changed

8 files changed

+70
-40
lines changed

android/app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ dependencies {
100100
debugImplementation(libs.androidx.ui.tooling)
101101
debugImplementation(libs.androidx.ui.test.manifest)
102102

103-
implementation("dev.deliteai:nimblenet_ktx:0.0.1-dev-1751902318")
104-
implementation("dev.deliteai:nimblenet_core:0.0.1-dev-1751904491")
103+
implementation("dev.deliteai:nimblenet_ktx:0.0.1-dev-1751904492")
104+
implementation("dev.deliteai:nimblenet_core:0.0.1-dev-1751904492")
105105

106106
implementation("com.halilibo.compose-richtext:richtext-ui-material3:1.0.0+")
107107
implementation("com.halilibo.compose-richtext:richtext-commonmark:1.0.0+")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"architectures": [
3+
"Qwen3ForCausalLM"
4+
],
5+
"attention_bias": false,
6+
"attention_dropout": 0.0,
7+
"bos_token_id": 151643,
8+
"eos_token_id": 151645,
9+
"head_dim": 128,
10+
"hidden_act": "silu",
11+
"hidden_size": 2048,
12+
"initializer_range": 0.02,
13+
"intermediate_size": 6144,
14+
"max_position_embeddings": 40960,
15+
"max_window_layers": 28,
16+
"model_type": "qwen3",
17+
"num_attention_heads": 16,
18+
"num_hidden_layers": 28,
19+
"num_key_value_heads": 8,
20+
"rms_norm_eps": 1e-06,
21+
"rope_scaling": null,
22+
"rope_theta": 1000000,
23+
"sliding_window": null,
24+
"tie_word_embeddings": true,
25+
"torch_dtype": "bfloat16",
26+
"transformers_version": "4.52.0.dev0",
27+
"use_cache": true,
28+
"use_sliding_window": false,
29+
"vocab_size": 151936,
30+
"transformers.js_config": {
31+
"kv_cache_dtype": {
32+
"q4f16": "float16",
33+
"fp16": "float16"
34+
},
35+
"use_external_data_format": {
36+
"model.onnx": true,
37+
"model_fp16.onnx": true
38+
}
39+
}
40+
}

android/app/src/main/assets/tokenizer.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

android/app/src/main/kotlin/dev/deliteai/assistant/domain/features/llm/LLMManager.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,21 @@ package dev.deliteai.assistant.domain.features.llm
99
import dev.deliteai.NimbleNet
1010
import dev.deliteai.datamodels.NimbleNetTensor
1111
import dev.deliteai.impl.common.DATATYPE
12+
import org.json.JSONObject
1213

1314
object LLMManager {
1415
suspend fun feedInput(input: String, isVoiceInitiated: Boolean) {
1516
val res = NimbleNet.runMethod(
16-
"prompt_llm",
17+
"prompt_for_tool_calling",
1718
inputs = hashMapOf(
18-
"query" to NimbleNetTensor(input, DATATYPE.STRING, null),
19-
"is_voice_initiated" to NimbleNetTensor(
20-
if (isVoiceInitiated) 1 else 0,
21-
DATATYPE.INT32,
22-
null
23-
)
19+
"prompt" to NimbleNetTensor(input, DATATYPE.STRING, null),
2420
),
2521
)
26-
check(res.status) { "NimbleNet.runMethod('prompt_llm') failed with status: ${res.status}" }
22+
check(res.status) { "NimbleNet.runMethod('prompt_for_tool_calling') failed with status: ${res.status}" }
2723
}
2824

2925
suspend fun getNextMap(): Map<String, NimbleNetTensor> {
30-
val res2 = NimbleNet.runMethod("get_next_str", hashMapOf())
26+
val res2 = NimbleNet.runMethod("get_token_stream", hashMapOf())
3127
check(res2.status) { "NimbleNet.runMethod('get_next_str') failed with error: ${res2.error?.message}" }
3228
return res2.payload
3329
?: throw IllegalStateException("NimbleNet.runMethod('get_next_str') returned null payload")

android/app/src/main/kotlin/dev/deliteai/assistant/domain/repositories/ChatRepository.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ class ChatRepository {
5252
suspend fun getModelName() = LLMService.getLLMName()
5353

5454
fun getLLMText(textInput: String) = flow {
55-
LLMService.feedInput(textInput, false)
55+
repositoryScope.launch(Dispatchers.Default) { LLMService.feedInput(textInput, false) }
5656
do {
5757
val outputMap = LLMService.getNextMap()
58-
val currentOutputString = (outputMap["str"] as NimbleNetTensor).data.toString()
58+
val currentOutputString = (outputMap["token_stream"] as NimbleNetTensor).data.toString()
59+
Log.d(TAG, "token stream $currentOutputString")
5960
emit(GenerateResponseJobStatus.NextItem(currentOutputString))
60-
} while (!outputMap.containsKey("finished"))
61+
} while (!outputMap.containsKey("<|im_end|>"))
6162

6263
emit(GenerateResponseJobStatus.Finished())
6364
Log.d(TAG, "startFeedbackLoop: LLM finished output")

android/app/src/main/kotlin/dev/deliteai/assistant/presentation/components/ScrollableTextSuggestions.kt

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,10 @@ fun ScrollableTextSuggestions(
4242
) {
4343
val allSuggestions = remember {
4444
listOf(
45-
"Design workout routine",
46-
"Recommend wine pairings",
47-
"Write a short poem",
48-
"Draft party menu",
49-
"Create smoothie blends",
50-
"Generate gift ideas",
51-
"Craft cocktail ideas",
52-
"Mix mocktail recipes",
53-
"Suggest hiking essentials",
54-
"Plan a game night",
55-
"Prep for camping",
56-
"Plan a movie marathon",
57-
"Invent signature cocktail",
58-
"Craft lunchbox ideas",
59-
"Who are you?",
60-
"Plan a solo trip",
61-
"Curate weekend playlist",
62-
"Plan a beach day"
45+
"How is the weather here?",
46+
"Where am I located currently?",
47+
"Multiply 23 and 35",
48+
"What is time right now?"
6349
)
6450
}
6551

android/app/src/main/kotlin/dev/deliteai/assistant/utils/Utils.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ suspend fun initializeNimbleNetAndWaitForIsReady(application: Application, ct: S
7777
host = BuildConfig.NIMBLENET_CONFIG_HOST,
7878
deviceId = getInternalDeviceId(application),
7979
clientSecret = BuildConfig.NIMBLENET_CONFIG_CLIENT_SECRET,
80-
debug = false,
81-
compatibilityTag = ct,
80+
debug = true,
81+
online = true,
82+
compatibilityTag = "QWEN_ONNX",
8283
libraryVariant = NIMBLENET_VARIANTS.STATIC,
8384
showDownloadProgress = true
8485
)
@@ -93,17 +94,21 @@ suspend fun initializeNimbleNetAndWaitForIsReady(application: Application, ct: S
9394

9495
//used only during the app init
9596
private suspend fun passLexiconToTheWorkflowScript(context: Context) {
96-
val resString = context.assets.open("lexicon.json").bufferedReader().use { it.readText() }
97-
val lexiconArray = JSONObject(resString)
97+
val generationConfig = JSONObject(context.assets.open("config.json").bufferedReader().use { it.readText() })
98+
val tokenizerConfig = JSONObject(context.assets.open("tokenizer.json").bufferedReader().use { it.readText() })
99+
98100
val res = NimbleNet.runMethod(
99-
"init",
101+
"init_generation_mixin",
100102
inputs = hashMapOf(
101-
"lexicon" to NimbleNetTensor(
102-
shape = null, data = lexiconArray, datatype = DATATYPE.JSON
103+
"tokenizer_config" to NimbleNetTensor(
104+
shape = null, data = tokenizerConfig, datatype = DATATYPE.JSON
105+
),
106+
"generation_config" to NimbleNetTensor(
107+
shape = null, data = generationConfig, datatype = DATATYPE.JSON
103108
)
104109
)
105110
)
106-
check(res.status) { "NimbleNet.runMethod('init') failed with status: ${res.status}" }
111+
check(res.status) { "NimbleNet.runMethod('init_generation_mixin') failed with status: ${res.status}" }
107112
}
108113

109114
fun MutableList<String>.mergeChunks(): MutableList<String> {

android/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencyResolutionManagement {
2525
maven {
2626
url = uri("https://deliteai.s3.ap-south-1.amazonaws.com/releases-dev/android/")
2727
}
28+
mavenLocal()
2829
}
2930
}
3031

0 commit comments

Comments
 (0)