File size: 2,647 Bytes
258e7ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import Any, Dict, List
from flow_modules.Tachi67.ExtendLibraryFlowModule import ControllerFlow_ExtLib


from dataclasses import dataclass


@dataclass
class Command:
    name: str
    description: str
    input_args: List[str]

class Controller_CoderFlow(ControllerFlow_ExtLib):
    def __init__(
            self,
            commands: List[Command],
            **kwargs):
        super().__init__(**kwargs)
        self.system_message_prompt_template = self.system_message_prompt_template.partial(
            commands=self.build_commands_manual(commands),
            plan="no plans yet",
            plan_file_location="no location yet",
            code_library="no code library yet",
            code_library_location="no location yet",
            logs="no logs yet",
        )
        self.hint_for_model = """
        Make sure your response is in the following format:
              Response Format:
              {
              "command": "call one of the subordinates",
              "command_args": {
                  "arg name": "value"
                  }
              }
        """

    def _get_code_library_location(self, input_data):
        assert "memory_files" in input_data, "memory_files not passed to Coder/Controller"
        assert "code_library" in input_data["memory_files"], "code_library not in memory files"
        return input_data["memory_files"]["code_library"]

    def _get_code_library_content(self, input_data):
        assert "code_library" in input_data, "code_library not passed to Coder/Controller"
        code_library_content = input_data["code_library"]
        if len(code_library_content) == 0:
            code_library_content = 'No plan yet'
        return code_library_content

    def _update_prompts_and_input(self, input_data: Dict[str, Any]):
        if 'goal' in input_data:
            input_data['goal'] += self.hint_for_model
        if 'result' in input_data:
            input_data['result'] += self.hint_for_model
        plan_file_location = self._get_plan_file_location(input_data)
        plan_content = self._get_plan_content(input_data)
        code_library_location = self._get_code_library_location(input_data)
        code_library_content = self._get_code_library_content(input_data)
        logs_content = self._get_logs_content(input_data)
        self.system_message_prompt_template = self.system_message_prompt_template.partial(
            plan_file_location=plan_file_location,
            plan=plan_content,
            code_library_location=code_library_location,
            code_library=code_library_content,
            logs=logs_content
        )