Spaces:
Sleeping
Sleeping
| import re | |
| from form.form import work_categories | |
| class LlmParser: | |
| _verification_prompt_answers_regex = re.compile(r"\|\s*([^|]*)\s?", re.MULTILINE) | |
| def parse_verification_prompt_answers(cls, llm_answer) -> dict[int, str | None]: | |
| print(f"llm answer: {llm_answer}") | |
| expected_answers_count = 13 | |
| answers = {} | |
| i = 0 | |
| question_id = 0 | |
| lines = [l for l in llm_answer.split("\n") if len(l.strip()) > 0] | |
| while i < len(lines): | |
| line = lines[i].strip() | |
| if len(line) == 0: | |
| i += 1 | |
| elif line.endswith("?") and i+1<len(lines): | |
| i+=1 | |
| elif "null" in lines[i]: | |
| answers[question_id] = None | |
| i += 1 | |
| question_id += 1 | |
| elif ":" in lines[i]: | |
| answers[question_id] = line.split(":")[1] | |
| i += 1 | |
| question_id += 1 | |
| else: | |
| answers[question_id] = line | |
| i+=1 | |
| question_id += 1 | |
| return answers | |
| def parse_get_categories_answer(cls, category_answer) -> list[str]: | |
| categories = [] | |
| for category in category_answer.split(";"): | |
| categories.extend([k for k, v in work_categories.items() if category.lower() in v.lower()]) | |
| return categories | |