code: import warnings
  from typing import Any, Callable, Dict, Optional, Sequence
  
  from llama_index.legacy.bridge.pydantic import Field, PrivateAttr
  from llama_index.legacy.callbacks import CallbackManager
  from llama_index.legacy.core.llms.types import (
      ChatMessage,
      ChatResponse,
      ChatResponseAsyncGen,
      ChatResponseGen,
      CompletionResponse,
      CompletionResponseAsyncGen,
      CompletionResponseGen,
      LLMMetadata,
      MessageRole,
  )
  from llama_index.legacy.llms.base import (
      llm_chat_callback,
      llm_completion_callback,
  )
  from llama_index.legacy.llms.cohere_utils import (
      CHAT_MODELS,
      acompletion_with_retry,
      cohere_modelname_to_contextsize,
      completion_with_retry,
      messages_to_cohere_history,
  )
  from llama_index.legacy.llms.llm import LLM
  from llama_index.legacy.types import BaseOutputParser, PydanticProgramMode
  
  
  class Cohere(LLM):
      model: str = Field(description="The cohere model to use.")
      temperature: float = Field(description="The temperature to use for sampling.")
      max_retries: int = Field(
          default=10, description="The maximum number of API retries."
      )
      additional_kwargs: Dict[str, Any] = Field(
          default_factory=dict, description="Additional kwargs for the Cohere API."
      )
      max_tokens: int = Field(description="The maximum number of tokens to generate.")
  
      _client: Any = PrivateAttr()
      _aclient: Any = PrivateAttr()
  
      def __init__(
          self,
          model: str = "command",
          temperature: float = 0.5,
          max_tokens: int = 512,
          timeout: Optional[float] = None,
          max_retries: int = 10,
          api_key: Optional[str] = None,
          additional_kwargs: Optional[Dict[str, Any]] = 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,
      ) -> None:
          try:
              import cohere
          except ImportError as e:
              raise ImportError(
                  "You must install the `cohere` package to use Cohere."
                  "Please `pip install cohere`"
              ) from e
          additional_kwargs = additional_kwargs or {}
          callback_manager = callback_manager or CallbackManager([])
  
          self._client = cohere.Client(api_key, client_name="llama_index")
          self._aclient = cohere.AsyncClient(api_key, client_name="llama_index")
  
          super().__init__(
              temperature=temperature,
              additional_kwargs=additional_kwargs,
              timeout=timeout,
              max_retries=max_retries,
              model=model,
              callback_manager=callback_manager,
              max_tokens=max_tokens,
              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,
          )
  
      @classmethod
      def class_name(cls) -> str:
          """Get class name."""
          return "Cohere_LLM"
  
      @property
      def metadata(self) -> LLMMetadata:
          return LLMMetadata(
              context_window=cohere_modelname_to_contextsize(self.model),
              num_output=self.max_tokens,
              is_chat_model=True,
              model_name=self.model,
              system_role=MessageRole.CHATBOT,
          )
  
      @property
      def _model_kwargs(self) -> Dict[str, Any]:
          base_kwargs = {
              "model": self.model,
              "temperature": self.temperature,
          }
          return {
              **base_kwargs,
              **self.additional_kwargs,
          }
  
      def _get_all_kwargs(self, **kwargs: Any) -> Dict[str, Any]:
          return {
              **self._model_kwargs,
              **kwargs,
          }
  
      @llm_chat_callback()
      def chat(self, messages: Sequence[ChatMessage], **kwargs: Any) -> ChatResponse:
          history = messages_to_cohere_history(messages[:-1])
          prompt = messages[-1].content
          all_kwargs = self._get_all_kwargs(**kwargs)
          if all_kwargs["model"] not in CHAT_MODELS:
              raise ValueError(f"{all_kwargs['model']} not supported for chat")
  
          if "stream" in all_kwargs:
              warnings.warn(
                  "Parameter `stream` is not supported by the `chat` method."
                  "Use the `stream_chat` method instead"
              )
          response = completion_with_retry(
              client=self._client,
              max_retries=self.max_retries,
              chat=True,
              message=prompt,
              chat_history=history,
              **all_kwargs,
          )
          return ChatResponse(
              message=ChatMessage(role=MessageRole.ASSISTANT, content=response.text),
              raw=response.__dict__,
          )
  
      @llm_completion_callback()
      def complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponse:
          all_kwargs = self._get_all_kwargs(**kwargs)
          if "stream" in all_kwargs:
              warnings.warn(
                  "Parameter `stream` is not supported by the `chat` method."
                  "Use the `stream_chat` method instead"
              )
  
          response = completion_with_retry(
              client=self._client,
              max_retries=self.max_retries,
              chat=False,
              prompt=prompt,
              **all_kwargs,
          )
  
          return CompletionResponse(
              text=response.generations[0].text,
              raw=response.__dict__,
          )
  
      @llm_chat_callback()
      def stream_chat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponseGen:
          history = messages_to_cohere_history(messages[:-1])
          prompt = messages[-1].content
          all_kwargs = self._get_all_kwargs(**kwargs)
          all_kwargs["stream"] = True
          if all_kwargs["model"] not in CHAT_MODELS:
              raise ValueError(f"{all_kwargs['model']} not supported for chat")
          response = completion_with_retry(
              client=self._client,
              max_retries=self.max_retries,
              chat=True,
              message=prompt,
              chat_history=history,
              **all_kwargs,
          )
  
          def gen() -> ChatResponseGen:
              content = ""
              role = MessageRole.ASSISTANT
              for r in response:
                  if "text" in r.__dict__:
                      content_delta = r.text
                  else:
                      content_delta = ""
                  content += content_delta
                  yield ChatResponse(
                      message=ChatMessage(role=role, content=content),
                      delta=content_delta,
                      raw=r.__dict__,
                  )
  
          return gen()
  
      @llm_completion_callback()
      def stream_complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponseGen:
          all_kwargs = self._get_all_kwargs(**kwargs)
          all_kwargs["stream"] = True
  
          response = completion_with_retry(
              client=self._client,
              max_retries=self.max_retries,
              chat=False,
              prompt=prompt,
              **all_kwargs,
          )
  
          def gen() -> CompletionResponseGen:
              content = ""
              for r in response:
                  content_delta = r.text
                  content += content_delta
                  yield CompletionResponse(
                      text=content, delta=content_delta, raw=r._asdict()
                  )
  
          return gen()
  
      @llm_chat_callback()
      async def achat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponse:
          history = messages_to_cohere_history(messages[:-1])
          prompt = messages[-1].content
          all_kwargs = self._get_all_kwargs(**kwargs)
          if all_kwargs["model"] not in CHAT_MODELS:
              raise ValueError(f"{all_kwargs['model']} not supported for chat")
          if "stream" in all_kwargs:
              warnings.warn(
                  "Parameter `stream` is not supported by the `chat` method."
                  "Use the `stream_chat` method instead"
              )
  
          response = await acompletion_with_retry(
              aclient=self._aclient,
              max_retries=self.max_retries,
              chat=True,
              message=prompt,
              chat_history=history,
              **all_kwargs,
          )
  
          return ChatResponse(
              message=ChatMessage(role=MessageRole.ASSISTANT, content=response.text),
              raw=response.__dict__,
          )
  
      @llm_completion_callback()
      async def acomplete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponse:
          all_kwargs = self._get_all_kwargs(**kwargs)
          if "stream" in all_kwargs:
              warnings.warn(
                  "Parameter `stream` is not supported by the `chat` method."
                  "Use the `stream_chat` method instead"
              )
  
          response = await acompletion_with_retry(
              aclient=self._aclient,
              max_retries=self.max_retries,
              chat=False,
              prompt=prompt,
              **all_kwargs,
          )
  
          return CompletionResponse(
              text=response.generations[0].text,
              raw=response.__dict__,
          )
  
      @llm_chat_callback()
      async def astream_chat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponseAsyncGen:
          history = messages_to_cohere_history(messages[:-1])
          prompt = messages[-1].content
          all_kwargs = self._get_all_kwargs(**kwargs)
          all_kwargs["stream"] = True
          if all_kwargs["model"] not in CHAT_MODELS:
              raise ValueError(f"{all_kwargs['model']} not supported for chat")
          response = await acompletion_with_retry(
              aclient=self._aclient,
              max_retries=self.max_retries,
              chat=True,
              message=prompt,
              chat_history=history,
              **all_kwargs,
          )
  
          async def gen() -> ChatResponseAsyncGen:
              content = ""
              role = MessageRole.ASSISTANT
              async for r in response:
                  if "text" in r.__dict__:
                      content_delta = r.text
                  else:
                      content_delta = ""
                  content += content_delta
                  yield ChatResponse(
                      message=ChatMessage(role=role, content=content),
                      delta=content_delta,
                      raw=r.__dict__,
                  )
  
          return gen()
  
      @llm_completion_callback()
      async def astream_complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponseAsyncGen:
          all_kwargs = self._get_all_kwargs(**kwargs)
          all_kwargs["stream"] = True
  
          response = await acompletion_with_retry(
              aclient=self._aclient,
              max_retries=self.max_retries,
              chat=False,
              prompt=prompt,
              **all_kwargs,
          )
  
          async def gen() -> CompletionResponseAsyncGen:
              content = ""
              async for r in response:
                  content_delta = r.text
                  content += content_delta
                  yield CompletionResponse(
                      text=content, delta=content_delta, raw=r._asdict()
                  )
  
          return gen()
  
apis: llama_index.legacy.llms.cohere_utils.messages_to_cohere_history llama_index.legacy.core.llms.types.CompletionResponse llama_index.legacy.llms.cohere_utils.cohere_modelname_to_contextsize llama_index.legacy.llms.base.llm_chat_callback llama_index.legacy.bridge.pydantic.Field llama_index.legacy.llms.cohere_utils.acompletion_with_retry llama_index.legacy.llms.base.llm_completion_callback llama_index.legacy.core.llms.types.ChatMessage llama_index.legacy.bridge.pydantic.PrivateAttr llama_index.legacy.llms.cohere_utils.completion_with_retry llama_index.legacy.callbacks.CallbackManager
extract_api: [((897, 942), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'description': '"""The cohere model to use."""'}), "(description='The cohere model to use.')\n", (902, 942), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((968, 1025), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'description': '"""The temperature to use for sampling."""'}), "(description='The temperature to use for sampling.')\n", (973, 1025), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((1049, 1116), '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", (1054, 1116), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((1171, 1256), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'default_factory': 'dict', 'description': '"""Additional kwargs for the Cohere API."""'}), "(default_factory=dict, description='Additional kwargs for the Cohere API.'\n    )\n", (1176, 1256), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((1288, 1350), 'llama_index.legacy.bridge.pydantic.Field', 'Field', ([], {'description': '"""The maximum number of tokens to generate."""'}), "(description='The maximum number of tokens to generate.')\n", (1293, 1350), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((1371, 1384), 'llama_index.legacy.bridge.pydantic.PrivateAttr', 'PrivateAttr', ([], {}), '()\n', (1382, 1384), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((1405, 1418), 'llama_index.legacy.bridge.pydantic.PrivateAttr', 'PrivateAttr', ([], {}), '()\n', (1416, 1418), False, 'from llama_index.legacy.bridge.pydantic import Field, PrivateAttr\n'), ((4032, 4051), 'llama_index.legacy.llms.base.llm_chat_callback', 'llm_chat_callback', ([], {}), '()\n', (4049, 4051), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((5025, 5050), 'llama_index.legacy.llms.base.llm_completion_callback', 'llm_completion_callback', ([], {}), '()\n', (5048, 5050), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((5762, 5781), 'llama_index.legacy.llms.base.llm_chat_callback', 'llm_chat_callback', ([], {}), '()\n', (5779, 5781), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((6993, 7018), 'llama_index.legacy.llms.base.llm_completion_callback', 'llm_completion_callback', ([], {}), '()\n', (7016, 7018), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((7775, 7794), 'llama_index.legacy.llms.base.llm_chat_callback', 'llm_chat_callback', ([], {}), '()\n', (7792, 7794), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((8799, 8824), 'llama_index.legacy.llms.base.llm_completion_callback', 'llm_completion_callback', ([], {}), '()\n', (8822, 8824), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((9552, 9571), 'llama_index.legacy.llms.base.llm_chat_callback', 'llm_chat_callback', ([], {}), '()\n', (9569, 9571), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((10821, 10846), 'llama_index.legacy.llms.base.llm_completion_callback', 'llm_completion_callback', ([], {}), '()\n', (10844, 10846), False, 'from llama_index.legacy.llms.base import llm_chat_callback, llm_completion_callback\n'), ((2518, 2567), 'cohere.Client', 'cohere.Client', (['api_key'], {'client_name': '"""llama_index"""'}), "(api_key, client_name='llama_index')\n", (2531, 2567), False, 'import cohere\n'), ((2592, 2646), 'cohere.AsyncClient', 'cohere.AsyncClient', (['api_key'], {'client_name': '"""llama_index"""'}), "(api_key, client_name='llama_index')\n", (2610, 2646), False, 'import cohere\n'), ((4154, 4195), 'llama_index.legacy.llms.cohere_utils.messages_to_cohere_history', 'messages_to_cohere_history', (['messages[:-1]'], {}), '(messages[:-1])\n', (4180, 4195), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((4642, 4781), 'llama_index.legacy.llms.cohere_utils.completion_with_retry', 'completion_with_retry', ([], {'client': 'self._client', 'max_retries': 'self.max_retries', 'chat': '(True)', 'message': 'prompt', 'chat_history': 'history'}), '(client=self._client, max_retries=self.max_retries,\n    chat=True, message=prompt, chat_history=history, **all_kwargs)\n', (4663, 4781), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((5443, 5560), 'llama_index.legacy.llms.cohere_utils.completion_with_retry', 'completion_with_retry', ([], {'client': 'self._client', 'max_retries': 'self.max_retries', 'chat': '(False)', 'prompt': 'prompt'}), '(client=self._client, max_retries=self.max_retries,\n    chat=False, prompt=prompt, **all_kwargs)\n', (5464, 5560), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((5644, 5720), 'llama_index.legacy.core.llms.types.CompletionResponse', 'CompletionResponse', ([], {'text': 'response.generations[0].text', 'raw': 'response.__dict__'}), '(text=response.generations[0].text, raw=response.__dict__)\n', (5662, 5720), False, 'from llama_index.legacy.core.llms.types import ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, LLMMetadata, MessageRole\n'), ((5908, 5949), 'llama_index.legacy.llms.cohere_utils.messages_to_cohere_history', 'messages_to_cohere_history', (['messages[:-1]'], {}), '(messages[:-1])\n', (5934, 5949), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((6224, 6363), 'llama_index.legacy.llms.cohere_utils.completion_with_retry', 'completion_with_retry', ([], {'client': 'self._client', 'max_retries': 'self.max_retries', 'chat': '(True)', 'message': 'prompt', 'chat_history': 'history'}), '(client=self._client, max_retries=self.max_retries,\n    chat=True, message=prompt, chat_history=history, **all_kwargs)\n', (6245, 6363), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((7250, 7367), 'llama_index.legacy.llms.cohere_utils.completion_with_retry', 'completion_with_retry', ([], {'client': 'self._client', 'max_retries': 'self.max_retries', 'chat': '(False)', 'prompt': 'prompt'}), '(client=self._client, max_retries=self.max_retries,\n    chat=False, prompt=prompt, **all_kwargs)\n', (7271, 7367), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((7918, 7959), 'llama_index.legacy.llms.cohere_utils.messages_to_cohere_history', 'messages_to_cohere_history', (['messages[:-1]'], {}), '(messages[:-1])\n', (7944, 7959), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((9434, 9510), 'llama_index.legacy.core.llms.types.CompletionResponse', 'CompletionResponse', ([], {'text': 'response.generations[0].text', 'raw': 'response.__dict__'}), '(text=response.generations[0].text, raw=response.__dict__)\n', (9452, 9510), False, 'from llama_index.legacy.core.llms.types import ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, LLMMetadata, MessageRole\n'), ((9710, 9751), 'llama_index.legacy.llms.cohere_utils.messages_to_cohere_history', 'messages_to_cohere_history', (['messages[:-1]'], {}), '(messages[:-1])\n', (9736, 9751), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((2474, 2493), 'llama_index.legacy.callbacks.CallbackManager', 'CallbackManager', (['[]'], {}), '([])\n', (2489, 2493), False, 'from llama_index.legacy.callbacks import CallbackManager\n'), ((4463, 4583), 'warnings.warn', 'warnings.warn', (['"""Parameter `stream` is not supported by the `chat` method.Use the `stream_chat` method instead"""'], {}), "(\n    'Parameter `stream` is not supported by the `chat` method.Use the `stream_chat` method instead'\n    )\n", (4476, 4583), False, 'import warnings\n'), ((5263, 5383), 'warnings.warn', 'warnings.warn', (['"""Parameter `stream` is not supported by the `chat` method.Use the `stream_chat` method instead"""'], {}), "(\n    'Parameter `stream` is not supported by the `chat` method.Use the `stream_chat` method instead'\n    )\n", (5276, 5383), False, 'import warnings\n'), ((8226, 8346), 'warnings.warn', 'warnings.warn', (['"""Parameter `stream` is not supported by the `chat` method.Use the `stream_chat` method instead"""'], {}), "(\n    'Parameter `stream` is not supported by the `chat` method.Use the `stream_chat` method instead'\n    )\n", (8239, 8346), False, 'import warnings\n'), ((8412, 8554), 'llama_index.legacy.llms.cohere_utils.acompletion_with_retry', 'acompletion_with_retry', ([], {'aclient': 'self._aclient', 'max_retries': 'self.max_retries', 'chat': '(True)', 'message': 'prompt', 'chat_history': 'history'}), '(aclient=self._aclient, max_retries=self.max_retries,\n    chat=True, message=prompt, chat_history=history, **all_kwargs)\n', (8434, 8554), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((9044, 9164), 'warnings.warn', 'warnings.warn', (['"""Parameter `stream` is not supported by the `chat` method.Use the `stream_chat` method instead"""'], {}), "(\n    'Parameter `stream` is not supported by the `chat` method.Use the `stream_chat` method instead'\n    )\n", (9057, 9164), False, 'import warnings\n'), ((9230, 9350), 'llama_index.legacy.llms.cohere_utils.acompletion_with_retry', 'acompletion_with_retry', ([], {'aclient': 'self._aclient', 'max_retries': 'self.max_retries', 'chat': '(False)', 'prompt': 'prompt'}), '(aclient=self._aclient, max_retries=self.max_retries,\n    chat=False, prompt=prompt, **all_kwargs)\n', (9252, 9350), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((10032, 10174), 'llama_index.legacy.llms.cohere_utils.acompletion_with_retry', 'acompletion_with_retry', ([], {'aclient': 'self._aclient', 'max_retries': 'self.max_retries', 'chat': '(True)', 'message': 'prompt', 'chat_history': 'history'}), '(aclient=self._aclient, max_retries=self.max_retries,\n    chat=True, message=prompt, chat_history=history, **all_kwargs)\n', (10054, 10174), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((11096, 11216), 'llama_index.legacy.llms.cohere_utils.acompletion_with_retry', 'acompletion_with_retry', ([], {'aclient': 'self._aclient', 'max_retries': 'self.max_retries', 'chat': '(False)', 'prompt': 'prompt'}), '(aclient=self._aclient, max_retries=self.max_retries,\n    chat=False, prompt=prompt, **all_kwargs)\n', (11118, 11216), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((3405, 3448), 'llama_index.legacy.llms.cohere_utils.cohere_modelname_to_contextsize', 'cohere_modelname_to_contextsize', (['self.model'], {}), '(self.model)\n', (3436, 3448), False, 'from llama_index.legacy.llms.cohere_utils import CHAT_MODELS, acompletion_with_retry, cohere_modelname_to_contextsize, completion_with_retry, messages_to_cohere_history\n'), ((4910, 4972), 'llama_index.legacy.core.llms.types.ChatMessage', 'ChatMessage', ([], {'role': 'MessageRole.ASSISTANT', 'content': 'response.text'}), '(role=MessageRole.ASSISTANT, content=response.text)\n', (4921, 4972), False, 'from llama_index.legacy.core.llms.types import ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, LLMMetadata, MessageRole\n'), ((8684, 8746), 'llama_index.legacy.core.llms.types.ChatMessage', 'ChatMessage', ([], {'role': 'MessageRole.ASSISTANT', 'content': 'response.text'}), '(role=MessageRole.ASSISTANT, content=response.text)\n', (8695, 8746), False, 'from llama_index.legacy.core.llms.types import ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, LLMMetadata, MessageRole\n'), ((6829, 6868), 'llama_index.legacy.core.llms.types.ChatMessage', 'ChatMessage', ([], {'role': 'role', 'content': 'content'}), '(role=role, content=content)\n', (6840, 6868), False, 'from llama_index.legacy.core.llms.types import ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, LLMMetadata, MessageRole\n'), ((10657, 10696), 'llama_index.legacy.core.llms.types.ChatMessage', 'ChatMessage', ([], {'role': 'role', 'content': 'content'}), '(role=role, content=content)\n', (10668, 10696), False, 'from llama_index.legacy.core.llms.types import ChatMessage, ChatResponse, ChatResponseAsyncGen, ChatResponseGen, CompletionResponse, CompletionResponseAsyncGen, CompletionResponseGen, LLMMetadata, MessageRole\n')]