class_docstr: A class for using a RAG model for question answering
class_docstr_tok: ["A","class","for","using","a","RAG","model","for","question","answering"]
docstr: Extract generated text from LLM response
docstr_tok: ["Extract","generated","text","from","LLM","response"]
code: def extract_generated_text(response: str) -> str:
      """Extract generated text from LLM response"""
  
      if isinstance(response, str):
          data = json.loads(response)
      else:
          data = response
  
      try:
          if "choices" in data:
              return data["choices"][0]["text"]
          else:
              logger.info(
                  f"Error extracting generated text: failed to parse response {response}"
              )
              return response
  
      except Exception as e:
          raise Exception(
              f"{e} Error extracting generated text: failed to parse response {response}"
          )
  
file_path: mindsdb/mindsdb/integrations/handlers/rag_handler/rag.py
imports: import json
  from collections import defaultdict
  from typing import List
  from mindsdb.integrations.handlers.rag_handler.settings import LLMLoader, PersistedVectorStoreLoader, PersistedVectorStoreLoaderConfig, RAGBaseParameters, RAGHandlerParameters, load_embeddings_model
  from mindsdb.utilities import log
label_desc: Use image node_id 6 for calling the RAGQuestionAnswerer obj's underlying member method code with example usage: obj.extract_generated_text(response) and returns: data, response