code: from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, cast
  
  import httpx
  from openai import AsyncOpenAI
  from openai import OpenAI as SyncOpenAI
  from openai.types.chat import ChatCompletionMessageParam
  from openai.types.chat.chat_completion_chunk import (
      ChatCompletionChunk,
      ChoiceDelta,
      ChoiceDeltaToolCall,
  )
  
  from llama_index.legacy.bridge.pydantic import Field, PrivateAttr
  from llama_index.legacy.callbacks import CallbackManager
  from llama_index.legacy.constants import (
      DEFAULT_CONTEXT_WINDOW,
      DEFAULT_NUM_OUTPUTS,
      DEFAULT_TEMPERATURE,
  )
  from llama_index.legacy.core.llms.types import (
      ChatMessage,
      ChatResponse,
      ChatResponseAsyncGen,
      ChatResponseGen,
      CompletionResponse,
      CompletionResponseAsyncGen,
      CompletionResponseGen,
      MessageRole,
  )
  from llama_index.legacy.llms.generic_utils import (
      messages_to_prompt as generic_messages_to_prompt,
  )
  from llama_index.legacy.llms.openai_utils import (
      from_openai_message,
      resolve_openai_credentials,
      to_openai_message_dicts,
  )
  from llama_index.legacy.multi_modal_llms import (
      MultiModalLLM,
      MultiModalLLMMetadata,
  )
  from llama_index.legacy.multi_modal_llms.openai_utils import (
      GPT4V_MODELS,
      generate_openai_multi_modal_chat_message,
  )
  from llama_index.legacy.schema import ImageDocument
  
  
  class OpenAIMultiModal(MultiModalLLM):
      model: str = Field(description="The Multi-Modal model to use from OpenAI.")
      temperature: float = Field(description="The temperature to use for sampling.")
      max_new_tokens: Optional[int] = Field(
          description=" The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt",
          gt=0,
      )
      context_window: Optional[int] = Field(
          description="The maximum number of context tokens for the model.",
          gt=0,
      )
      image_detail: str = Field(
          description="The level of details for image in API calls. Can be low, high, or auto"
      )
      max_retries: int = Field(
          default=3,
          description="Maximum number of retries.",
          gte=0,
      )
      timeout: float = Field(
          default=60.0,
          description="The timeout, in seconds, for API requests.",
          gte=0,
      )
      api_key: str = Field(default=None, description="The OpenAI API key.", exclude=True)
      api_base: str = Field(default=None, description="The base URL for OpenAI API.")
      api_version: str = Field(description="The API version for OpenAI API.")
      additional_kwargs: Dict[str, Any] = Field(
          default_factory=dict, description="Additional kwargs for the OpenAI API."
      )
      default_headers: Dict[str, str] = Field(
          default=None, description="The default headers for API requests."
      )
  
      _messages_to_prompt: Callable = PrivateAttr()
      _completion_to_prompt: Callable = PrivateAttr()
      _client: SyncOpenAI = PrivateAttr()
      _aclient: AsyncOpenAI = PrivateAttr()
      _http_client: Optional[httpx.Client] = PrivateAttr()
  
      def __init__(
          self,
          model: str = "gpt-4-vision-preview",
          temperature: float = DEFAULT_TEMPERATURE,
          max_new_tokens: Optional[int] = 300,
          additional_kwargs: Optional[Dict[str, Any]] = None,
          context_window: Optional[int] = DEFAULT_CONTEXT_WINDOW,
          max_retries: int = 3,
          timeout: float = 60.0,
          image_detail: str = "low",
          api_key: Optional[str] = None,
          api_base: Optional[str] = None,
          api_version: Optional[str] = None,
          messages_to_prompt: Optional[Callable] = None,
          completion_to_prompt: Optional[Callable] = None,
          callback_manager: Optional[CallbackManager] = None,
          default_headers: Optional[Dict[str, str]] = None,
          http_client: Optional[httpx.Client] = None,
          **kwargs: Any,
      ) -> None:
          self._messages_to_prompt = messages_to_prompt or generic_messages_to_prompt
          self._completion_to_prompt = completion_to_prompt or (lambda x: x)
          api_key, api_base, api_version = resolve_openai_credentials(
              api_key=api_key,
              api_base=api_base,
              api_version=api_version,
          )
  
          super().__init__(
              model=model,
              temperature=temperature,
              max_new_tokens=max_new_tokens,
              additional_kwargs=additional_kwargs or {},
              context_window=context_window,
              image_detail=image_detail,
              max_retries=max_retries,
              timeout=timeout,
              api_key=api_key,
              api_base=api_base,
              api_version=api_version,
              callback_manager=callback_manager,
              default_headers=default_headers,
              **kwargs,
          )
          self._http_client = http_client
          self._client, self._aclient = self._get_clients(**kwargs)
  
      def _get_clients(self, **kwargs: Any) -> Tuple[SyncOpenAI, AsyncOpenAI]:
          client = SyncOpenAI(**self._get_credential_kwargs())
          aclient = AsyncOpenAI(**self._get_credential_kwargs())
          return client, aclient
  
      @classmethod
      def class_name(cls) -> str:
          return "openai_multi_modal_llm"
  
      @property
      def metadata(self) -> MultiModalLLMMetadata:
          """Multi Modal LLM metadata."""
          return MultiModalLLMMetadata(
              num_output=self.max_new_tokens or DEFAULT_NUM_OUTPUTS,
              model_name=self.model,
          )
  
      def _get_credential_kwargs(self, **kwargs: Any) -> Dict[str, Any]:
          return {
              "api_key": self.api_key,
              "base_url": self.api_base,
              "max_retries": self.max_retries,
              "default_headers": self.default_headers,
              "http_client": self._http_client,
              "timeout": self.timeout,
              **kwargs,
          }
  
      def _get_multi_modal_chat_messages(
          self,
          prompt: str,
          role: str,
          image_documents: Sequence[ImageDocument],
          **kwargs: Any,
      ) -> List[ChatCompletionMessageParam]:
          return to_openai_message_dicts(
              [
                  generate_openai_multi_modal_chat_message(
                      prompt=prompt,
                      role=role,
                      image_documents=image_documents,
                      image_detail=self.image_detail,
                  )
              ]
          )
  
      # Model Params for OpenAI GPT4V model.
      def _get_model_kwargs(self, **kwargs: Any) -> Dict[str, Any]:
          if self.model not in GPT4V_MODELS:
              raise ValueError(
                  f"Invalid model {self.model}. "
                  f"Available models are: {list(GPT4V_MODELS.keys())}"
              )
          base_kwargs = {"model": self.model, "temperature": self.temperature, **kwargs}
          if self.max_new_tokens is not None:
              # If max_tokens is None, don't include in the payload:
              # https://platform.openai.com/docs/api-reference/chat
              # https://platform.openai.com/docs/api-reference/completions
              base_kwargs["max_tokens"] = self.max_new_tokens
          return {**base_kwargs, **self.additional_kwargs}
  
      def _get_response_token_counts(self, raw_response: Any) -> dict:
          """Get the token usage reported by the response."""
          if not isinstance(raw_response, dict):
              return {}
  
          usage = raw_response.get("usage", {})
          # NOTE: other model providers that use the OpenAI client may not report usage
          if usage is None:
              return {}
  
          return {
              "prompt_tokens": usage.get("prompt_tokens", 0),
              "completion_tokens": usage.get("completion_tokens", 0),
              "total_tokens": usage.get("total_tokens", 0),
          }
  
      def _complete(
          self, prompt: str, image_documents: Sequence[ImageDocument], **kwargs: Any
      ) -> CompletionResponse:
          all_kwargs = self._get_model_kwargs(**kwargs)
          message_dict = self._get_multi_modal_chat_messages(
              prompt=prompt, role=MessageRole.USER, image_documents=image_documents
          )
          response = self._client.chat.completions.create(
              messages=message_dict,
              stream=False,
              **all_kwargs,
          )
  
          return CompletionResponse(
              text=response.choices[0].message.content,
              raw=response,
              additional_kwargs=self._get_response_token_counts(response),
          )
  
      def _chat(self, messages: Sequence[ChatMessage], **kwargs: Any) -> ChatResponse:
          all_kwargs = self._get_model_kwargs(**kwargs)
          message_dicts = to_openai_message_dicts(messages)
          response = self._client.chat.completions.create(
              messages=message_dicts,
              stream=False,
              **all_kwargs,
          )
          openai_message = response.choices[0].message
          message = from_openai_message(openai_message)
  
          return ChatResponse(
              message=message,
              raw=response,
              additional_kwargs=self._get_response_token_counts(response),
          )
  
      def _stream_complete(
          self, prompt: str, image_documents: Sequence[ImageDocument], **kwargs: Any
      ) -> CompletionResponseGen:
          all_kwargs = self._get_model_kwargs(**kwargs)
          message_dict = self._get_multi_modal_chat_messages(
              prompt=prompt, role=MessageRole.USER, image_documents=image_documents
          )
  
          def gen() -> CompletionResponseGen:
              text = ""
  
              for response in self._client.chat.completions.create(
                  messages=message_dict,
                  stream=True,
                  **all_kwargs,
              ):
                  response = cast(ChatCompletionChunk, response)
                  if len(response.choices) > 0:
                      delta = response.choices[0].delta
                  else:
                      delta = ChoiceDelta()
  
                  # update using deltas
                  content_delta = delta.content or ""
                  text += content_delta
  
                  yield CompletionResponse(
                      delta=content_delta,
                      text=text,
                      raw=response,
                      additional_kwargs=self._get_response_token_counts(response),
                  )
  
          return gen()
  
      def _stream_chat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponseGen:
          message_dicts = to_openai_message_dicts(messages)
  
          def gen() -> ChatResponseGen:
              content = ""
              tool_calls: List[ChoiceDeltaToolCall] = []
  
              is_function = False
              for response in self._client.chat.completions.create(
                  messages=message_dicts,
                  stream=True,
                  **self._get_model_kwargs(**kwargs),
              ):
                  response = cast(ChatCompletionChunk, response)
                  if len(response.choices) > 0:
                      delta = response.choices[0].delta
                  else:
                      delta = ChoiceDelta()
  
                  # check if this chunk is the start of a function call
                  if delta.tool_calls:
                      is_function = True
  
                  # update using deltas
                  role = delta.role or MessageRole.ASSISTANT
                  content_delta = delta.content or ""
                  content += content_delta
  
                  additional_kwargs = {}
                  if is_function:
                      tool_calls = self._update_tool_calls(tool_calls, delta.tool_calls)
                      additional_kwargs["tool_calls"] = tool_calls
  
                  yield ChatResponse(
                      message=ChatMessage(
                          role=role,
                          content=content,
                          additional_kwargs=additional_kwargs,
                      ),
                      delta=content_delta,
                      raw=response,
                      additional_kwargs=self._get_response_token_counts(response),
                  )
  
          return gen()
  
      def complete(
          self, prompt: str, image_documents: Sequence[ImageDocument], **kwargs: Any
      ) -> CompletionResponse:
          return self._complete(prompt, image_documents, **kwargs)
  
      def stream_complete(
          self, prompt: str, image_documents: Sequence[ImageDocument], **kwargs: Any
      ) -> CompletionResponseGen:
          return self._stream_complete(prompt, image_documents, **kwargs)
  
      def chat(
          self,
          messages: Sequence[ChatMessage],
          **kwargs: Any,
      ) -> ChatResponse:
          return self._chat(messages, **kwargs)
  
      def stream_chat(
          self,
          messages: Sequence[ChatMessage],
          **kwargs: Any,
      ) -> ChatResponseGen:
          return self._stream_chat(messages, **kwargs)
  
      # ===== Async Endpoints =====
  
      async def _acomplete(
          self, prompt: str, image_documents: Sequence[ImageDocument], **kwargs: Any
      ) -> CompletionResponse:
          all_kwargs = self._get_model_kwargs(**kwargs)
          message_dict = self._get_multi_modal_chat_messages(
              prompt=prompt, role=MessageRole.USER, image_documents=image_documents
          )
          response = await self._aclient.chat.completions.create(
              messages=message_dict,
              stream=False,
              **all_kwargs,
          )
  
          return CompletionResponse(
              text=response.choices[0].message.content,
              raw=response,
              additional_kwargs=self._get_response_token_counts(response),
          )
  
      async def acomplete(
          self, prompt: str, image_documents: Sequence[ImageDocument], **kwargs: Any
      ) -> CompletionResponse:
          return await self._acomplete(prompt, image_documents, **kwargs)
  
      async def _astream_complete(
          self, prompt: str, image_documents: Sequence[ImageDocument], **kwargs: Any
      ) -> CompletionResponseAsyncGen:
          all_kwargs = self._get_model_kwargs(**kwargs)
          message_dict = self._get_multi_modal_chat_messages(
              prompt=prompt, role=MessageRole.USER, image_documents=image_documents
          )
  
          async def gen() -> CompletionResponseAsyncGen:
              text = ""
  
              async for response in await self._aclient.chat.completions.create(
                  messages=message_dict,
                  stream=True,
                  **all_kwargs,
              ):
                  response = cast(ChatCompletionChunk, response)
                  if len(response.choices) > 0:
                      delta = response.choices[0].delta
                  else:
                      delta = ChoiceDelta()
  
                  # update using deltas
                  content_delta = delta.content or ""
                  text += content_delta
  
                  yield CompletionResponse(
                      delta=content_delta,
                      text=text,
                      raw=response,
                      additional_kwargs=self._get_response_token_counts(response),
                  )
  
          return gen()
  
      async def _achat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponse:
          all_kwargs = self._get_model_kwargs(**kwargs)
          message_dicts = to_openai_message_dicts(messages)
          response = await self._aclient.chat.completions.create(
              messages=message_dicts,
              stream=False,
              **all_kwargs,
          )
          openai_message = response.choices[0].message
          message = from_openai_message(openai_message)
  
          return ChatResponse(
              message=message,
              raw=response,
              additional_kwargs=self._get_response_token_counts(response),
          )
  
      async def _astream_chat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponseAsyncGen:
          message_dicts = to_openai_message_dicts(messages)
  
          async def gen() -> ChatResponseAsyncGen:
              content = ""
              tool_calls: List[ChoiceDeltaToolCall] = []
  
              is_function = False
              async for response in await self._aclient.chat.completions.create(
                  messages=message_dicts,
                  stream=True,
                  **self._get_model_kwargs(**kwargs),
              ):
                  response = cast(ChatCompletionChunk, response)
                  if len(response.choices) > 0:
                      delta = response.choices[0].delta
                  else:
                      delta = ChoiceDelta()
  
                  # check if this chunk is the start of a function call
                  if delta.tool_calls:
                      is_function = True
  
                  # update using deltas
                  role = delta.role or MessageRole.ASSISTANT
                  content_delta = delta.content or ""
                  content += content_delta
  
                  additional_kwargs = {}
                  if is_function:
                      tool_calls = self._update_tool_calls(tool_calls, delta.tool_calls)
                      additional_kwargs["tool_calls"] = tool_calls
  
                  yield ChatResponse(
                      message=ChatMessage(
                          role=role,
                          content=content,
                          additional_kwargs=additional_kwargs,
                      ),
                      delta=content_delta,
                      raw=response,
                      additional_kwargs=self._get_response_token_counts(response),
                  )
  
          return gen()
  
      async def astream_complete(
          self, prompt: str, image_documents: Sequence[ImageDocument], **kwargs: Any
      ) -> CompletionResponseAsyncGen:
          return await self._astream_complete(prompt, image_documents, **kwargs)
  
      async def achat(
          self,
          messages: Sequence[ChatMessage],
          **kwargs: Any,
      ) -> ChatResponse:
          return await self._achat(messages, **kwargs)
  
      async def astream_chat(
          self,
          messages: Sequence[ChatMessage],
          **kwargs: Any,
      ) -> ChatResponseAsyncGen:
          return await self._astream_chat(messages, **kwargs)
  
apis: llama_index.legacy.llms.openai_utils.from_openai_message llama_index.legacy.multi_modal_llms.MultiModalLLMMetadata llama_index.legacy.multi_modal_llms.openai_utils.generate_openai_multi_modal_chat_message llama_index.legacy.bridge.pydantic.Field llama_index.legacy.core.llms.types.ChatMessage llama_index.legacy.bridge.pydantic.PrivateAttr llama_index.legacy.llms.openai_utils.to_openai_message_dicts llama_index.legacy.multi_modal_llms.openai_utils.GPT4V_MODELS.keys llama_index.legacy.llms.openai_utils.resolve_openai_credentials
extract_api: [((1407, 1469), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'description': '"""The Multi-Modal model to use from OpenAI."""'}), "(description='The Multi-Modal model to use from OpenAI.')\n", (1412, 1469), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((1495, 1552), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'description': '"""The temperature to use for sampling."""'}), "(description='The temperature to use for sampling.')\n", (1500, 1552), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((1589, 1713), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'description': '""" The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt"""', 'gt': '(0)'}), "(description=\n    ' The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt'\n    , gt=0)\n", (1594, 1713), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((1763, 1841), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'description': '"""The maximum number of context tokens for the model."""', 'gt': '(0)'}), "(description='The maximum number of context tokens for the model.', gt=0)\n", (1768, 1841), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((1889, 1985), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'description': '"""The level of details for image in API calls. Can be low, high, or auto"""'}), "(description=\n    'The level of details for image in API calls. Can be low, high, or auto')\n", (1894, 1985), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2018, 2083), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default': '(3)', 'description': '"""Maximum number of retries."""', 'gte': '(0)'}), "(default=3, description='Maximum number of retries.', gte=0)\n", (2023, 2083), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2136, 2225), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default': '(60.0)', 'description': '"""The timeout, in seconds, for API requests."""', 'gte': '(0)'}), "(default=60.0, description=\n    'The timeout, in seconds, for API requests.', gte=0)\n", (2141, 2225), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2271, 2339), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default': 'None', 'description': '"""The OpenAI API key."""', 'exclude': '(True)'}), "(default=None, description='The OpenAI API key.', exclude=True)\n", (2276, 2339), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2360, 2423), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default': 'None', 'description': '"""The base URL for OpenAI API."""'}), "(default=None, description='The base URL for OpenAI API.')\n", (2365, 2423), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2447, 2499), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'description': '"""The API version for OpenAI API."""'}), "(description='The API version for OpenAI API.')\n", (2452, 2499), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2540, 2625), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default_factory': 'dict', 'description': '"""Additional kwargs for the OpenAI API."""'}), "(default_factory=dict, description='Additional kwargs for the OpenAI API.'\n    )\n", (2545, 2625), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2673, 2745), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default': 'None', 'description': '"""The default headers for API requests."""'}), "(default=None, description='The default headers for API requests.')\n", (2678, 2745), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2797, 2810), 'llama_index.legacy.bridge.pydantic.PrivateAttr', 'PrivateAttr', ([], {}), '()\n', (2808, 2810), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2849, 2862), 'llama_index.legacy.bridge.pydantic.PrivateAttr', 'PrivateAttr', ([], {}), '()\n', (2860, 2862), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2889, 2902), 'llama_index.legacy.bridge.pydantic.PrivateAttr', 'PrivateAttr', ([], {}), '()\n', (2900, 2902), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2931, 2944), 'llama_index.legacy.bridge.pydantic.PrivateAttr', 'PrivateAttr', ([], {}), '()\n', (2942, 2944), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((2988, 3001), 'llama_index.legacy.bridge.pydantic.PrivateAttr', 'PrivateAttr', ([], {}), '()\n', (2999, 3001), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((4037, 4129), 'llama_index.legacy.llms.openai_utils.resolve_openai_credentials', 'resolve_openai_credentials', ([], {'api_key': 'api_key', 'api_base': 'api_base', 'api_version': 'api_version'}), '(api_key=api_key, api_base=api_base, api_version=\n    api_version)\n', (4063, 4129), False, 'from llama_index.legacy.llms.openai_utils import from_openai_message, resolve_openai_credentials, to_openai_message_dicts\n'), ((5276, 5379), 'llama_index.legacy.multi_modal_llms.MultiModalLLMMetadata', 'MultiModalLLMMetadata', ([], {'num_output': '(self.max_new_tokens or DEFAULT_NUM_OUTPUTS)', 'model_name': 'self.model'}), '(num_output=self.max_new_tokens or DEFAULT_NUM_OUTPUTS,\n    model_name=self.model)\n', (5297, 5379), False, 'from llama_index.legacy.multi_modal_llms import MultiModalLLM, MultiModalLLMMetadata\n'), ((8542, 8575), 'llama_index.legacy.llms.openai_utils.to_openai_message_dicts', 'to_openai_message_dicts', (['messages'], {}), '(messages)\n', (8565, 8575), False, 'from llama_index.legacy.llms.openai_utils import from_openai_message, resolve_openai_credentials, to_openai_message_dicts\n'), ((8802, 8837), 'llama_index.legacy.llms.openai_utils.from_openai_message', 'from_openai_message', (['openai_message'], {}), '(openai_message)\n', (8821, 8837), False, 'from llama_index.legacy.llms.openai_utils import from_openai_message, resolve_openai_credentials, to_openai_message_dicts\n'), ((10361, 10394), 'llama_index.legacy.llms.openai_utils.to_openai_message_dicts', 'to_openai_message_dicts', (['messages'], {}), '(messages)\n', (10384, 10394), False, 'from llama_index.legacy.llms.openai_utils import from_openai_message, resolve_openai_credentials, to_openai_message_dicts\n'), ((15114, 15147), 'llama_index.legacy.llms.openai_utils.to_openai_message_dicts', 'to_openai_message_dicts', (['messages'], {}), '(messages)\n', (15137, 15147), False, 'from llama_index.legacy.llms.openai_utils import from_openai_message, resolve_openai_credentials, to_openai_message_dicts\n'), ((15381, 15416), 'llama_index.legacy.llms.openai_utils.from_openai_message', 'from_openai_message', (['openai_message'], {}), '(openai_message)\n', (15400, 15416), False, 'from llama_index.legacy.llms.openai_utils import from_openai_message, resolve_openai_credentials, to_openai_message_dicts\n'), ((15731, 15764), 'llama_index.legacy.llms.openai_utils.to_openai_message_dicts', 'to_openai_message_dicts', (['messages'], {}), '(messages)\n', (15754, 15764), False, 'from llama_index.legacy.llms.openai_utils import from_openai_message, resolve_openai_credentials, to_openai_message_dicts\n'), ((6070, 6205), 'llama_index.legacy.multi_modal_llms.openai_utils.generate_openai_multi_modal_chat_message', 'generate_openai_multi_modal_chat_message', ([], {'prompt': 'prompt', 'role': 'role', 'image_documents': 'image_documents', 'image_detail': 'self.image_detail'}), '(prompt=prompt, role=role,\n    image_documents=image_documents, image_detail=self.image_detail)\n', (6110, 6205), False, 'from llama_index.legacy.multi_modal_llms.openai_utils import GPT4V_MODELS, generate_openai_multi_modal_chat_message\n'), ((9628, 9663), 'typing.cast', 'cast', (['ChatCompletionChunk', 'response'], {}), '(ChatCompletionChunk, response)\n', (9632, 9663), False, 'from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, cast\n'), ((10776, 10811), 'typing.cast', 'cast', (['ChatCompletionChunk', 'response'], {}), '(ChatCompletionChunk, response)\n', (10780, 10811), False, 'from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, cast\n'), ((14330, 14365), 'typing.cast', 'cast', (['ChatCompletionChunk', 'response'], {}), '(ChatCompletionChunk, response)\n', (14334, 14365), False, 'from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, cast\n'), ((16170, 16205), 'typing.cast', 'cast', (['ChatCompletionChunk', 'response'], {}), '(ChatCompletionChunk, response)\n', (16174, 16205), False, 'from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, cast\n'), ((9814, 9827), 'openai.types.chat.chat_completion_chunk.ChoiceDelta', 'ChoiceDelta', ([], {}), '()\n', (9825, 9827), False, 'from openai.types.chat.chat_completion_chunk import ChatCompletionChunk, ChoiceDelta, ChoiceDeltaToolCall\n'), ((10962, 10975), 'openai.types.chat.chat_completion_chunk.ChoiceDelta', 'ChoiceDelta', ([], {}), '()\n', (10973, 10975), False, 'from openai.types.chat.chat_completion_chunk import ChatCompletionChunk, ChoiceDelta, ChoiceDeltaToolCall\n'), ((14516, 14529), 'openai.types.chat.chat_completion_chunk.ChoiceDelta', 'ChoiceDelta', ([], {}), '()\n', (14527, 14529), False, 'from openai.types.chat.chat_completion_chunk import ChatCompletionChunk, ChoiceDelta, ChoiceDeltaToolCall\n'), ((16356, 16369), 'openai.types.chat.chat_completion_chunk.ChoiceDelta', 'ChoiceDelta', ([], {}), '()\n', (16367, 16369), False, 'from openai.types.chat.chat_completion_chunk import ChatCompletionChunk, ChoiceDelta, ChoiceDeltaToolCall\n'), ((6602, 6621), 'llama_index.legacy.multi_modal_llms.openai_utils.GPT4V_MODELS.keys', 'GPT4V_MODELS.keys', ([], {}), '()\n', (6619, 6621), False, 'from llama_index.legacy.multi_modal_llms.openai_utils import GPT4V_MODELS, generate_openai_multi_modal_chat_message\n'), ((11603, 11679), 'llama_index.legacy.core.llms.types.ChatMessage', 'ChatMessage', ([], {'role': 'role', 'content': 'content', 'additional_kwargs': 'additional_kwargs'}), '(role=role, content=content, additional_kwargs=additional_kwargs)\n', (11614, 11679), False, 'from llama_index.legacy.core.llms.types import ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole\n'), ((16997, 17073), 'llama_index.legacy.core.llms.types.ChatMessage', 'ChatMessage', ([], {'role': 'role', 'content': 'content', 'additional_kwargs': 'additional_kwargs'}), '(role=role, content=content, additional_kwargs=additional_kwargs)\n', (17008, 17073), False, 'from llama_index.legacy.core.llms.types import ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, MessageRole\n')]