Skip to content

Commit 8ca49eb

Browse files
refac(lm): update debugging logs and lm listner lifecycle
1 parent 276e2bf commit 8ca49eb

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

  • apps/app/src/components/general/app_settings/editor/lm_config/local

apps/app/src/components/general/app_settings/editor/lm_config/local/index.svelte

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
<script lang="ts">
22
import { invoke } from '@tauri-apps/api/core';
33
import { LLMStreamListener } from 'tauri-plugin-llm-api';
4+
import { onMount } from 'svelte';
5+
46
const listener = new LLMStreamListener();
5-
let text = $state<string>();
6-
listener.setup({
7-
onData: (id, data, timestamp) => {
8-
text = new TextDecoder().decode(data);
9-
console.log(text);
10-
},
11-
onError: (msg) => console.error('Error:', msg),
12-
onEnd: (usage) => {
13-
if (usage) {
14-
console.log(`Done. ${usage.total_tokens} tokens used.`);
15-
}
16-
},
7+
let text = $state<string>('hi');
8+
9+
onMount(async () => {
10+
await listener.setup({
11+
onData: (id, data, timestamp) => {
12+
const chunk = new TextDecoder().decode(data);
13+
text += chunk;
14+
console.log('Incoming chunk:', chunk);
15+
},
16+
onError: (msg) => console.error('Error:', msg),
17+
onEnd: (usage) => {
18+
if (usage) {
19+
console.log(`Done. ${usage.total_tokens} tokens used.`);
20+
}
21+
},
22+
});
1723
});
1824
</script>
1925

0 commit comments

Comments
 (0)