@@ -188,9 +188,8 @@ export default {
188188
189189 case 'business_message' : {
190190 await bot . sendTyping ( ) ;
191- const fileId : string = bot . update . business_message ?. photo ?. pop ( ) ?. file_id ?? '' ;
192- const fileResponse = await bot . getFile ( fileId ) ;
193- const blob = await fileResponse . arrayBuffer ( ) ;
191+ const photo = bot . update . business_message ?. photo ;
192+ const fileId : string = photo ? photo [ photo . length - 1 ] ?. file_id ?? '' : '' ;
194193 const prompt = bot . update . business_message ?. text ?. toString ( ) ?? bot . update . business_message ?. caption ?? '' ;
195194
196195 if ( bot . update . business_message ?. from . id !== 69148517 ) {
@@ -199,22 +198,30 @@ export default {
199198 . all ( ) ;
200199
201200 const messageHistory = results . map ( ( col ) => ( { role : 'system' , content : col . content as string } ) ) ;
202-
203201 const messages = [ { role : 'system' , content : SYSTEM_PROMPTS . SEAN } , ...messageHistory , { role : 'user' , content : prompt } ] ;
204202
205203 try {
206204 let response ;
207-
208- if ( blob . byteLength === 0 ) {
205+
206+ if ( fileId ) {
207+ const fileResponse = await bot . getFile ( fileId ) ;
208+ const blob = await fileResponse . arrayBuffer ( ) ;
209209 // @ts -expect-error broken bindings
210- response = await env . AI . run ( AI_MODELS . LLAMA , { messages } ) ;
210+ response = await env . AI . run ( AI_MODELS . LLAMA , { messages, image : [ ... new Uint8Array ( blob ) ] } ) ;
211211 } else {
212212 // @ts -expect-error broken bindings
213- response = await env . AI . run ( AI_MODELS . LLAMA , { messages, image : [ ... new Uint8Array ( blob ) ] } ) ;
213+ response = await env . AI . run ( AI_MODELS . LLAMA , { messages } ) ;
214214 }
215215
216216 if ( 'response' in response && response . response ) {
217- await bot . reply ( await markdownToHtml ( typeof response . response === 'string' ? response . response : '' ) , 'HTML' ) ;
217+ await bot . reply (
218+ await markdownToHtml (
219+ typeof response . response === 'string'
220+ ? response . response
221+ : JSON . stringify ( response . response )
222+ ) ,
223+ 'HTML'
224+ ) ;
218225
219226 await env . DB . prepare ( 'INSERT INTO Messages (id, userId, content) VALUES (?, ?, ?)' )
220227 . bind (
0 commit comments