Skip to content

Commit

Permalink
avoiding questions from being none
Browse files Browse the repository at this point in the history
  • Loading branch information
surcyf123 committed Dec 16, 2023
1 parent e3a3668 commit ca4a848
Show file tree
Hide file tree
Showing 6 changed files with 18,082 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bittensor_subnet_template.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: bittensor-subnet-template
Version: 2.6.3
Version: 2.6.4
Summary: bittensor_subnet_template
Home-page: https://github.com/opentensor/bittensor-subnet-template
Author: bittensor.com
Expand Down
2 changes: 1 addition & 1 deletion state.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


# version must stay on line 22
__version__ = "2.6.4"
__version__ = "2.6.5"
version_split = __version__.split(".")
__spec_version__ = (
(1000 * int(version_split[0]))
Expand Down
Binary file modified template/__pycache__/utils.cpython-310.pyc
Binary file not shown.
32 changes: 15 additions & 17 deletions template/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,14 @@ async def get_list(list_type, num_questions_needed, theme=None):
"prompt": f"Provide a python-formatted list of {prompts_in_question[list_type]} creative and detailed scenarios for image generation, each inspired by the theme '{theme}'. The scenarios should be diverse, thoughtful, and possibly out-of-the-box interpretations related to '{theme}'. Each element in the list should be a concise, but a vividly descriptive situation designed to inspire visually rich stories. Format these elements as comma-separated, quote-encapsulated strings in a single Python list."
}
}

selected_prompts = []
if list_type == "text_questions":
question_pool = []
for theme in template.INSTRUCT_DEFAULT_THEMES:
for complexity_level in range(1, 11):
for relevance_level in range(1, 11):
prompt = f"Generate a python-formatted list of {prompts_in_question[list_type]} questions or instruct tasks related to the theme '{theme}', each with a complexity level of {complexity_level} out of 10 and a relevance level to the theme of {relevance_level} out of 10. These tasks should varyingly explore {theme} in a manner that is consistent with their assigned complexity and relevance levels to the theme, allowing for a diverse and insightful engagement about {theme}. Format the questions as comma-separated, quote-encapsulated strings in a single Python list."
question_pool.append(prompt)
for complexity_level in range(1, 21):
for relevance_level in range(1, 21):
prompt = f"Generate a python-formatted list of {prompts_in_question[list_type]} questions or instruct tasks related to the theme '{theme}', each with a complexity level of {complexity_level} out of 20 and a relevance level to the theme of {relevance_level} out of 20. These tasks should varyingly explore {theme} in a manner that is consistent with their assigned complexity and relevance levels to the theme, allowing for a diverse and insightful engagement about {theme}. Format the questions as comma-separated, quote-encapsulated strings in a single Python list."
question_pool.append(prompt)

random.shuffle(question_pool)
num_questions_to_select = min(math.ceil(num_questions_needed / prompts_in_question[list_type]), len(question_pool))
Expand All @@ -97,10 +96,8 @@ async def get_list(list_type, num_questions_needed, theme=None):
]

responses = await asyncio.gather(*tasks)

extracted_lists = []
max_retries = 5

for i, answer in enumerate(responses):
try:
answer = answer.replace("\n", " ") if answer else ""
Expand All @@ -119,14 +116,15 @@ async def get_list(list_type, num_questions_needed, theme=None):
if new_extracted_list:
extracted_lists += new_extracted_list
break
else: bt.logging.error(f"no list found in {new_answer}")
except Exception as e:
bt.logging.error(f"Exception on retry {retry + 1} for prompt '{selected_prompts[i]}': {e}\n{traceback.format_exc()}")
except Exception as e:
bt.logging.error(f"Exception in processing initial response for prompt '{selected_prompts[i]}': {e}\n{traceback.format_exc()}")

if not extracted_lists:
bt.logging.error(f"No valid lists found after processing and retries, using default list.")
return template.INSTRUCT_DEFAULT_QUESTIONS
bt.logging.error(f"No valid lists found after processing and retries, returning None")
return None

return extracted_lists

Expand All @@ -140,18 +138,18 @@ async def get_items(category, item_type, theme=None):
else:
return template.INSTRUCT_DEFAULT_THEMES
else:
# Ensure theme is always available for 'questions'
if theme is None:
theme = await get_current_theme(category)

return await get_list(f"{category}_questions", num_questions_needed, theme)
# Never fail here, retry until valid list is found
while True:
theme = await get_random_theme(category)
if theme is not None:
return await get_list(f"{category}_questions", num_questions_needed, theme)

async def get_current_theme(category):
async def get_random_theme(category):
themes = state[category]["themes"]
if not themes:
themes = await get_items(category, "themes")
state[category]["themes"] = themes
return themes.pop() if themes else None
return random.choice(themes)

list_type = f"{category}_{item_type}"

Expand Down
Loading

0 comments on commit ca4a848

Please sign in to comment.