(category: str, data_info: Dict[str, str], image_path: str,
generation_prompt: str, model_name: str)
| 236 | |
| 237 | |
| 238 | def create_generation_request(category: str, data_info: Dict[str, str], image_path: str, |
| 239 | generation_prompt: str, model_name: str) -> Dict: |
| 240 | |
| 241 | text_prompt = create_user_prompt(category, data_info) |
| 242 | image_base64 = encode_image_to_base64(image_path) |
| 243 | user_content = [ |
| 244 | { |
| 245 | "type": "text", |
| 246 | "text": f'{text_prompt}. Note that in this environment, the version of matplotlib is {matplotlib.__version__}, the version of seaborn is {seaborn.__version__}, the version of plotly is {plotly.__version__}, the version of bokeh is {bokeh.__version__}, the version of altair is {altair.__version__}.' |
| 247 | # "text": text_prompt |
| 248 | }, |
| 249 | { |
| 250 | "type": "image_url", |
| 251 | "image_url": { |
| 252 | "url": image_base64 |
| 253 | } |
| 254 | } |
| 255 | ] |
| 256 | |
| 257 | return { |
| 258 | "model": model_name, |
| 259 | "messages": [ |
| 260 | {"role": "system", "content": generation_prompt}, |
| 261 | {"role": "user", "content": user_content} |
| 262 | ], |
| 263 | "max_tokens": 32768, |
| 264 | "temperature": 0.0, |
| 265 | "timeout": 1200 |
| 266 | } |
| 267 | |
| 268 | |
| 269 | def extract_python_code(response: str) -> str: |
no test coverage detected