code: import os
  
  import openai
  from dotenv import load_dotenv
  from llama_index.embeddings import AzureOpenAIEmbedding, OpenAIEmbedding
  from llama_index.llms import AzureOpenAI, OpenAI, OpenAILike
  from llama_index.llms.llama_utils import messages_to_prompt
  
  
  def load_models(args, logger):
      llm_service = args.llm_service
      llm_model = args.llm_model
      load_dotenv()
      llm_temperature = 0.1
      timeout = 120.0
  
      if llm_model == "gpt3":
          # _llm_model = "gpt-35-turbo"
          _llm_model = "gpt-3.5-turbo-1106"
          _azure_openai_key = os.getenv("AZURE_OPENAI_GPT4_KEY")
          _azure_ada_deployment_name = "sketch-ai-gpt4-ada002"
          _azure_endpoint = "https://open-ai-uk-south.openai.azure.com/"
          _azure_deployment_name = "sketch-ai-gpt35turbo"
      elif llm_model == "gpt4":
          _azure_deployment_name = "sketch-ai-gpt4"
          _llm_model = "gpt-4-1106-preview"
          # _llm_model_oai = "gpt-4-1106-preview"
          _azure_openai_key = os.getenv("AZURE_OPENAI_GPT4_KEY")
          _azure_ada_deployment_name = "sketch-ai-gpt4-ada002"
          _azure_endpoint = "https://open-ai-uk-south.openai.azure.com/"
      elif llm_model == "local":
          # TODO: Replace these once I figure out how to get local embedding server working
          _azure_deployment_name = "sketch-ai-gpt4"
          _azure_openai_key = os.getenv("AZURE_OPENAI_GPT4_KEY")
          _azure_ada_deployment_name = "sketch-ai-gpt4-ada002"
          _azure_endpoint = "https://open-ai-uk-south.openai.azure.com/"
          api_version = "2023-07-01-preview"
      else:
          raise ValueError(f"Model {llm_model} not supported")
  
      _llm = None
      _embed_model = None
  
      if llm_service == "openai":
          logger.info("Using OPENAI services")
          _embed_model = OpenAIEmbedding()
  
          openai.api_key = os.getenv("OPENAI_API_KEY")
          _llm = OpenAI(temperature=llm_temperature, model=_llm_model, timeout=timeout)
      elif llm_service == "azure":
          logger.info("Using AZURE services")
  
          api_version = "2023-07-01-preview"
  
          _llm = AzureOpenAI(
              model=_llm_model,
              deployment_name=_azure_deployment_name,
              api_key=_azure_openai_key,
              azure_endpoint=_azure_endpoint,
              api_version=api_version,
              temperature=llm_temperature,
              timeout=timeout,
          )
  
          # You need to deploy your own embedding model as well as your own chat completion model
          _embed_model = AzureOpenAIEmbedding(
              model="text-embedding-ada-002",
              deployment_name=_azure_ada_deployment_name,
              api_key=_azure_openai_key,
              azure_endpoint=_azure_endpoint,
              api_version=api_version,
          )
      elif llm_service == "local":
          MAC_M1_LUNADEMO_CONSERVATIVE_TIMEOUT = 10 * 60  # sec
          _llm = OpenAILike(
              max_tokens=4096,
              temperature=0.9,
              api_key="localai_fake",
              api_version="localai_fake",
              api_base=f"http://{args.local_llm_address}:{args.local_llm_port}/v1",
              model="local llm",
              is_chat_model=True,
              timeout=MAC_M1_LUNADEMO_CONSERVATIVE_TIMEOUT,
              messages_to_prompt=messages_to_prompt,
          )
          # TODO(qu): _embed_model = HuggingFaceEmbedding(model_name="WhereIsAI/UAE-Large-V1")
          _embed_model = OpenAIEmbedding()
      else:
          raise ValueError(f"Service {llm_service} not supported")
  
      logger.info(f"Loading embedded model {_embed_model.model_name} \n")
      logger.info(f"Loading llm model {_llm.model} \n")
  
      return _llm, _embed_model
  
apis: llama_index.llms.AzureOpenAI llama_index.embeddings.AzureOpenAIEmbedding llama_index.llms.OpenAILike llama_index.llms.OpenAI llama_index.embeddings.OpenAIEmbedding
extract_api: [((353, 366), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (364, 366), False, 'from dotenv import load_dotenv\n'), ((550, 584), 'os.getenv', 'os.getenv', (['"""AZURE_OPENAI_GPT4_KEY"""'], {}), "('AZURE_OPENAI_GPT4_KEY')\n", (559, 584), False, 'import os\n'), ((1760, 1777), 'llama_index.embeddings.OpenAIEmbedding', 'OpenAIEmbedding', ([], {}), '()\n', (1775, 1777), False, 'from llama_index.embeddings import AzureOpenAIEmbedding, OpenAIEmbedding\n'), ((1804, 1831), 'os.getenv', 'os.getenv', (['"""OPENAI_API_KEY"""'], {}), "('OPENAI_API_KEY')\n", (1813, 1831), False, 'import os\n'), ((1847, 1917), 'llama_index.llms.OpenAI', 'OpenAI', ([], {'temperature': 'llm_temperature', 'model': '_llm_model', 'timeout': 'timeout'}), '(temperature=llm_temperature, model=_llm_model, timeout=timeout)\n', (1853, 1917), False, 'from llama_index.llms import AzureOpenAI, OpenAI, OpenAILike\n'), ((971, 1005), 'os.getenv', 'os.getenv', (['"""AZURE_OPENAI_GPT4_KEY"""'], {}), "('AZURE_OPENAI_GPT4_KEY')\n", (980, 1005), False, 'import os\n'), ((2055, 2263), 'llama_index.llms.AzureOpenAI', 'AzureOpenAI', ([], {'model': '_llm_model', 'deployment_name': '_azure_deployment_name', 'api_key': '_azure_openai_key', 'azure_endpoint': '_azure_endpoint', 'api_version': 'api_version', 'temperature': 'llm_temperature', 'timeout': 'timeout'}), '(model=_llm_model, deployment_name=_azure_deployment_name,\n    api_key=_azure_openai_key, azure_endpoint=_azure_endpoint, api_version=\n    api_version, temperature=llm_temperature, timeout=timeout)\n', (2066, 2263), False, 'from llama_index.llms import AzureOpenAI, OpenAI, OpenAILike\n'), ((2470, 2660), 'llama_index.embeddings.AzureOpenAIEmbedding', 'AzureOpenAIEmbedding', ([], {'model': '"""text-embedding-ada-002"""', 'deployment_name': '_azure_ada_deployment_name', 'api_key': '_azure_openai_key', 'azure_endpoint': '_azure_endpoint', 'api_version': 'api_version'}), "(model='text-embedding-ada-002', deployment_name=\n    _azure_ada_deployment_name, api_key=_azure_openai_key, azure_endpoint=\n    _azure_endpoint, api_version=api_version)\n", (2490, 2660), False, 'from llama_index.embeddings import AzureOpenAIEmbedding, OpenAIEmbedding\n'), ((1337, 1371), 'os.getenv', 'os.getenv', (['"""AZURE_OPENAI_GPT4_KEY"""'], {}), "('AZURE_OPENAI_GPT4_KEY')\n", (1346, 1371), False, 'import os\n'), ((2832, 3146), 'llama_index.llms.OpenAILike', 'OpenAILike', ([], {'max_tokens': '(4096)', 'temperature': '(0.9)', 'api_key': '"""localai_fake"""', 'api_version': '"""localai_fake"""', 'api_base': 'f"""http://{args.local_llm_address}:{args.local_llm_port}/v1"""', 'model': '"""local llm"""', 'is_chat_model': '(True)', 'timeout': 'MAC_M1_LUNADEMO_CONSERVATIVE_TIMEOUT', 'messages_to_prompt': 'messages_to_prompt'}), "(max_tokens=4096, temperature=0.9, api_key='localai_fake',\n    api_version='localai_fake', api_base=\n    f'http://{args.local_llm_address}:{args.local_llm_port}/v1', model=\n    'local llm', is_chat_model=True, timeout=\n    MAC_M1_LUNADEMO_CONSERVATIVE_TIMEOUT, messages_to_prompt=messages_to_prompt\n    )\n", (2842, 3146), False, 'from llama_index.llms import AzureOpenAI, OpenAI, OpenAILike\n'), ((3358, 3375), 'llama_index.embeddings.OpenAIEmbedding', 'OpenAIEmbedding', ([], {}), '()\n', (3373, 3375), False, 'from llama_index.embeddings import AzureOpenAIEmbedding, OpenAIEmbedding\n')]