@@ -48,8 +48,6 @@ const rules =
48
48
}
49
49
50
50
51
-
52
-
53
51
const tools = [
54
52
{
55
53
type : "function" ,
@@ -125,8 +123,14 @@ async function initializeWebLLMEngine() {
125
123
document . getElementById ( "user-input" ) . textContent = 'Write and execute a sample SPARQL query'
126
124
document . getElementById ( "download-status" ) . classList . remove ( "hidden" ) ;
127
125
selectedModel = document . getElementById ( "model-selection" ) . value ;
126
+
127
+ let temperature = 0.5 ;
128
+
129
+ if ( selectedModel . startsWith ( 'Llama-3.1-' ) )
130
+ temperature = 0.4 ;
131
+
128
132
const config = {
129
- temperature : 0.6 ,
133
+ temperature : temperature ,
130
134
top_p : 0.9 ,
131
135
context_window_size : - 1 ,
132
136
sliding_window_size : 8192 ,
@@ -194,14 +198,13 @@ const availableModels = webllm.prebuiltAppConfig.model_list
194
198
. map ( ( m ) => m . model_id )
195
199
. filter ( ( model_id ) => (
196
200
model_id . startsWith ( 'Qwen2.5-7B' )
197
- // || model_id.startsWith('Hermes-2-Pro-Llama')
198
201
|| model_id . startsWith ( 'Hermes-3-Llama-3.1' )
199
202
|| ( model_id . startsWith ( 'Llama-3.1-8B-' ) && ! model_id . endsWith ( '-1k' ) )
200
203
// || model_id.startsWith('DeepSeek-R1-Distill-Llama-')
201
204
) ) ;
202
205
203
- let selectedModel = "Llama-3.1-8B-Instruct-q4f16_1-1k" ;
204
- // let selectedModel = "Qwen2.5-7B-Instruct-q4f16_1-MLC";
206
+ // let selectedModel = "Llama-3.1-8B-Instruct-q4f16_1-1k";
207
+ let selectedModel = "Qwen2.5-7B-Instruct-q4f16_1-MLC" ;
205
208
206
209
async function onMessageStop ( ) {
207
210
engine . interruptGenerate ( ) ;
@@ -379,22 +382,7 @@ class ToolHanler {
379
382
+ 'You are a helpful Assistant.\n'
380
383
+ 'Do not generate function results.\n'
381
384
+ 'Always do real call of functions, when it is required.\n'
382
- + 'Execute only one function per time.\n' ;
383
-
384
-
385
- hermes2_template =
386
- `You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags.`
387
- + ` You may call one or more functions to assist with the user query. `
388
- + `Don't make assumptions about what values to plug into functions. Here are the available tools: <tools>\n`
389
- + ' #{functions} \n\n'
390
- + ` </tools>.\n Use the following pydantic model json schema for each tool call you will make:`
391
- + ` {"properties": {"arguments": {"title": "Arguments", "type": "object"}, "name": {"title": "Name", "type": "string"}}, "required": ["arguments", "name"], "title": "FunctionCall", "type": "object"} `
392
- + `For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:\n`
393
- + `<tool_call>\n{"arguments": <args-dict>, "name": <function-name>}\n</tool_call>\n`
394
- + 'You are a helpful Assistant.\n'
395
- + 'Do not generate function results.\n'
396
- + 'Always do real call of functions, when it is required.\n'
397
- + 'Execute only one function per time.\n' ;
385
+ + 'Execute only one function per time.\n'
398
386
399
387
400
388
@@ -428,8 +416,7 @@ class ToolHanler {
428
416
+ 'You are a helpful Assistant.\n'
429
417
+ 'Do not generate function results.\n'
430
418
+ 'Always do real call of functions, when it is required.\n'
431
- + 'Execute only one function per time.\n' ;
432
-
419
+ + 'Execute only one function per time.\n'
433
420
434
421
435
422
llama31_template =
@@ -454,8 +441,9 @@ class ToolHanler {
454
441
+ 'You are a helpful Assistant.\n'
455
442
+ 'Do not generate function results.\n'
456
443
+ 'Always do real call of functions, when it is required.\n'
457
- + 'Execute only one function per time.\n' ;
458
-
444
+ + 'Execute only one function per time.\n'
445
+
446
+
459
447
deepseek_template =
460
448
'Cutting Knowledge Date: December 2023\n'
461
449
+ 'Today Date: 23 Jul 2024\n\n'
@@ -485,8 +473,6 @@ class ToolHanler {
485
473
constructor ( model_id ) {
486
474
if ( model_id . startsWith ( 'Qwen2.5' ) )
487
475
this . mode = 'qwen' ;
488
- else if ( model_id . startsWith ( 'Hermes-2-Pro-' ) )
489
- this . mode = 'hermes2_llama'
490
476
else if ( model_id . startsWith ( 'Hermes-3-Llama' ) )
491
477
this . mode = 'hermes3_llama'
492
478
else if ( model_id . startsWith ( 'Llama-3.1-' ) )
@@ -507,10 +493,7 @@ class ToolHanler {
507
493
funcs += JSON . stringify ( t , '\n' , 2 ) + '\n\n' ;
508
494
509
495
if ( this . mode === 'qwen' )
510
- // return this.qwen_template.replace('#{functions}', JSON.stringify(tools, '\n', 2));
511
496
sys_template = this . qwen_template . replace ( '#{functions}' , funcs ) ;
512
- else if ( this . mode === 'hermes2_llama' )
513
- sys_template = this . hermes2_template . replace ( '#{functions}' , funcs ) ;
514
497
else if ( this . mode === 'hermes3_llama' )
515
498
sys_template = this . hermes2_template . replace ( '#{functions}' , funcs ) ;
516
499
else if ( this . mode === 'llama31' )
@@ -520,7 +503,7 @@ class ToolHanler {
520
503
else if ( this . mode === 'deepseek' )
521
504
sys_template = this . deepseek_template . replace ( '#{functions}' , funcs ) ;
522
505
523
- return sys_template + `\n\n\n ${ JSON . stringify ( rules , '\n' , 2 ) } \n \n`
506
+ return sys_template + `\n\n ${ JSON . stringify ( rules , '\n' , 2 ) } \n`
524
507
}
525
508
526
509
checkResponse ( str ) {
@@ -532,7 +515,7 @@ class ToolHanler {
532
515
const function_end = str . match ( this . rexp_function ) ;
533
516
534
517
535
- if ( this . mode === 'qwen' || this . mode === 'hermes2_llama' || this . mode === ' hermes3_llama') {
518
+ if ( this . mode === 'qwen' || this . mode === 'hermes3_llama' ) {
536
519
if ( str . startsWith ( "<tool_call>" ) ) {
537
520
tool_call = str . replace ( "<tool_call>" , "" ) . replace ( "</tool_call>" , "" ) ;
538
521
}
0 commit comments