code: import json
  from typing import Sequence
  
  from llama_index.legacy.prompts.base import PromptTemplate
  from llama_index.legacy.question_gen.types import SubQuestion
  from llama_index.legacy.tools.types import ToolMetadata
  
  # deprecated, kept for backward compatibility
  SubQuestionPrompt = PromptTemplate
  
  
  def build_tools_text(tools: Sequence[ToolMetadata]) -> str:
      tools_dict = {}
      for tool in tools:
          tools_dict[tool.name] = tool.description
      return json.dumps(tools_dict, indent=4)
  
  
  PREFIX = """\
  Given a user question, and a list of tools, output a list of relevant sub-questions \
  in json markdown that when composed can help answer the full user question:
  
  """
  
  
  example_query_str = (
      "Compare and contrast the revenue growth and EBITDA of Uber and Lyft for year 2021"
  )
  example_tools = [
      ToolMetadata(
          name="uber_10k",
          description="Provides information about Uber financials for year 2021",
      ),
      ToolMetadata(
          name="lyft_10k",
          description="Provides information about Lyft financials for year 2021",
      ),
  ]
  example_tools_str = build_tools_text(example_tools)
  example_output = [
      SubQuestion(
          sub_question="What is the revenue growth of Uber", tool_name="uber_10k"
      ),
      SubQuestion(sub_question="What is the EBITDA of Uber", tool_name="uber_10k"),
      SubQuestion(
          sub_question="What is the revenue growth of Lyft", tool_name="lyft_10k"
      ),
      SubQuestion(sub_question="What is the EBITDA of Lyft", tool_name="lyft_10k"),
  ]
  example_output_str = json.dumps({"items": [x.dict() for x in example_output]}, indent=4)
  
  EXAMPLES = f"""\
  # Example 1
  <Tools>
  ```json
  {example_tools_str}
  ```
  
  <User Question>
  {example_query_str}
  
  
  <Output>
  ```json
  {example_output_str}
  ```
  
  """.replace(
      "{", "{{"
  ).replace(
      "}", "}}"
  )
  
  SUFFIX = """\
  # Example 2
  <Tools>
  ```json
  {tools_str}
  ```
  
  <User Question>
  {query_str}
  
  <Output>
  """
  
  DEFAULT_SUB_QUESTION_PROMPT_TMPL = PREFIX + EXAMPLES + SUFFIX
  
apis: llama_index.legacy.question_gen.types.SubQuestion llama_index.legacy.tools.types.ToolMetadata
extract_api: [((465, 497), 'json.dumps', 'json.dumps', (['tools_dict'], {'indent': '(4)'}), '(tools_dict, indent=4)\n', (475, 497), False, 'import json\n'), ((817, 923), 'llama_index.legacy.tools.types.ToolMetadata', 'ToolMetadata', ([], {'name': '"""uber_10k"""', 'description': '"""Provides information about Uber financials for year 2021"""'}), "(name='uber_10k', description=\n    'Provides information about Uber financials for year 2021')\n", (829, 923), False, 'from llama_index.legacy.tools.types import ToolMetadata\n'), ((947, 1053), 'llama_index.legacy.tools.types.ToolMetadata', 'ToolMetadata', ([], {'name': '"""lyft_10k"""', 'description': '"""Provides information about Lyft financials for year 2021"""'}), "(name='lyft_10k', description=\n    'Provides information about Lyft financials for year 2021')\n", (959, 1053), False, 'from llama_index.legacy.tools.types import ToolMetadata\n'), ((1150, 1239), 'llama_index.legacy.question_gen.types.SubQuestion', 'SubQuestion', ([], {'sub_question': '"""What is the revenue growth of Uber"""', 'tool_name': '"""uber_10k"""'}), "(sub_question='What is the revenue growth of Uber', tool_name=\n    'uber_10k')\n", (1161, 1239), False, 'from llama_index.legacy.question_gen.types import SubQuestion\n'), ((1254, 1330), 'llama_index.legacy.question_gen.types.SubQuestion', 'SubQuestion', ([], {'sub_question': '"""What is the EBITDA of Uber"""', 'tool_name': '"""uber_10k"""'}), "(sub_question='What is the EBITDA of Uber', tool_name='uber_10k')\n", (1265, 1330), False, 'from llama_index.legacy.question_gen.types import SubQuestion\n'), ((1336, 1425), 'llama_index.legacy.question_gen.types.SubQuestion', 'SubQuestion', ([], {'sub_question': '"""What is the revenue growth of Lyft"""', 'tool_name': '"""lyft_10k"""'}), "(sub_question='What is the revenue growth of Lyft', tool_name=\n    'lyft_10k')\n", (1347, 1425), False, 'from llama_index.legacy.question_gen.types import SubQuestion\n'), ((1440, 1516), 'llama_index.legacy.question_gen.types.SubQuestion', 'SubQuestion', ([], {'sub_question': '"""What is the EBITDA of Lyft"""', 'tool_name': '"""lyft_10k"""'}), "(sub_question='What is the EBITDA of Lyft', tool_name='lyft_10k')\n", (1451, 1516), False, 'from llama_index.legacy.question_gen.types import SubQuestion\n')]