Skip to content

Commit

Permalink
fix: always return a category
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli committed Feb 20, 2024
1 parent 544da43 commit d9d61e8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 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 @@ -13,7 +13,7 @@
or casing of the categories, return them exactly as they are written in the list above.
You must make sure that the categorization of the prompt is extensive enough so projects can be retrieved
based on these categories.
based on these categories. ALWAYS return at least 2 categories, even if no direct relation.
Prompt: {prompt}
"""
Expand All @@ -27,9 +27,15 @@ def categorize_prompt(prompt: str, categories: list[str]) -> list[str]:

categorize_chain = categorize_prompt | llm | StrOutputParser()

categories = [c.strip() for c in categorize_chain.invoke({
categories_res = categorize_chain.invoke({
"prompt": prompt,
"categories": "\n".join(f"- {category}" for category in categories)
}).split(',')]

})
categories = [c.strip() for c in categories_res.split(',')]

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

return categories

0 comments on commit d9d61e8

Please sign in to comment.