File size: 1,279 Bytes
f745baf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class Postprocessor:
    """Postprocessor."""

    def run(self, text: str) -> str:
        """Postprocess."""
        raise NotImplementedError("Postprocess method is not implemented")

class ClaudePostprocessor(Postprocessor):
    """Claude Postprocessor."""
    def run(self, text: str) -> str:
        """Clean the response from the Claude model.

        Args:
            text (str): The response from the Claude model.

        Returns:
            str: The cleaned response.
        """
        # remove the ```markdown and ``` at the beginning and end of the text
        text = text.replace("```markdown", "").replace("```", "")
        # Remove any leading or trailing whitespace
        text = text.strip()
        return text

class GPTPostprocessor(Postprocessor):
    """GPT Postprocessor."""
    def run(self, text: str) -> str:
        """Clean the response from the GPT model.

        Args:
            text (str): The response from the GPT model.

        Returns:
            str: The cleaned response.
        """
        # remove the ```markdown and ``` at the beginning and end of the text
        text = text.replace("```markdown", "").replace("```", "")
        # Remove any leading or trailing whitespace
        text = text.strip()
        return text