Skip to content

Commit

Permalink
fix: always add categories
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli committed Feb 20, 2024
1 parent f80b741 commit 4c06694
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions workers/fund_public_goods/lib/strategy/utils/categorize_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
You must make sure that the categorization of the prompt is extensive enough so projects can be retrieved
based on these categories. ALWAYS return at least 2 categories, even if no direct relation.
You must make sure that the categorization of the prompt is extensive enough so projects can be retrieved
based on these categories.
Some prompts will not be able to be categorized. If that's the case, simply respond with "NONE" (without quotes).
Prompt: {prompt}
"""

Expand All @@ -31,11 +36,19 @@ def categorize_prompt(prompt: str, categories: list[str]) -> list[str]:
"prompt": prompt,
"categories": "\n".join(f"- {category}" for category in categories)
})
categories = [c.strip() for c in categories_res.split(',')]
category_strings = [c.strip() for c in categories_res.split(',')]
result: list[str] = []

for category_string in category_strings:
if category_string == "NONE":
result.append(categories[0])
result.append(categories[1])
else:
result.append(category_string)

if len(categories) == 0:
if len(result) == 0:
raise Exception(
f"The LLM has responded with no categories. Llm response ({categories_res}). Response split ({categories})"
f"The LLM has responded with no categories. Llm response ({categories_res}). Response split ({category_strings})"
)

return categories
return result

0 comments on commit 4c06694

Please sign in to comment.