117117 max-width : 65% ;
118118 }
119119
120+ .message .console .message-content {
121+ font-family : 'Monaco' , 'Menlo' , 'Ubuntu Mono' , 'Consolas' , 'Courier New' , monospace;
122+ font-size : 0.875rem ;
123+ background-color : # fafafa ;
124+ padding : 0.75rem 1rem ;
125+ color : # 374151 ;
126+ max-width : 80% ;
127+ }
128+
120129 .input-container {
121130 background-color : # ffffff ;
122131 padding : 1rem ;
@@ -255,6 +264,8 @@ <h1>nanochat</h1>
255264
256265 let messages = [ ] ;
257266 let isGenerating = false ;
267+ let currentTemperature = 0.8 ;
268+ let currentTopK = 50 ;
258269
259270 chatInput . addEventListener ( 'input' , function ( ) {
260271 this . style . height = 'auto' ;
@@ -304,10 +315,67 @@ <h1>nanochat</h1>
304315 return contentDiv ;
305316 }
306317
318+ function handleSlashCommand ( command ) {
319+ const parts = command . trim ( ) . split ( / \s + / ) ;
320+ const cmd = parts [ 0 ] . toLowerCase ( ) ;
321+ const arg = parts [ 1 ] ;
322+
323+ if ( cmd === '/temperature' ) {
324+ if ( arg === undefined ) {
325+ addMessage ( 'console' , `Current temperature: ${ currentTemperature } ` ) ;
326+ } else {
327+ const temp = parseFloat ( arg ) ;
328+ if ( isNaN ( temp ) || temp < 0 || temp > 2 ) {
329+ addMessage ( 'console' , 'Invalid temperature. Must be between 0.0 and 2.0' ) ;
330+ } else {
331+ currentTemperature = temp ;
332+ addMessage ( 'console' , `Temperature set to ${ currentTemperature } ` ) ;
333+ }
334+ }
335+ return true ;
336+ } else if ( cmd === '/topk' ) {
337+ if ( arg === undefined ) {
338+ addMessage ( 'console' , `Current top-k: ${ currentTopK } ` ) ;
339+ } else {
340+ const topk = parseInt ( arg ) ;
341+ if ( isNaN ( topk ) || topk < 1 || topk > 200 ) {
342+ addMessage ( 'console' , 'Invalid top-k. Must be between 1 and 200' ) ;
343+ } else {
344+ currentTopK = topk ;
345+ addMessage ( 'console' , `Top-k set to ${ currentTopK } ` ) ;
346+ }
347+ }
348+ return true ;
349+ } else if ( cmd === '/clear' ) {
350+ newConversation ( ) ;
351+ return true ;
352+ } else if ( cmd === '/help' ) {
353+ addMessage ( 'console' ,
354+ 'Available commands:\n' +
355+ '/temperature - Show current temperature\n' +
356+ '/temperature <value> - Set temperature (0.0-2.0)\n' +
357+ '/topk - Show current top-k\n' +
358+ '/topk <value> - Set top-k (1-200)\n' +
359+ '/clear - Clear conversation\n' +
360+ '/help - Show this help message'
361+ ) ;
362+ return true ;
363+ }
364+ return false ;
365+ }
366+
307367 async function sendMessage ( ) {
308368 const message = chatInput . value . trim ( ) ;
309369 if ( ! message || isGenerating ) return ;
310370
371+ // Handle slash commands
372+ if ( message . startsWith ( '/' ) ) {
373+ chatInput . value = '' ;
374+ chatInput . style . height = 'auto' ;
375+ handleSlashCommand ( message ) ;
376+ return ;
377+ }
378+
311379 isGenerating = true ;
312380 chatInput . value = '' ;
313381 chatInput . style . height = 'auto' ;
@@ -327,7 +395,8 @@ <h1>nanochat</h1>
327395 } ,
328396 body : JSON . stringify ( {
329397 messages : messages ,
330- temperature : 0.8 ,
398+ temperature : currentTemperature ,
399+ top_k : currentTopK ,
331400 max_tokens : 512
332401 } ) ,
333402 } ) ;
0 commit comments