Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge release/prod #207

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading