@@ -147,13 +147,14 @@ export default {
147147 } ;
148148 let response : AiImageToTextOutput ;
149149 try {
150- response = await env . AI . run ( '@cf/llava-hf/llava-1.5-7b-hf' , input ) ;
150+ // @ts -expect-error broken bindings
151+ response = await env . AI . run ( '@cf/meta/llama-3.2-11b-vision-instruct' , input ) ;
151152 } catch ( e ) {
152153 console . log ( e ) ;
153154 await bot . reply ( `Error: ${ e as string } ` ) ;
154155 return new Response ( 'ok' ) ;
155156 }
156- await bot . replyPhoto ( file_id , response . description ) ;
157+ await bot . replyPhoto ( file_id , ( response as unknown as { response : string } ) . response ) ;
157158 }
158159 return new Response ( 'ok' ) ;
159160 } )
@@ -277,8 +278,11 @@ export default {
277278 }
278279 case 'business_message' : {
279280 await bot . sendTyping ( ) ;
280- const prompt = bot . update . business_message ?. text ?. toString ( ) ?? '' ;
281- if ( bot . update . business_message ?. from . id !== 69148517 ) {
281+ const file_id : string = bot . update . business_message ?. photo ?. pop ( ) ?. file_id ?? '' ;
282+ const file_response = await bot . getFile ( file_id ) ;
283+ const blob = await file_response . arrayBuffer ( ) ;
284+ const prompt = bot . update . business_message ?. text ?. toString ( ) ?? bot . update . business_message ?. caption ?? '' ;
285+ if ( bot . update . business_message ?. from . id !== 69148518 ) {
282286 const { results } = await env . DB . prepare ( 'SELECT * FROM Messages WHERE userId=?' )
283287 . bind ( bot . update . business_message ?. from . id )
284288 . all ( ) ;
@@ -297,8 +301,14 @@ export default {
297301 ] ;
298302 let response : AiTextGenerationOutput ;
299303 try {
300- // @ts -expect-error broken bindings
301- response = await env . AI . run ( '@cf/meta/llama-3.2-11b-vision-instruct' , { messages } ) ;
304+ try {
305+ // @ts -expect-error broken bindings
306+ response = await env . AI . run ( '@cf/meta/llama-3.2-11b-vision-instruct' , { messages, image : [ ...new Uint8Array ( blob ) ] } ) ;
307+ } catch ( e ) {
308+ console . log ( e ) ;
309+ // @ts -expect-error broken bindings
310+ response = await env . AI . run ( '@cf/meta/llama-3.2-11b-vision-instruct' , { messages } ) ;
311+ }
302312 } catch ( e ) {
303313 console . log ( e ) ;
304314 await bot . reply ( `Error: ${ e as string } ` ) ;
0 commit comments