File size: 1,301 Bytes
246d201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
workflow_summary_markers = [
    'WORKFLOW SUMMARY',
    'WORKFLOW_SUMMARY',
    'WORKFLOW-SUMMARY',
    'Workflow Summary',
]

final_answer_markers = [
    'FINAL ANSWER',
    'FINAL_ANSWER',
    'FINAL-ANSWER',
    'Final Answer',
    'Scientific Hypothesis',
    'Hypothesis',
]

next_agent_markers = [
    'NEXT AGENT',
    'NEXT-AGENT',
    'NEXT_AGENT',
    'FEEDBACK',
]


def extract_between(content, start_markers, end_markers=None):
    for marker in start_markers:
        if marker in content:
            result = content.split(marker, 1)[1]
            if end_markers:
                for end_marker in end_markers:
                    if end_marker in result:
                        result = result.split(end_marker, 1)[0]
            return result
    return ''


def extract_gen_hypo_from_logs(content: str):
    error = ''

    gen_workflow = extract_between(
        content, workflow_summary_markers, final_answer_markers
    )

    if not gen_workflow:
        error += 'No Workflow Summary found in the line. | '

    gen_hypothesis = extract_between(content, final_answer_markers, next_agent_markers)

    if not gen_hypothesis:
        error += 'No Final Answer in the line.'

    return gen_hypothesis, gen_workflow, error