Spaces:
Runtime error
Runtime error
| '''def qStr2Dict(question: str) -> dict: | |
| print('qStr2Dict :', question) | |
| split = question.strip(" '\"").split(".", 1) | |
| question_dict = {'id': int(split[0]), 'question': split[-1].strip()} | |
| return question_dict | |
| def result2QuestionsList(question_response: str, type: str, status: str) -> list: | |
| response_splits = question_response.split("\n") | |
| qlist = [] | |
| for q in response_splits: | |
| question = {**qStr2Dict(q), 'type': type, 'status': status, 'answer': None} | |
| qlist = qlist + [question] | |
| return qlist | |
| ''' | |
| def qStr2Dict(question: str) -> dict: | |
| try: | |
| print('qStr2Dict:', question) | |
| split = question.strip(" '\"").split(".", 1) | |
| # Check if id_part is 'Here are the sub-questions:', set it to integer 1 | |
| id_part = split[0].replace("#", "").strip() | |
| if isinstance(id_part, str): | |
| id_part = 1 # Convert any string to integer 1 | |
| # Convert id_part to integer, if not empty | |
| id_part = int(id_part) if id_part else None | |
| question_dict = {'id': id_part, 'question': split[-1].strip()} | |
| return question_dict | |
| except ValueError as e: | |
| print("Error:", e) | |
| return {'id': None, 'question': question.strip()} | |
| def result2QuestionsList(question_response: str, type: str, status: str) -> list: | |
| response_splits = question_response.split("\n") | |
| qlist = [] | |
| for q in response_splits: | |
| # Skip empty lines | |
| if q.strip() == '': | |
| continue | |
| question = qStr2Dict(q) | |
| question.update({'type': type, 'status': status, 'answer': None}) | |
| qlist.append(question) | |
| return qlist |