File tree Expand file tree Collapse file tree 3 files changed +44
-15
lines changed
Expand file tree Collapse file tree 3 files changed +44
-15
lines changed Original file line number Diff line number Diff line change @@ -96,27 +96,54 @@ async def process_page(
9696 image_data = buf .read ()
9797 image_base64 = base64 .b64encode (image_data ).decode ("utf-8" )
9898
99+ model = self .config .vision_pdf_model or self .config .app .vlm
100+
99101 # Configure generation parameters
100102 generation_config = GenerationConfig (
101103 model = self .config .vision_pdf_model or self .config .app .vlm ,
102104 stream = False ,
103105 )
104106
107+ is_anthropic = model and "anthropic/" in model
108+
109+ # FIXME: This is a hacky fix to handle the different formats
110+ # that was causing an outage. This logic really needs to be refactored
111+ # and cleaned up such that it handles providers more robustly.
112+
105113 # Prepare message with image content
106- messages = [
107- {
108- "role" : "user" ,
109- "content" : [
110- {"type" : "text" , "text" : self .vision_prompt_text },
111- {
112- "type" : "image_url" ,
113- "image_url" : {
114- "url" : f"data:image/jpeg;base64,{ image_base64 } "
114+ if is_anthropic :
115+ messages = [
116+ {
117+ "role" : "user" ,
118+ "content" : [
119+ {"type" : "text" , "text" : self .vision_prompt_text },
120+ {
121+ "type" : "image" ,
122+ "source" : {
123+ "type" : "base64" ,
124+ "media_type" : "image/jpeg" ,
125+ "data" : image_base64 ,
126+ },
115127 },
116- },
117- ],
118- }
119- ]
128+ ],
129+ }
130+ ]
131+ else :
132+ # Use OpenAI format
133+ messages = [
134+ {
135+ "role" : "user" ,
136+ "content" : [
137+ {"type" : "text" , "text" : self .vision_prompt_text },
138+ {
139+ "type" : "image_url" ,
140+ "image_url" : {
141+ "url" : f"data:image/jpeg;base64,{ image_base64 } "
142+ },
143+ },
144+ ],
145+ }
146+ ]
120147
121148 logger .debug (f"Sending page { page_num } to vision model." )
122149 req_start = time .perf_counter ()
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44
55[project ]
66name = " r2r"
7- version = " 3.5.0 "
7+ version = " 3.5.1 "
88description = " SciPhi R2R"
99readme = " README.md"
1010license = {text = " MIT" }
Original file line number Diff line number Diff line change @@ -33,7 +33,9 @@ async def create_app(
3333 config_path = config_path or os .getenv ("R2R_CONFIG_PATH" )
3434
3535 if config_path and config_name :
36- raise ValueError ("Cannot specify both config_path and config_name" )
36+ raise ValueError (
37+ f"Cannot specify both config_path and config_name, got { config_path } and { config_name } "
38+ )
3739
3840 if not config_path and not config_name :
3941 # If neither is specified nor set in environment,
You can’t perform that action at this time.
0 commit comments