code: from typing import Any, Awaitable, Callable, Dict, Optional, Sequence
  
  from llama_index.legacy.bridge.pydantic import Field
  from llama_index.legacy.callbacks import CallbackManager
  from llama_index.legacy.constants import DEFAULT_TEMPERATURE
  from llama_index.legacy.core.llms.types import (
      ChatMessage,
      ChatResponse,
      ChatResponseAsyncGen,
      ChatResponseGen,
      CompletionResponse,
      CompletionResponseAsyncGen,
      CompletionResponseGen,
      LLMMetadata,
  )
  from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback
  from llama_index.legacy.llms.generic_utils import (
      achat_to_completion_decorator,
      acompletion_to_chat_decorator,
      astream_chat_to_completion_decorator,
      astream_completion_to_chat_decorator,
      chat_to_completion_decorator,
      completion_to_chat_decorator,
      stream_chat_to_completion_decorator,
      stream_completion_to_chat_decorator,
  )
  from llama_index.legacy.llms.litellm_utils import (
      acompletion_with_retry,
      completion_with_retry,
      from_litellm_message,
      is_function_calling_model,
      openai_modelname_to_contextsize,
      to_openai_message_dicts,
      validate_litellm_api_key,
  )
  from llama_index.legacy.llms.llm import LLM
  from llama_index.legacy.types import BaseOutputParser, PydanticProgramMode
  
  DEFAULT_LITELLM_MODEL = "gpt-3.5-turbo"
  
  
  class LiteLLM(LLM):
      model: str = Field(
          default=DEFAULT_LITELLM_MODEL,
          description=(
              "The LiteLLM model to use. "
              "For complete list of providers https://docs.litellm.ai/docs/providers"
          ),
      )
      temperature: float = Field(
          default=DEFAULT_TEMPERATURE,
          description="The temperature to use during generation.",
          gte=0.0,
          lte=1.0,
      )
      max_tokens: Optional[int] = Field(
          description="The maximum number of tokens to generate.",
          gt=0,
      )
      additional_kwargs: Dict[str, Any] = Field(
          default_factory=dict,
          description="Additional kwargs for the LLM API.",
          # for all inputs https://docs.litellm.ai/docs/completion/input
      )
      max_retries: int = Field(
          default=10, description="The maximum number of API retries."
      )
  
      def __init__(
          self,
          model: str = DEFAULT_LITELLM_MODEL,
          temperature: float = DEFAULT_TEMPERATURE,
          max_tokens: Optional[int] = None,
          additional_kwargs: Optional[Dict[str, Any]] = None,
          max_retries: int = 10,
          api_key: Optional[str] = None,
          api_type: Optional[str] = None,
          api_base: Optional[str] = None,
          callback_manager: Optional[CallbackManager] = None,
          system_prompt: Optional[str] = None,
          messages_to_prompt: Optional[Callable[[Sequence[ChatMessage]], str]] = None,
          completion_to_prompt: Optional[Callable[[str], str]] = None,
          pydantic_program_mode: PydanticProgramMode = PydanticProgramMode.DEFAULT,
          output_parser: Optional[BaseOutputParser] = None,
          **kwargs: Any,
      ) -> None:
          if "custom_llm_provider" in kwargs:
              if (
                  kwargs["custom_llm_provider"] != "ollama"
                  and kwargs["custom_llm_provider"] != "vllm"
              ):  # don't check keys for local models
                  validate_litellm_api_key(api_key, api_type)
          else:  # by default assume it's a hosted endpoint
              validate_litellm_api_key(api_key, api_type)
  
          additional_kwargs = additional_kwargs or {}
          if api_key is not None:
              additional_kwargs["api_key"] = api_key
          if api_type is not None:
              additional_kwargs["api_type"] = api_type
          if api_base is not None:
              additional_kwargs["api_base"] = api_base
  
          super().__init__(
              model=model,
              temperature=temperature,
              max_tokens=max_tokens,
              additional_kwargs=additional_kwargs,
              max_retries=max_retries,
              callback_manager=callback_manager,
              system_prompt=system_prompt,
              messages_to_prompt=messages_to_prompt,
              completion_to_prompt=completion_to_prompt,
              pydantic_program_mode=pydantic_program_mode,
              output_parser=output_parser,
              **kwargs,
          )
  
      def _get_model_name(self) -> str:
          model_name = self.model
          if "ft-" in model_name:  # legacy fine-tuning
              model_name = model_name.split(":")[0]
          elif model_name.startswith("ft:"):
              model_name = model_name.split(":")[1]
  
          return model_name
  
      @classmethod
      def class_name(cls) -> str:
          return "litellm_llm"
  
      @property
      def metadata(self) -> LLMMetadata:
          return LLMMetadata(
              context_window=openai_modelname_to_contextsize(self._get_model_name()),
              num_output=self.max_tokens or -1,
              is_chat_model=True,
              is_function_calling_model=is_function_calling_model(self._get_model_name()),
              model_name=self.model,
          )
  
      @llm_chat_callback()
      def chat(self, messages: Sequence[ChatMessage], **kwargs: Any) -> ChatResponse:
          if self._is_chat_model:
              chat_fn = self._chat
          else:
              chat_fn = completion_to_chat_decorator(self._complete)
          return chat_fn(messages, **kwargs)
  
      @llm_chat_callback()
      def stream_chat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponseGen:
          if self._is_chat_model:
              stream_chat_fn = self._stream_chat
          else:
              stream_chat_fn = stream_completion_to_chat_decorator(self._stream_complete)
          return stream_chat_fn(messages, **kwargs)
  
      @llm_completion_callback()
      def complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponse:
          # litellm assumes all llms are chat llms
          if self._is_chat_model:
              complete_fn = chat_to_completion_decorator(self._chat)
          else:
              complete_fn = self._complete
  
          return complete_fn(prompt, **kwargs)
  
      @llm_completion_callback()
      def stream_complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponseGen:
          if self._is_chat_model:
              stream_complete_fn = stream_chat_to_completion_decorator(self._stream_chat)
          else:
              stream_complete_fn = self._stream_complete
          return stream_complete_fn(prompt, **kwargs)
  
      @property
      def _is_chat_model(self) -> bool:
          # litellm assumes all llms are chat llms
          return True
  
      @property
      def _model_kwargs(self) -> Dict[str, Any]:
          base_kwargs = {
              "model": self.model,
              "temperature": self.temperature,
              "max_tokens": self.max_tokens,
          }
          return {
              **base_kwargs,
              **self.additional_kwargs,
          }
  
      def _get_all_kwargs(self, **kwargs: Any) -> Dict[str, Any]:
          return {
              **self._model_kwargs,
              **kwargs,
          }
  
      def _chat(self, messages: Sequence[ChatMessage], **kwargs: Any) -> ChatResponse:
          if not self._is_chat_model:
              raise ValueError("This model is not a chat model.")
  
          message_dicts = to_openai_message_dicts(messages)
          all_kwargs = self._get_all_kwargs(**kwargs)
          if "max_tokens" in all_kwargs and all_kwargs["max_tokens"] is None:
              all_kwargs.pop(
                  "max_tokens"
              )  # don't send max_tokens == None, this throws errors for Non OpenAI providers
  
          response = completion_with_retry(
              is_chat_model=self._is_chat_model,
              max_retries=self.max_retries,
              messages=message_dicts,
              stream=False,
              **all_kwargs,
          )
          message_dict = response["choices"][0]["message"]
          message = from_litellm_message(message_dict)
  
          return ChatResponse(
              message=message,
              raw=response,
              additional_kwargs=self._get_response_token_counts(response),
          )
  
      def _stream_chat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponseGen:
          if not self._is_chat_model:
              raise ValueError("This model is not a chat model.")
  
          message_dicts = to_openai_message_dicts(messages)
          all_kwargs = self._get_all_kwargs(**kwargs)
          if "max_tokens" in all_kwargs and all_kwargs["max_tokens"] is None:
              all_kwargs.pop(
                  "max_tokens"
              )  # don't send max_tokens == None, this throws errors for Non OpenAI providers
  
          def gen() -> ChatResponseGen:
              content = ""
              function_call: Optional[dict] = None
              for response in completion_with_retry(
                  is_chat_model=self._is_chat_model,
                  max_retries=self.max_retries,
                  messages=message_dicts,
                  stream=True,
                  **all_kwargs,
              ):
                  delta = response["choices"][0]["delta"]
                  role = delta.get("role", "assistant")
                  content_delta = delta.get("content", "") or ""
                  content += content_delta
  
                  function_call_delta = delta.get("function_call", None)
                  if function_call_delta is not None:
                      if function_call is None:
                          function_call = function_call_delta
  
                          ## ensure we do not add a blank function call
                          if function_call.get("function_name", "") is None:
                              del function_call["function_name"]
                      else:
                          function_call["arguments"] += function_call_delta["arguments"]
  
                  additional_kwargs = {}
                  if function_call is not None:
                      additional_kwargs["function_call"] = function_call
  
                  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, **kwargs: Any) -> CompletionResponse:
          raise NotImplementedError("litellm assumes all llms are chat llms.")
  
      def _stream_complete(self, prompt: str, **kwargs: Any) -> CompletionResponseGen:
          raise NotImplementedError("litellm assumes all llms are chat llms.")
  
      def _get_max_token_for_prompt(self, prompt: str) -> int:
          try:
              import tiktoken
          except ImportError:
              raise ImportError(
                  "Please install tiktoken to use the max_tokens=None feature."
              )
          context_window = self.metadata.context_window
          try:
              encoding = tiktoken.encoding_for_model(self._get_model_name())
          except KeyError:
              encoding = encoding = tiktoken.get_encoding(
                  "cl100k_base"
              )  # default to using cl10k_base
          tokens = encoding.encode(prompt)
          max_token = context_window - len(tokens)
          if max_token <= 0:
              raise ValueError(
                  f"The prompt is too long for the model. "
                  f"Please use a prompt that is less than {context_window} tokens."
              )
          return max_token
  
      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", {})
          return {
              "prompt_tokens": usage.get("prompt_tokens", 0),
              "completion_tokens": usage.get("completion_tokens", 0),
              "total_tokens": usage.get("total_tokens", 0),
          }
  
      # ===== Async Endpoints =====
      @llm_chat_callback()
      async def achat(
          self,
          messages: Sequence[ChatMessage],
          **kwargs: Any,
      ) -> ChatResponse:
          achat_fn: Callable[..., Awaitable[ChatResponse]]
          if self._is_chat_model:
              achat_fn = self._achat
          else:
              achat_fn = acompletion_to_chat_decorator(self._acomplete)
          return await achat_fn(messages, **kwargs)
  
      @llm_chat_callback()
      async def astream_chat(
          self,
          messages: Sequence[ChatMessage],
          **kwargs: Any,
      ) -> ChatResponseAsyncGen:
          astream_chat_fn: Callable[..., Awaitable[ChatResponseAsyncGen]]
          if self._is_chat_model:
              astream_chat_fn = self._astream_chat
          else:
              astream_chat_fn = astream_completion_to_chat_decorator(
                  self._astream_complete
              )
          return await astream_chat_fn(messages, **kwargs)
  
      @llm_completion_callback()
      async def acomplete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponse:
          if self._is_chat_model:
              acomplete_fn = achat_to_completion_decorator(self._achat)
          else:
              acomplete_fn = self._acomplete
          return await acomplete_fn(prompt, **kwargs)
  
      @llm_completion_callback()
      async def astream_complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponseAsyncGen:
          if self._is_chat_model:
              astream_complete_fn = astream_chat_to_completion_decorator(
                  self._astream_chat
              )
          else:
              astream_complete_fn = self._astream_complete
          return await astream_complete_fn(prompt, **kwargs)
  
      async def _achat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponse:
          if not self._is_chat_model:
              raise ValueError("This model is not a chat model.")
  
          message_dicts = to_openai_message_dicts(messages)
          all_kwargs = self._get_all_kwargs(**kwargs)
          response = await acompletion_with_retry(
              is_chat_model=self._is_chat_model,
              max_retries=self.max_retries,
              messages=message_dicts,
              stream=False,
              **all_kwargs,
          )
          message_dict = response["choices"][0]["message"]
          message = from_litellm_message(message_dict)
  
          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:
          if not self._is_chat_model:
              raise ValueError("This model is not a chat model.")
  
          message_dicts = to_openai_message_dicts(messages)
          all_kwargs = self._get_all_kwargs(**kwargs)
  
          async def gen() -> ChatResponseAsyncGen:
              content = ""
              function_call: Optional[dict] = None
              async for response in await acompletion_with_retry(
                  is_chat_model=self._is_chat_model,
                  max_retries=self.max_retries,
                  messages=message_dicts,
                  stream=True,
                  **all_kwargs,
              ):
                  delta = response["choices"][0]["delta"]
                  role = delta.get("role", "assistant")
                  content_delta = delta.get("content", "") or ""
                  content += content_delta
  
                  function_call_delta = delta.get("function_call", None)
                  if function_call_delta is not None:
                      if function_call is None:
                          function_call = function_call_delta
  
                          ## ensure we do not add a blank function call
                          if function_call.get("function_name", "") is None:
                              del function_call["function_name"]
                      else:
                          function_call["arguments"] += function_call_delta["arguments"]
  
                  additional_kwargs = {}
                  if function_call is not None:
                      additional_kwargs["function_call"] = function_call
  
                  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 _acomplete(self, prompt: str, **kwargs: Any) -> CompletionResponse:
          raise NotImplementedError("litellm assumes all llms are chat llms.")
  
      async def _astream_complete(
          self, prompt: str, **kwargs: Any
      ) -> CompletionResponseAsyncGen:
          raise NotImplementedError("litellm assumes all llms are chat llms.")
  
apis: llama_index.legacy.llms.generic_utils.astream_completion_to_chat_decorator llama_index.legacy.llms.generic_utils.astream_chat_to_completion_decorator llama_index.legacy.llms.generic_utils.acompletion_to_chat_decorator llama_index.legacy.llms.generic_utils.stream_completion_to_chat_decorator llama_index.legacy.llms.litellm_utils.validate_litellm_api_key llama_index.legacy.llms.base.llm_chat_callback llama_index.legacy.bridge.pydantic.Field llama_index.legacy.llms.generic_utils.stream_chat_to_completion_decorator llama_index.legacy.llms.litellm_utils.acompletion_with_retry llama_index.legacy.llms.base.llm_completion_callback llama_index.legacy.llms.litellm_utils.completion_with_retry llama_index.legacy.llms.litellm_utils.from_litellm_message llama_index.legacy.core.llms.types.ChatMessage llama_index.legacy.llms.generic_utils.completion_to_chat_decorator llama_index.legacy.llms.litellm_utils.to_openai_message_dicts llama_index.legacy.llms.generic_utils.achat_to_completion_decorator llama_index.legacy.llms.generic_utils.chat_to_completion_decorator
extract_api: [((1378, 1535), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default': 'DEFAULT_LITELLM_MODEL', 'description': '"""The LiteLLM model to use. For complete list of providers https://docs.litellm.ai/docs/providers"""'}), "(default=DEFAULT_LITELLM_MODEL, description=\n    'The LiteLLM model to use. For complete list of providers https://docs.litellm.ai/docs/providers'\n    )\n", (1383, 1535), False, 'from llama_index.legacy.bridge.pydantic import Field\n'), ((1613, 1727), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default': 'DEFAULT_TEMPERATURE', 'description': '"""The temperature to use during generation."""', 'gte': '(0.0)', 'lte': '(1.0)'}), "(default=DEFAULT_TEMPERATURE, description=\n    'The temperature to use during generation.', gte=0.0, lte=1.0)\n", (1618, 1727), False, 'from llama_index.legacy.bridge.pydantic import Field\n'), ((1794, 1862), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'description': '"""The maximum number of tokens to generate."""', 'gt': '(0)'}), "(description='The maximum number of tokens to generate.', gt=0)\n", (1799, 1862), False, 'from llama_index.legacy.bridge.pydantic import Field\n'), ((1926, 2003), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default_factory': 'dict', 'description': '"""Additional kwargs for the LLM API."""'}), "(default_factory=dict, description='Additional kwargs for the LLM API.')\n", (1931, 2003), False, 'from llama_index.legacy.bridge.pydantic import Field\n'), ((2121, 2188), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default': '(10)', 'description': '"""The maximum number of API retries."""'}), "(default=10, description='The maximum number of API retries.')\n", (2126, 2188), False, 'from llama_index.legacy.bridge.pydantic import Field\n'), ((5024, 5043), 'llama_index.legacy.llms.base.llm_chat_callback', 'llm_chat_callback', ([], {}), '()\n', (5041, 5043), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((5323, 5342), 'llama_index.legacy.llms.base.llm_chat_callback', 'llm_chat_callback', ([], {}), '()\n', (5340, 5342), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((5688, 5713), 'llama_index.legacy.llms.base.llm_completion_callback', 'llm_completion_callback', ([], {}), '()\n', (5711, 5713), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((6082, 6107), 'llama_index.legacy.llms.base.llm_completion_callback', 'llm_completion_callback', ([], {}), '()\n', (6105, 6107), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((12053, 12072), 'llama_index.legacy.llms.base.llm_chat_callback', 'llm_chat_callback', ([], {}), '()\n', (12070, 12072), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((12459, 12478), 'llama_index.legacy.llms.base.llm_chat_callback', 'llm_chat_callback', ([], {}), '()\n', (12476, 12478), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((12967, 12992), 'llama_index.legacy.llms.base.llm_completion_callback', 'llm_completion_callback', ([], {}), '()\n', (12990, 12992), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((13330, 13355), 'llama_index.legacy.llms.base.llm_completion_callback', 'llm_completion_callback', ([], {}), '()\n', (13353, 13355), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((7262, 7295), 'llama_index.legacy.llms.litellm_utils.to_openai_message_dicts', 'to_openai_message_dicts', (['messages'], {}), '(messages)\n', (7285, 7295), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((7593, 7736), 'llama_index.legacy.llms.litellm_utils.completion_with_retry', 'completion_with_retry', ([], {'is_chat_model': 'self._is_chat_model', 'max_retries': 'self.max_retries', 'messages': 'message_dicts', 'stream': '(False)'}), '(is_chat_model=self._is_chat_model, max_retries=self.\n    max_retries, messages=message_dicts, stream=False, **all_kwargs)\n', (7614, 7736), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((7878, 7912), 'llama_index.legacy.llms.litellm_utils.from_litellm_message', 'from_litellm_message', (['message_dict'], {}), '(message_dict)\n', (7898, 7912), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((8316, 8349), 'llama_index.legacy.llms.litellm_utils.to_openai_message_dicts', 'to_openai_message_dicts', (['messages'], {}), '(messages)\n', (8339, 8349), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((14006, 14039), 'llama_index.legacy.llms.litellm_utils.to_openai_message_dicts', 'to_openai_message_dicts', (['messages'], {}), '(messages)\n', (14029, 14039), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((14403, 14437), 'llama_index.legacy.llms.litellm_utils.from_litellm_message', 'from_litellm_message', (['message_dict'], {}), '(message_dict)\n', (14423, 14437), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((14853, 14886), 'llama_index.legacy.llms.litellm_utils.to_openai_message_dicts', 'to_openai_message_dicts', (['messages'], {}), '(messages)\n', (14876, 14886), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((3380, 3423), 'llama_index.legacy.llms.litellm_utils.validate_litellm_api_key', 'validate_litellm_api_key', (['api_key', 'api_type'], {}), '(api_key, api_type)\n', (3404, 3423), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((5229, 5273), 'llama_index.legacy.llms.generic_utils.completion_to_chat_decorator', 'completion_to_chat_decorator', (['self._complete'], {}), '(self._complete)\n', (5257, 5273), False, 'from llama_index.legacy.llms.generic_utils import achat_to_completion_decorator, acompletion_to_chat_decorator, astream_chat_to_completion_decorator, astream_completion_to_chat_decorator, chat_to_completion_decorator, completion_to_chat_decorator, stream_chat_to_completion_decorator, stream_completion_to_chat_decorator\n'), ((5573, 5631), 'llama_index.legacy.llms.generic_utils.stream_completion_to_chat_decorator', 'stream_completion_to_chat_decorator', (['self._stream_complete'], {}), '(self._stream_complete)\n', (5608, 5631), False, 'from llama_index.legacy.llms.generic_utils import achat_to_completion_decorator, acompletion_to_chat_decorator, astream_chat_to_completion_decorator, astream_completion_to_chat_decorator, chat_to_completion_decorator, completion_to_chat_decorator, stream_chat_to_completion_decorator, stream_completion_to_chat_decorator\n'), ((5934, 5974), 'llama_index.legacy.llms.generic_utils.chat_to_completion_decorator', 'chat_to_completion_decorator', (['self._chat'], {}), '(self._chat)\n', (5962, 5974), False, 'from llama_index.legacy.llms.generic_utils import achat_to_completion_decorator, acompletion_to_chat_decorator, astream_chat_to_completion_decorator, astream_completion_to_chat_decorator, chat_to_completion_decorator, completion_to_chat_decorator, stream_chat_to_completion_decorator, stream_completion_to_chat_decorator\n'), ((6296, 6350), 'llama_index.legacy.llms.generic_utils.stream_chat_to_completion_decorator', 'stream_chat_to_completion_decorator', (['self._stream_chat'], {}), '(self._stream_chat)\n', (6331, 6350), False, 'from llama_index.legacy.llms.generic_utils import achat_to_completion_decorator, acompletion_to_chat_decorator, astream_chat_to_completion_decorator, astream_completion_to_chat_decorator, chat_to_completion_decorator, completion_to_chat_decorator, stream_chat_to_completion_decorator, stream_completion_to_chat_decorator\n'), ((8768, 8910), 'llama_index.legacy.llms.litellm_utils.completion_with_retry', 'completion_with_retry', ([], {'is_chat_model': 'self._is_chat_model', 'max_retries': 'self.max_retries', 'messages': 'message_dicts', 'stream': '(True)'}), '(is_chat_model=self._is_chat_model, max_retries=self.\n    max_retries, messages=message_dicts, stream=True, **all_kwargs)\n', (8789, 8910), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((12356, 12402), 'llama_index.legacy.llms.generic_utils.acompletion_to_chat_decorator', 'acompletion_to_chat_decorator', (['self._acomplete'], {}), '(self._acomplete)\n', (12385, 12402), False, 'from llama_index.legacy.llms.generic_utils import achat_to_completion_decorator, acompletion_to_chat_decorator, astream_chat_to_completion_decorator, astream_completion_to_chat_decorator, chat_to_completion_decorator, completion_to_chat_decorator, stream_chat_to_completion_decorator, stream_completion_to_chat_decorator\n'), ((12813, 12873), 'llama_index.legacy.llms.generic_utils.astream_completion_to_chat_decorator', 'astream_completion_to_chat_decorator', (['self._astream_complete'], {}), '(self._astream_complete)\n', (12849, 12873), False, 'from llama_index.legacy.llms.generic_utils import achat_to_completion_decorator, acompletion_to_chat_decorator, astream_chat_to_completion_decorator, astream_completion_to_chat_decorator, chat_to_completion_decorator, completion_to_chat_decorator, stream_chat_to_completion_decorator, stream_completion_to_chat_decorator\n'), ((13172, 13214), 'llama_index.legacy.llms.generic_utils.achat_to_completion_decorator', 'achat_to_completion_decorator', (['self._achat'], {}), '(self._achat)\n', (13201, 13214), False, 'from llama_index.legacy.llms.generic_utils import achat_to_completion_decorator, acompletion_to_chat_decorator, astream_chat_to_completion_decorator, astream_completion_to_chat_decorator, chat_to_completion_decorator, completion_to_chat_decorator, stream_chat_to_completion_decorator, stream_completion_to_chat_decorator\n'), ((13557, 13613), 'llama_index.legacy.llms.generic_utils.astream_chat_to_completion_decorator', 'astream_chat_to_completion_decorator', (['self._astream_chat'], {}), '(self._astream_chat)\n', (13593, 13613), False, 'from llama_index.legacy.llms.generic_utils import achat_to_completion_decorator, acompletion_to_chat_decorator, astream_chat_to_completion_decorator, astream_completion_to_chat_decorator, chat_to_completion_decorator, completion_to_chat_decorator, stream_chat_to_completion_decorator, stream_completion_to_chat_decorator\n'), ((14117, 14261), 'llama_index.legacy.llms.litellm_utils.acompletion_with_retry', 'acompletion_with_retry', ([], {'is_chat_model': 'self._is_chat_model', 'max_retries': 'self.max_retries', 'messages': 'message_dicts', 'stream': '(False)'}), '(is_chat_model=self._is_chat_model, max_retries=self.\n    max_retries, messages=message_dicts, stream=False, **all_kwargs)\n', (14139, 14261), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((3266, 3309), 'llama_index.legacy.llms.litellm_utils.validate_litellm_api_key', 'validate_litellm_api_key', (['api_key', 'api_type'], {}), '(api_key, api_type)\n', (3290, 3309), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((11130, 11166), 'tiktoken.get_encoding', 'tiktoken.get_encoding', (['"""cl100k_base"""'], {}), "('cl100k_base')\n", (11151, 11166), False, 'import tiktoken\n'), ((15103, 15246), 'llama_index.legacy.llms.litellm_utils.acompletion_with_retry', 'acompletion_with_retry', ([], {'is_chat_model': 'self._is_chat_model', 'max_retries': 'self.max_retries', 'messages': 'message_dicts', 'stream': '(True)'}), '(is_chat_model=self._is_chat_model, max_retries=self.\n    max_retries, messages=message_dicts, stream=True, **all_kwargs)\n', (15125, 15246), False, 'from llama_index.legacy.llms.litellm_utils import acompletion_with_retry, completion_with_retry, from_litellm_message, is_function_calling_model, openai_modelname_to_contextsize, to_openai_message_dicts, validate_litellm_api_key\n'), ((9990, 10066), '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', (10001, 10066), False, 'from llama_index.legacy.core.llms.types import ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, LLMMetadata\n'), ((16326, 16402), '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', (16337, 16402), False, 'from llama_index.legacy.core.llms.types import ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, LLMMetadata\n')]