classOpenAIMultiModal(OpenAI):@classmethoddefclass_name(cls)->str:return"openai_multi_modal_llm"def_get_multi_modal_chat_message(self,prompt:str,role:str,image_documents:Sequence[ImageNode],image_detail:Optional[str]="low",**kwargs:Any,)->ChatMessage:chat_msg=ChatMessage(role=role,content=prompt)ifnotimage_documents:# if image_documents is empty, return text only chat messagereturnchat_msgforimage_documentinimage_documents:# Create the appropriate ContentBlock depending on the document contentifimage_document.image:chat_msg.blocks.append(ImageBlock(image=bytes(image_document.image,encoding="utf-8"),detail=image_detail,))elifimage_document.image_url:chat_msg.blocks.append(ImageBlock(url=image_document.image_url,detail=image_detail))elifimage_document.image_path:chat_msg.blocks.append(ImageBlock(path=Path(image_document.image_path),detail=image_detail,image_mimetype=image_document.image_mimetypeorimage_document.metadata.get("file_type"),))eliff_path:=image_document.metadata.get("file_path"):chat_msg.blocks.append(ImageBlock(path=Path(f_path),detail=image_detail,image_mimetype=image_document.metadata.get("file_type"),))returnchat_msgdefcomplete(self,prompt:str,image_documents:Sequence[ImageNode],**kwargs:Any)->CompletionResponse:chat_message=self._get_multi_modal_chat_message(prompt=prompt,role=MessageRole.USER,image_documents=image_documents,)chat_response=self.chat([chat_message],**kwargs)returnchat_response_to_completion_response(chat_response)defstream_complete(self,prompt:str,image_documents:Sequence[ImageNode],**kwargs:Any)->CompletionResponseGen:chat_message=self._get_multi_modal_chat_message(prompt=prompt,role=MessageRole.USER,image_documents=image_documents,)chat_response=self.stream_chat([chat_message],**kwargs)returnstream_chat_response_to_completion_response(chat_response)# ===== Async Endpoints =====asyncdefacomplete(self,prompt:str,image_documents:Sequence[ImageNode],**kwargs:Any)->CompletionResponse:chat_message=self._get_multi_modal_chat_message(prompt=prompt,role=MessageRole.USER,image_documents=image_documents,)chat_response=awaitself.achat([chat_message],**kwargs)returnchat_response_to_completion_response(chat_response)asyncdefastream_complete(self,prompt:str,image_documents:Sequence[ImageNode],**kwargs:Any)->CompletionResponseAsyncGen:chat_message=self._get_multi_modal_chat_message(prompt=prompt,role=MessageRole.USER,image_documents=image_documents,)chat_response=awaitself.astream_chat([chat_message],**kwargs)returnastream_chat_response_to_completion_response(chat_response)