@@ -284,47 +284,49 @@ export default {
284284 case 'business_message' : {
285285 await bot . sendTyping ( ) ;
286286 const prompt = bot . update . business_message ?. text ?. toString ( ) ?? '' ;
287- const { results } = await env . DB . prepare ( 'SELECT * FROM Messages WHERE userId=?' )
288- . bind (
289- bot . update . inline_query
290- ? bot . update . inline_query . from . id
291- : bot . update . business_message
292- ? bot . update . business_message . from . id
293- : bot . update . message ?. from . id ,
294- )
295- . all ( ) ;
296- const message_history = results . map ( ( col ) => ( { role : 'system' , content : col . content as string } ) ) ;
297- const messages = [
298- { role : 'system' , content : 'You are a friendly assistant named Sean.' } ,
299- ...message_history ,
300- {
301- role : 'user' ,
302- content : prompt ,
303- } ,
304- ] ;
305- let response : AiTextGenerationOutput ;
306- try {
307- // @ts -expect-error broken bindings
308- response = await env . AI . run ( '@cf/meta/llama-3.1-70b-instruct' , { messages } ) ;
309- } catch ( e ) {
310- console . log ( e ) ;
311- await bot . reply ( `Error: ${ e as string } ` ) ;
312- return new Response ( 'ok' ) ;
313- }
314- if ( 'response' in response ) {
315- if ( response . response ) {
316- await bot . reply ( await markdown_to_html ( response . response ?? '' ) , 'HTML' ) ;
317- await env . DB . prepare ( 'INSERT INTO Messages (id, userId, content) VALUES (?, ?, ?)' )
318- . bind (
319- crypto . randomUUID ( ) ,
320- bot . update . inline_query
321- ? bot . update . inline_query . from . id
322- : bot . update . business_message
323- ? bot . update . business_message . from . id
324- : bot . update . message ?. from . id ,
325- `'[INST] ${ prompt } [/INST] \n ${ response . response } ` ,
326- )
327- . run ( ) ;
287+ if ( bot . update . business_message ?. from . id !== 69148517 ) {
288+ const { results } = await env . DB . prepare ( 'SELECT * FROM Messages WHERE userId=?' )
289+ . bind (
290+ bot . update . inline_query
291+ ? bot . update . inline_query . from . id
292+ : bot . update . business_message
293+ ? bot . update . business_message . from . id
294+ : bot . update . message ?. from . id ,
295+ )
296+ . all ( ) ;
297+ const message_history = results . map ( ( col ) => ( { role : 'system' , content : col . content as string } ) ) ;
298+ const messages = [
299+ { role : 'system' , content : 'You are a friendly assistant named Sean.' } ,
300+ ...message_history ,
301+ {
302+ role : 'user' ,
303+ content : prompt ,
304+ } ,
305+ ] ;
306+ let response : AiTextGenerationOutput ;
307+ try {
308+ // @ts -expect-error broken bindings
309+ response = await env . AI . run ( '@cf/meta/llama-3.1-70b-instruct' , { messages } ) ;
310+ } catch ( e ) {
311+ console . log ( e ) ;
312+ await bot . reply ( `Error: ${ e as string } ` ) ;
313+ return new Response ( 'ok' ) ;
314+ }
315+ if ( 'response' in response ) {
316+ if ( response . response ) {
317+ await bot . reply ( await markdown_to_html ( response . response ?? '' ) , 'HTML' ) ;
318+ await env . DB . prepare ( 'INSERT INTO Messages (id, userId, content) VALUES (?, ?, ?)' )
319+ . bind (
320+ crypto . randomUUID ( ) ,
321+ bot . update . inline_query
322+ ? bot . update . inline_query . from . id
323+ : bot . update . business_message
324+ ? bot . update . business_message . from . id
325+ : bot . update . message ?. from . id ,
326+ `'[INST] ${ prompt } [/INST] \n ${ response . response } ` ,
327+ )
328+ . run ( ) ;
329+ }
328330 }
329331 }
330332 break ;
0 commit comments