code: from enum import Enum
  from typing import Any, AsyncGenerator, Generator, Optional, Union, List
  
  from llama_index.core.bridge.pydantic import BaseModel, Field
  from llama_index.core.constants import DEFAULT_CONTEXT_WINDOW, DEFAULT_NUM_OUTPUTS
  
  
  class MessageRole(str, Enum):
      """Message role."""
  
      SYSTEM = "system"
      USER = "user"
      ASSISTANT = "assistant"
      FUNCTION = "function"
      TOOL = "tool"
      CHATBOT = "chatbot"
      MODEL = "model"
  
  
  # ===== Generic Model Input - Chat =====
  class ChatMessage(BaseModel):
      """Chat message."""
  
      role: MessageRole = MessageRole.USER
      content: Optional[Any] = ""
      additional_kwargs: dict = Field(default_factory=dict)
  
      def __str__(self) -> str:
          return f"{self.role.value}: {self.content}"
  
      @classmethod
      def from_str(
          cls,
          content: str,
          role: Union[MessageRole, str] = MessageRole.USER,
          **kwargs: Any,
      ) -> "ChatMessage":
          if isinstance(role, str):
              role = MessageRole(role)
          return cls(role=role, content=content, **kwargs)
  
  
  class LogProb(BaseModel):
      """LogProb of a token."""
  
      token: str = Field(default_factory=str)
      logprob: float = Field(default_factory=float)
      bytes: List[int] = Field(default_factory=list)
  
  
  # ===== Generic Model Output - Chat =====
  class ChatResponse(BaseModel):
      """Chat response."""
  
      message: ChatMessage
      raw: Optional[dict] = None
      delta: Optional[str] = None
      logprobs: Optional[List[List[LogProb]]] = None
      additional_kwargs: dict = Field(default_factory=dict)
  
      def __str__(self) -> str:
          return str(self.message)
  
  
  ChatResponseGen = Generator[ChatResponse, None, None]
  ChatResponseAsyncGen = AsyncGenerator[ChatResponse, None]
  
  
  # ===== Generic Model Output - Completion =====
  class CompletionResponse(BaseModel):
      """
      Completion response.
  
      Fields:
          text: Text content of the response if not streaming, or if streaming,
              the current extent of streamed text.
          additional_kwargs: Additional information on the response(i.e. token
              counts, function calling information).
          raw: Optional raw JSON that was parsed to populate text, if relevant.
          delta: New text that just streamed in (only relevant when streaming).
      """
  
      text: str
      additional_kwargs: dict = Field(default_factory=dict)
      raw: Optional[dict] = None
      delta: Optional[str] = None
  
      def __str__(self) -> str:
          return self.text
  
  
  CompletionResponseGen = Generator[CompletionResponse, None, None]
  CompletionResponseAsyncGen = AsyncGenerator[CompletionResponse, None]
  
  
  class LLMMetadata(BaseModel):
      context_window: int = Field(
          default=DEFAULT_CONTEXT_WINDOW,
          description=(
              "Total number of tokens the model can be input and output for one response."
          ),
      )
      num_output: int = Field(
          default=DEFAULT_NUM_OUTPUTS,
          description="Number of tokens the model can output when generating a response.",
      )
      is_chat_model: bool = Field(
          default=False,
          description=(
              "Set True if the model exposes a chat interface (i.e. can be passed a"
              " sequence of messages, rather than text), like OpenAI's"
              " /v1/chat/completions endpoint."
          ),
      )
      is_function_calling_model: bool = Field(
          default=False,
          # SEE: https://openai.com/blog/function-calling-and-other-api-updates
          description=(
              "Set True if the model supports function calling messages, similar to"
              " OpenAI's function calling API. For example, converting 'Email Anya to"
              " see if she wants to get coffee next Friday' to a function call like"
              " `send_email(to: string, body: string)`."
          ),
      )
      model_name: str = Field(
          default="unknown",
          description=(
              "The model's name used for logging, testing, and sanity checking. For some"
              " models this can be automatically discerned. For other models, like"
              " locally loaded models, this must be manually specified."
          ),
      )
      system_role: MessageRole = Field(
          default=MessageRole.SYSTEM,
          description="The role this specific LLM provider"
          "expects for system prompt. E.g. 'SYSTEM' for OpenAI, 'CHATBOT' for Cohere",
      )
  
apis: llama_index.core.bridge.pydantic.Field
extract_api: [((655, 682), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default_factory': 'dict'}), '(default_factory=dict)\n', (660, 682), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((1146, 1172), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default_factory': 'str'}), '(default_factory=str)\n', (1151, 1172), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((1194, 1222), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default_factory': 'float'}), '(default_factory=float)\n', (1199, 1222), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((1246, 1273), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default_factory': 'list'}), '(default_factory=list)\n', (1251, 1273), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((1544, 1571), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default_factory': 'dict'}), '(default_factory=dict)\n', (1549, 1571), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((2347, 2374), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default_factory': 'dict'}), '(default_factory=dict)\n', (2352, 2374), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((2690, 2827), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default': 'DEFAULT_CONTEXT_WINDOW', 'description': '"""Total number of tokens the model can be input and output for one response."""'}), "(default=DEFAULT_CONTEXT_WINDOW, description=\n    'Total number of tokens the model can be input and output for one response.'\n    )\n", (2695, 2827), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((2887, 3007), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default': 'DEFAULT_NUM_OUTPUTS', 'description': '"""Number of tokens the model can output when generating a response."""'}), "(default=DEFAULT_NUM_OUTPUTS, description=\n    'Number of tokens the model can output when generating a response.')\n", (2892, 3007), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((3052, 3252), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default': '(False)', 'description': '"""Set True if the model exposes a chat interface (i.e. can be passed a sequence of messages, rather than text), like OpenAI\'s /v1/chat/completions endpoint."""'}), '(default=False, description=\n    "Set True if the model exposes a chat interface (i.e. can be passed a sequence of messages, rather than text), like OpenAI\'s /v1/chat/completions endpoint."\n    )\n', (3057, 3252), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((3358, 3650), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default': '(False)', 'description': '"""Set True if the model supports function calling messages, similar to OpenAI\'s function calling API. For example, converting \'Email Anya to see if she wants to get coffee next Friday\' to a function call like `send_email(to: string, body: string)`."""'}), '(default=False, description=\n    "Set True if the model supports function calling messages, similar to OpenAI\'s function calling API. For example, converting \'Email Anya to see if she wants to get coffee next Friday\' to a function call like `send_email(to: string, body: string)`."\n    )\n', (3363, 3650), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((3833, 4079), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default': '"""unknown"""', 'description': '"""The model\'s name used for logging, testing, and sanity checking. For some models this can be automatically discerned. For other models, like locally loaded models, this must be manually specified."""'}), '(default=\'unknown\', description=\n    "The model\'s name used for logging, testing, and sanity checking. For some models this can be automatically discerned. For other models, like locally loaded models, this must be manually specified."\n    )\n', (3838, 4079), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n'), ((4178, 4345), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default': 'MessageRole.SYSTEM', 'description': '"""The role this specific LLM providerexpects for system prompt. E.g. \'SYSTEM\' for OpenAI, \'CHATBOT\' for Cohere"""'}), '(default=MessageRole.SYSTEM, description=\n    "The role this specific LLM providerexpects for system prompt. E.g. \'SYSTEM\' for OpenAI, \'CHATBOT\' for Cohere"\n    )\n', (4183, 4345), False, 'from llama_index.core.bridge.pydantic import BaseModel, Field\n')]