class_docstr: Integration with the LlamaIndex data framework for LLM applications.
class_docstr_tok: ["Integration","with","the","LlamaIndex","data","framework","for","LLM","applications","."]
code: def _get_service_context(self):
      args = self.model_storage.json_get("args")
      engine_storage = self.engine_storage
  
      key = "OPENAI_API_KEY"
      openai_api_key = get_api_key(
          key,
          "llama_index",
          args["using"],
          engine_storage,
          strict=False,
      )
      if openai_api_key is None:
          openai_api_key = get_api_key(
              key.lower(),
              "llama_index",
              args["using"],
              engine_storage,
              strict=True,
          )
  
      openai.api_key = (
          openai_api_key  # TODO: shouldn't have to do this! bug?
      )
      llm_kwargs = {"openai_api_key": openai_api_key}
      if "temperature" in args["using"]:
          llm_kwargs["temperature"] = args["using"]["temperature"]
      if "model_name" in args["using"]:
          llm_kwargs["model_name"] = args["using"]["model_name"]
      if "max_tokens" in args["using"]:
          llm_kwargs["max_tokens"] = args["using"]["max_tokens"]
  
      llm = OpenAI(
          **llm_kwargs
      )  # TODO: all usual params should go here
      embed_model = OpenAIEmbedding(openai_api_key=openai_api_key)
      service_context = ServiceContext.from_defaults(
          llm_predictor=LLMPredictor(llm=llm), embed_model=embed_model
      )
      return service_context
  
imports: import os
  from typing import Optional, Dict
  import openai
  import pandas
  import llama_index
  from langchain.llms import OpenAI
  from llama_index.readers.schema.base import Document
  from llama_index.readers import SimpleWebPageReader
  from llama_index.prompts import PromptTemplate
  from llama_index import ServiceContext, StorageContext, load_index_from_storage
  from llama_index import LLMPredictor, OpenAIEmbedding
  from llama_index.indices.vector_store.base import VectorStore
  from llama_hub.github_repo import GithubClient, GithubRepositoryReader
  from llama_hub.youtube_transcript import YoutubeTranscriptReader, is_youtube_video
  from mindsdb.integrations.libs.base import BaseMLEngine
  from mindsdb.utilities.config import Config
  from mindsdb.utilities.security import is_private_url
  from mindsdb.integrations.handlers.llama_index_handler import config
  from mindsdb.integrations.handlers.llama_index_handler.github_loader_helper import _get_github_token, _get_filter_file_extensions, _get_filter_directories
  from mindsdb.integrations.utilities.handler_utils import get_api_key
label_desc: Use image node_id 6 for calling the LlamaIndexHandler obj's underlying member method code with example usage: obj._get_service_context() and returns: service_context