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 predict(
      self,
      df: Optional[pd.DataFrame] = None,
      args: Optional[Dict] = None,
  ) -> pd.DataFrame:
      pred_args = args["predict_params"] if args else {}
  
      args = self.model_storage.json_get("args")
      engine_kwargs = {}
  
      if args["using"].get("mode") == "conversational":
          user_column = args["using"]["user_column"]
          assistant_column = args["using"]["assistant_column"]
  
          messages = []
          for row in df[:-1].to_dict("records"):
              messages.append(f"user: {row[user_column]}")
              messages.append(f"assistant: {row[assistant_column]}")
  
          conversation = "\n".join(messages)
  
          questions = [df.iloc[-1][user_column]]
  
          if "prompt" in pred_args and pred_args["prompt"] is not None:
              user_prompt = pred_args["prompt"]
          else:
              user_prompt = args["using"].get("prompt", "")
  
          prompt_template = (
              f"{user_prompt}\n"
              f"---------------------\n"
              f"We have provided context information below. \n"
              f"{{context_str}}\n"
              f"---------------------\n"
              f"This is previous conversation history:\n"
              f"{conversation}\n"
              f"---------------------\n"
              f"Given this information, please answer the question: {{query_str}}"
          )
  
          engine_kwargs["text_qa_template"] = PromptTemplate(
              prompt_template
          )
  
      else:
          input_column = args["using"].get("input_column", None)
  
          prompt_template = args["using"].get(
              "prompt_template", args.get("prompt_template", None)
          )
          if prompt_template is not None:
              _validate_prompt_template(prompt_template)
              engine_kwargs["text_qa_template"] = PromptTemplate(
                  prompt_template
              )
  
          if input_column is None:
              raise Exception(
                  f"`input_column` must be provided at model creation time or through USING clause when predicting. Please try again."
              )  # noqa
  
          if input_column not in df.columns:
              raise Exception(
                  f'Column "{input_column}" not found in input data! Please try again.'
              )
  
          questions = df[input_column]
  
      index_path = self.model_storage.folder_get("context")
      storage_context = StorageContext.from_defaults(
          persist_dir=index_path
      )
      service_context = self._get_service_context()
      index = load_index_from_storage(
          storage_context, service_context=service_context
      )
      query_engine = index.as_query_engine(**engine_kwargs)
  
      results = []
  
      for question in questions:
          query_results = query_engine.query(
              question
          )  # TODO: provide extra_info in explain_target col
          results.append(query_results.response)
  
      result_df = pd.DataFrame(
          {"question": questions, args["target"]: results}
      )  # result_df['answer'].tolist()
      return result_df
  
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 5 for calling the LlamaIndexHandler obj's underlying member method code with example usage: obj.predict(df, args) and returns: result_df