@@ -69,12 +69,21 @@ def __call__(
69
69
openai_create_prompt : OpenAICreatePrompt = prompt .to_formatted_prompt ()
70
70
71
71
if "file_name" in kwargs :
72
- attached_file_content = ["The file is as follows:" ]
73
- attached_file_content += extract_text_and_fill_in_images (kwargs ["file_name" ], None , False ) \
74
- if self .model == "gemini-pro-vision" else ["" .join (extract_text (kwargs ["file_name" ]))]
75
72
max_tokens = model_max_tokens .get (self .model , 1000000 )
76
- while num_tokens_from_string (attached_file_content [1 ], "cl100k_base" ) > max_tokens :
77
- attached_file_content [1 ] = attached_file_content [1 ][:- 1000 ]
73
+ attached_file_content = ["The file is as follows:" ]
74
+
75
+ if self .model == "gemini-pro-vision" :
76
+ attached_file_content += extract_text_and_fill_in_images (kwargs ["file_name" ], None , False )
77
+ content_types = [type (c ) for c in attached_file_content ]
78
+ if not dict in content_types :
79
+ print (f"WARNING: pdf { kwargs ['file_name' ]} has no image!" )
80
+ self .model = "gemini-pro"
81
+ attached_file_content = ["The file is as follows:" ] + ["" .join (extract_text (kwargs ["file_name" ]))]
82
+ else :
83
+ attached_file_content += ["" .join (extract_text (kwargs ["file_name" ]))]
84
+ if self .model == "gemini-pro" :
85
+ while num_tokens_from_string (attached_file_content [1 ], "cl100k_base" ) > max_tokens :
86
+ attached_file_content [1 ] = attached_file_content [1 ][:- 1000 ]
78
87
else :
79
88
attached_file_content = []
80
89
self .model = "gemini-pro"
0 commit comments