Skip to content

Commit

Permalink
Merge pull request #208 from polywrap/release/dev
Browse files Browse the repository at this point in the history
merge release/dev
  • Loading branch information
dOrgJelli committed Feb 20, 2024
2 parents 4663213 + 8d2d413 commit 498c0d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
5 changes: 4 additions & 1 deletion workers/fund_public_goods/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def sqs_handler(sqs_event: SQSEvent, _: Context):
))

for event in events:
handler(event)
try:
handler(event)
except Exception as error:
print(error)

def add_event_middleware(app: FastAPI):
event_handlers: list[BaseEventHandler] = []
Expand Down
28 changes: 20 additions & 8 deletions workers/fund_public_goods/lib/strategy/utils/categorize_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
Respond strictly with a comma-separated list of categories, without quotes. Do not change the wording
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. ALWAYS return at least 2 categories, even if no direct relation.
A user's prompt can match to more than one category. Be strict with assigning categories.
Return a max of {n} categories, you can reutrn less if the project really only matches less than {n} 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 @@ -29,13 +31,23 @@ def categorize_prompt(prompt: str, categories: list[str]) -> list[str]:

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

if len(categories) == 0:
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])
result.append(categories[2])
else:
result.append(category_string)

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 498c0d9

Please sign in to comment.