File size: 3,128 Bytes
e048cbb
 
2158804
e048cbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from abc import ABC, abstractmethod
from typing import List
from src.llm.data_models.typeddict_data_models import MultiCommentModel
from src.llm.prompts.prompt_head import (
    prompt_head_expert,
    prompt_head_jarvis,
    prompt_head_novice,
    prompt_head_natural,
    prompt_head_generic,
)
from src.llm.prompts.prompt_core import prompt_core


class BaseLLMWrapper(ABC):
    def comment(
        self,
        character: str,
        game,
        comment_refs: List[int],
        move_nums: List,
        played_moves: List,
        played_by: List,
        comments: List,
        move_suggestions: List,
        pre_eval_scores: List,
        post_eval_scores: List,
    ) -> MultiCommentModel:
        """
        Rewrite the comment in a specific tone or style.

        Args:
            character (str): The character or style in which to rewrite the comment.
            move_nums (List): List of move numbers corresponding to the comments.
            comments (List): List of comments to be rewritten.
            move_suggestions (List): List of suggested moves, if any.
        Returns:
            MultiCommentModel: A model containing the rewritten comments.

        """
        character = character.lower().strip()
        if character == "natural":
            prompt_head = prompt_head_natural
        elif character == "jarvis":
            prompt_head = prompt_head_jarvis
        elif character == "novice":
            prompt_head = prompt_head_novice
        elif character == "expert":
            prompt_head = prompt_head_expert
        else:
            prompt_head = prompt_head_generic.format(character=character)

        comments_info = []
        for (
            comment_ref,
            move_num,
            played_move,
            played_by_player,
            comment,
            suggestion,
            pre_eval_score,
            post_eval_score,
        ) in zip(
            comment_refs,
            move_nums,
            played_moves,
            played_by,
            comments,
            move_suggestions,
            pre_eval_scores,
            post_eval_scores,
        ):
            comments_info.append(
                {
                    "comment_ref": comment_ref,
                    "move_num": move_num,
                    "move": played_move,
                    "played_by": played_by_player,
                    "comment": comment,
                    "better_variation": suggestion,
                    "score_before_move": pre_eval_score,
                    "score_after_move": post_eval_score,
                }
            )

        prompt = (
            prompt_head + "\n" + prompt_core.format(pgn=game, comments=comments_info)
        )

        response = self.generate_response(prompt)

        return response

    @abstractmethod
    def generate_response(self, prompt: str) -> MultiCommentModel:
        """
        Generate a response based on the provided prompt.

        Args:
            prompt (str): The input prompt to generate a response for.

        Returns:
            str: The generated response.
        """
        pass