@@ -39,6 +39,32 @@ const tools = [
3939 } ,
4040 } ,
4141 } ,
42+ {
43+ type : "function" ,
44+ function : {
45+ name : "execute_SPARQL" ,
46+ description : "Execute any SPARQL select queries and fetch results" +
47+ "Always use this if the user is asking for execute some SPARQL select query. " +
48+ "If the user has a typo in their SPARQL select query, correct it before executing." ,
49+ parameters : {
50+ type : "object" ,
51+ properties : {
52+ type : "object" ,
53+ properties : {
54+ query : {
55+ type : "string" ,
56+ description : "SPARQL select query"
57+ }
58+ } ,
59+ } ,
60+ required : [ "query" ] ,
61+ } ,
62+ "return" : {
63+ "type" : "object" ,
64+ "description" : "A data in application/sparql-results+json format"
65+ }
66+ } ,
67+ } ,
4268 ] ;
4369
4470const system_prompt = llm_template . replace ( '#{functions}' , JSON . stringify ( tools , '\n' , 2 ) ) ;
@@ -63,7 +89,7 @@ const availableModels = webllm.prebuiltAppConfig.model_list
6389 . map ( ( m ) => m . model_id )
6490 . filter ( ( model_id ) => model_id . startsWith ( 'Qwen2.5-' ) ) ;
6591
66- let selectedModel = "Qwen2.5-3B -Instruct-q4f16_1 -MLC" ;
92+ let selectedModel = "Qwen2.5-7B -Instruct-q4f32_1 -MLC" ;
6793
6894// Callback function for initializing progress
6995function updateEngineInitProgressCallback ( report ) {
@@ -80,8 +106,11 @@ async function initializeWebLLMEngine() {
80106 document . getElementById ( "download-status" ) . classList . remove ( "hidden" ) ;
81107 selectedModel = document . getElementById ( "model-selection" ) . value ;
82108 const config = {
83- temperature : 1.0 ,
109+ temperature : 0.5 ,
84110 top_p : 1 ,
111+ content_window_size : 8192 ,
112+ // sliding_window_size: 8192,
113+ prefill_chunk_size : 8192 ,
85114 } ;
86115 await engine . reload ( selectedModel , config ) ;
87116}
@@ -193,7 +222,12 @@ async function onMessageSend() {
193222 if ( tool_call && tool_call . name === "fetch_wikipedia_content" ) {
194223 const ret = await fetch_wikipedia_content ( tool_call . arguments . search_query ) ;
195224 content = JSON . stringify ( ret ) ;
196- } else {
225+ }
226+ else if ( tool_call && tool_call . name === "execute_SPARQL" ) {
227+ const ret = await execute_SPARQL ( tool_call . arguments . query ) ;
228+ content = JSON . stringify ( ret ) ;
229+ }
230+ else {
197231 content = 'Error: Unknown function ' + tool_call ?. name
198232 }
199233
@@ -327,3 +361,30 @@ async function fetch_wikipedia_content(searchQuery)
327361 } ;
328362 }
329363}
364+
365+
366+ const endpoint = "https://linkeddata.uriburner.com/sparql/?format=application%2Fsparql-results%2Bjson&timeout=30000&maxrows=15"
367+
368+ async function execute_SPARQL ( query ) {
369+ const url = new URL ( endpoint ) ;
370+ url . searchParams . append ( 'query' , query ) ;
371+
372+ try {
373+ const response = await fetch ( url , {
374+ method : 'GET' ,
375+ headers : {
376+ 'Accept' : 'application/sparql-results+json' ,
377+ } ,
378+ } ) ;
379+
380+ if ( ! response . ok ) {
381+ throw new Error ( `HTTP error! Status: ${ response . status } ` ) ;
382+ }
383+
384+ const results = await response . json ( ) ;
385+ return results ;
386+ } catch ( ex ) {
387+ console . error ( 'Error executing SPARQL query:' , ex ) ;
388+ return { error : ex . toString ( ) }
389+ }
390+ }
0 commit comments