code: from abc import abstractmethod
  from typing import (
      Any,
      Sequence,
  )
  
  from llama_index.core.base.llms.types import (
      ChatMessage,
      ChatResponse,
      ChatResponseAsyncGen,
      ChatResponseGen,
      CompletionResponse,
      CompletionResponseAsyncGen,
      CompletionResponseGen,
      LLMMetadata,
  )
  from llama_index.core.base.query_pipeline.query import (
      ChainableMixin,
  )
  from llama_index.core.bridge.pydantic import Field, validator
  from llama_index.core.callbacks import CallbackManager
  from llama_index.core.schema import BaseComponent
  
  
  class BaseLLM(ChainableMixin, BaseComponent):
      """LLM interface."""
  
      callback_manager: CallbackManager = Field(
          default_factory=CallbackManager, exclude=True
      )
  
      class Config:
          arbitrary_types_allowed = True
  
      @validator("callback_manager", pre=True)
      def _validate_callback_manager(cls, v: CallbackManager) -> CallbackManager:
          if v is None:
              return CallbackManager([])
          return v
  
      @property
      @abstractmethod
      def metadata(self) -> LLMMetadata:
          """LLM metadata."""
  
      @abstractmethod
      def chat(self, messages: Sequence[ChatMessage], **kwargs: Any) -> ChatResponse:
          """Chat endpoint for LLM."""
  
      @abstractmethod
      def complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponse:
          """Completion endpoint for LLM."""
  
      @abstractmethod
      def stream_chat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponseGen:
          """Streaming chat endpoint for LLM."""
  
      @abstractmethod
      def stream_complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponseGen:
          """Streaming completion endpoint for LLM."""
  
      # ===== Async Endpoints =====
      @abstractmethod
      async def achat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponse:
          """Async chat endpoint for LLM."""
  
      @abstractmethod
      async def acomplete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponse:
          """Async completion endpoint for LLM."""
  
      @abstractmethod
      async def astream_chat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponseAsyncGen:
          """Async streaming chat endpoint for LLM."""
  
      @abstractmethod
      async def astream_complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponseAsyncGen:
          """Async streaming completion endpoint for LLM."""
  
apis: llama_index.core.callbacks.CallbackManager llama_index.core.bridge.pydantic.validator llama_index.core.bridge.pydantic.Field
extract_api: [((669, 721), 'llama_index.core.bridge.pydantic.Field', 'Field', ([], {'default_factory': 'CallbackManager', 'exclude': '(True)'}), '(default_factory=CallbackManager, exclude=True)\n', (674, 721), False, 'from llama_index.core.bridge.pydantic import Field, validator\n'), ((800, 839), 'llama_index.core.bridge.pydantic.validator', 'validator', (['"""callback_manager"""'], {'pre': '(True)'}), "('callback_manager', pre=True)\n", (809, 839), False, 'from llama_index.core.bridge.pydantic import Field, validator\n'), ((961, 980), 'llama_index.core.callbacks.CallbackManager', 'CallbackManager', (['[]'], {}), '([])\n', (976, 980), False, 'from llama_index.core.callbacks import CallbackManager\n')]