@@ -48,8 +48,6 @@ const rules =
4848}
4949
5050
51-
52-
5351const tools = [
5452 {
5553 type : "function" ,
@@ -125,8 +123,14 @@ async function initializeWebLLMEngine() {
125123 document . getElementById ( "user-input" ) . textContent = 'Write and execute a sample SPARQL query'
126124 document . getElementById ( "download-status" ) . classList . remove ( "hidden" ) ;
127125 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+
128132 const config = {
129- temperature : 0.6 ,
133+ temperature : temperature ,
130134 top_p : 0.9 ,
131135 context_window_size : - 1 ,
132136 sliding_window_size : 8192 ,
@@ -194,14 +198,13 @@ const availableModels = webllm.prebuiltAppConfig.model_list
194198 . map ( ( m ) => m . model_id )
195199 . filter ( ( model_id ) => (
196200 model_id . startsWith ( 'Qwen2.5-7B' )
197- // || model_id.startsWith('Hermes-2-Pro-Llama')
198201 || model_id . startsWith ( 'Hermes-3-Llama-3.1' )
199202 || ( model_id . startsWith ( 'Llama-3.1-8B-' ) && ! model_id . endsWith ( '-1k' ) )
200203// || model_id.startsWith('DeepSeek-R1-Distill-Llama-')
201204 ) ) ;
202205
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" ;
205208
206209async function onMessageStop ( ) {
207210 engine . interruptGenerate ( ) ;
@@ -379,22 +382,7 @@ class ToolHanler {
379382+ 'You are a helpful Assistant.\n'
380383+ 'Do not generate function results.\n'
381384+ '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'
398386
399387
400388
@@ -428,8 +416,7 @@ class ToolHanler {
428416+ 'You are a helpful Assistant.\n'
429417+ 'Do not generate function results.\n'
430418+ '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'
433420
434421
435422 llama31_template =
@@ -454,8 +441,9 @@ class ToolHanler {
454441+ 'You are a helpful Assistant.\n'
455442+ 'Do not generate function results.\n'
456443+ '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+
459447 deepseek_template =
460448 'Cutting Knowledge Date: December 2023\n'
461449+ 'Today Date: 23 Jul 2024\n\n'
@@ -485,8 +473,6 @@ class ToolHanler {
485473 constructor ( model_id ) {
486474 if ( model_id . startsWith ( 'Qwen2.5' ) )
487475 this . mode = 'qwen' ;
488- else if ( model_id . startsWith ( 'Hermes-2-Pro-' ) )
489- this . mode = 'hermes2_llama'
490476 else if ( model_id . startsWith ( 'Hermes-3-Llama' ) )
491477 this . mode = 'hermes3_llama'
492478 else if ( model_id . startsWith ( 'Llama-3.1-' ) )
@@ -507,10 +493,7 @@ class ToolHanler {
507493 funcs += JSON . stringify ( t , '\n' , 2 ) + '\n\n' ;
508494
509495 if ( this . mode === 'qwen' )
510- // return this.qwen_template.replace('#{functions}', JSON.stringify(tools, '\n', 2));
511496 sys_template = this . qwen_template . replace ( '#{functions}' , funcs ) ;
512- else if ( this . mode === 'hermes2_llama' )
513- sys_template = this . hermes2_template . replace ( '#{functions}' , funcs ) ;
514497 else if ( this . mode === 'hermes3_llama' )
515498 sys_template = this . hermes2_template . replace ( '#{functions}' , funcs ) ;
516499 else if ( this . mode === 'llama31' )
@@ -520,7 +503,7 @@ class ToolHanler {
520503 else if ( this . mode === 'deepseek' )
521504 sys_template = this . deepseek_template . replace ( '#{functions}' , funcs ) ;
522505
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`
524507 }
525508
526509 checkResponse ( str ) {
@@ -532,7 +515,7 @@ class ToolHanler {
532515 const function_end = str . match ( this . rexp_function ) ;
533516
534517
535- if ( this . mode === 'qwen' || this . mode === 'hermes2_llama' || this . mode === ' hermes3_llama') {
518+ if ( this . mode === 'qwen' || this . mode === 'hermes3_llama' ) {
536519 if ( str . startsWith ( "<tool_call>" ) ) {
537520 tool_call = str . replace ( "<tool_call>" , "" ) . replace ( "</tool_call>" , "" ) ;
538521 }
0 commit comments