Parser error in L5-Evaluation (solved)

I am using LangChain 0.0.196 on my local machine and get the following error:


It seems that there is a problem with the parser. So I just run “apply” only instead and write a parser by myself (actually ChatGPT :D)

def parse_strings(strings_list):
    parsed_list = []
    
    for s in strings_list:
        split_s = s.split('\n')
        
        # Ensure there are 2 parts in the split string
        if len(split_s) != 2:
            continue
        
        question_part, answer_part = split_s
        
        # Ensure each part has the correct prefix
        if not question_part.startswith('QUESTION: ') or not answer_part.startswith('ANSWER: '):
            continue
        
        # Remove the prefixes and strip leading/trailing whitespace
        question = question_part.replace('QUESTION: ', '').strip()
        answer = answer_part.replace('ANSWER: ', '').strip()
        
        parsed_list.append({"query": question, "answer": answer})
    
    return parsed_list

new_examples = example_gen_chain.apply([{"doc": t} for t in data[:5]])
print(new_examples)

new_examples = parse_strings([t['text'] for t in new_examples])
print(new_examples)
3 Likes

hi, soarshi, how do you use GPT to write the parser?