code: import os
  from typing import Any, Callable, Dict, Optional, Sequence
  
  from llama_index.bridge.pydantic import Field, PrivateAttr
  
  from llama_index.core.llms.types import (
      ChatMessage,
      ChatResponse,
      ChatResponseGen,
      CompletionResponse,
      CompletionResponseGen,
      LLMMetadata,
  )
  from llama_index.llms.base import llm_chat_callback, llm_completion_callback
  from llama_index.llms.custom import CustomLLM
  from llama_index.llms.generic_utils import (
      completion_response_to_chat_response,
      stream_completion_response_to_chat_response,
  )
  from llama_index.types import BaseOutputParser, PydanticProgramMode
  from llama_index.utils import get_cache_dir
  from byzerllm.utils.client import ByzerLLM
  
  class ByzerAI(CustomLLM):
      """
      ByzerAI is a custom LLM that uses the ByzerLLM API to generate text.
      """    
     
      verbose: bool = Field(
          default=False,
          description="Whether to print verbose output.",
      )
  
      _model: ByzerLLM = PrivateAttr()
  
      def __init__(
          self,
          llm:ByzerLLM
      ) -> None:        
          self._model = llm                
          super().__init__()
  
      @classmethod
      def class_name(cls) -> str:
          return "ByzerAI_llm"
  
      @property
      def metadata(self) -> LLMMetadata:
          """LLM metadata."""
          return LLMMetadata(
              context_window=8024,
              num_output=2048,
              model_name=self._model.default_model_name,
          )   
  
      @llm_chat_callback()
      def chat(self, messages: Sequence[ChatMessage], **kwargs: Any) -> ChatResponse:
          conversations = [{
              "role":message.role,
              "content":message.content
          } for message in messages]
          m = self._model.chat_oai(conversations=conversations)
          completion_response = CompletionResponse(text=m[0].output, raw=None)
          return completion_response_to_chat_response(completion_response)
  
      @llm_chat_callback()
      def stream_chat(
          self, messages: Sequence[ChatMessage], **kwargs: Any
      ) -> ChatResponseGen:        
          conversations = [{
              "role":message.role,
              "content":message.content
          } for message in messages]
          m = self._model.stream_chat_oai(conversations=conversations)
          def gen():
              v = ""
              for response in m:                
                  text:str = response[0]
                  metadata:Dict[str,Any] = response[1]
                  completion_response = CompletionResponse(text=text, delta=text[len(v):], raw=None)
                  v = text
                  yield completion_response
          return stream_completion_response_to_chat_response(gen())
  
      @llm_completion_callback()
      def complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponse:        
          m = self._model.chat_oai(conversations=[{"role":"user","content":prompt}])
          completion_response = CompletionResponse(text=m[0].output, raw=None)
          return completion_response
  
      @llm_completion_callback()
      def stream_complete(
          self, prompt: str, formatted: bool = False, **kwargs: Any
      ) -> CompletionResponseGen:
          conversations=[{"role":"user","content":prompt}]
          m = self._model.stream_chat_oai(conversations=conversations)
          def gen():
              v = ""
              for response in m:                
                  text:str = response[0]
                  metadata:Dict[str,Any] = response[1]
                  completion_response = CompletionResponse(text=text, delta=text[len(v):], raw=None)
                  v = text
                  yield completion_response
          return gen()        
apis: llama_index.core.llms.types.CompletionResponse llama_index.bridge.pydantic.Field llama_index.llms.base.llm_completion_callback llama_index.bridge.pydantic.PrivateAttr llama_index.core.llms.types.LLMMetadata llama_index.llms.base.llm_chat_callback llama_index.llms.generic_utils.completion_response_to_chat_response
extract_api: [((858, 926), 'llama_index.bridge.pydantic.Field', 'Field', ([], {'default': '(False)', 'description': '"""Whether to print verbose output."""'}), "(default=False, description='Whether to print verbose output.')\n", (863, 926), False, 'from llama_index.bridge.pydantic import Field, PrivateAttr\n'), ((974, 987), 'llama_index.bridge.pydantic.PrivateAttr', 'PrivateAttr', ([], {}), '()\n', (985, 987), False, 'from llama_index.bridge.pydantic import Field, PrivateAttr\n'), ((1459, 1478), 'llama_index.llms.base.llm_chat_callback', 'llm_chat_callback', ([], {}), '()\n', (1476, 1478), False, 'from llama_index.llms.base import llm_chat_callback, llm_completion_callback\n'), ((1914, 1933), 'llama_index.llms.base.llm_chat_callback', 'llm_chat_callback', ([], {}), '()\n', (1931, 1933), False, 'from llama_index.llms.base import llm_chat_callback, llm_completion_callback\n'), ((2667, 2692), 'llama_index.llms.base.llm_completion_callback', 'llm_completion_callback', ([], {}), '()\n', (2690, 2692), False, 'from llama_index.llms.base import llm_chat_callback, llm_completion_callback\n'), ((3015, 3040), 'llama_index.llms.base.llm_completion_callback', 'llm_completion_callback', ([], {}), '()\n', (3038, 3040), False, 'from llama_index.llms.base import llm_chat_callback, llm_completion_callback\n'), ((1310, 1407), 'llama_index.core.llms.types.LLMMetadata', 'LLMMetadata', ([], {'context_window': '(8024)', 'num_output': '(2048)', 'model_name': 'self._model.default_model_name'}), '(context_window=8024, num_output=2048, model_name=self._model.\n    default_model_name)\n', (1321, 1407), False, 'from llama_index.core.llms.types import ChatMessage, ChatResponse, ChatResponseGen, CompletionResponse, CompletionResponseGen, LLMMetadata\n'), ((1788, 1834), 'llama_index.core.llms.types.CompletionResponse', 'CompletionResponse', ([], {'text': 'm[0].output', 'raw': 'None'}), '(text=m[0].output, raw=None)\n', (1806, 1834), False, 'from llama_index.core.llms.types import ChatMessage, ChatResponse, ChatResponseGen, CompletionResponse, CompletionResponseGen, LLMMetadata\n'), ((1850, 1907), 'llama_index.llms.generic_utils.completion_response_to_chat_response', 'completion_response_to_chat_response', (['completion_response'], {}), '(completion_response)\n', (1886, 1907), False, 'from llama_index.llms.generic_utils import completion_response_to_chat_response, stream_completion_response_to_chat_response\n'), ((2927, 2973), 'llama_index.core.llms.types.CompletionResponse', 'CompletionResponse', ([], {'text': 'm[0].output', 'raw': 'None'}), '(text=m[0].output, raw=None)\n', (2945, 2973), False, 'from llama_index.core.llms.types import ChatMessage, ChatResponse, ChatResponseGen, CompletionResponse, CompletionResponseGen, LLMMetadata\n')]