File size: 2,512 Bytes
bfb63a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#@title JSON log system prompt management

class LLMPrompts:
    def __init__(self, log_file):
        self.prompts = []
        self.log_file = log_file
        self.load_prompts_from_log()

    def add_prompt(self, identity, prompt, temperature):
        self.prompts.append({'identity': identity, 'prompt': prompt, 'temperature': temperature})
        self.save_prompts_to_log()

    def remove_prompt(self, identity):
        self.prompts = [p for p in self.prompts if p['identity'] != identity]
        self.save_prompts_to_log()

    def get_prompt(self, identity):
        for prompt in self.prompts:
            if prompt['identity'] == identity:
                return prompt['prompt']
        return None

    def get_temperature(self, identity):
        for prompt in self.prompts:
            if prompt['identity'] == identity:
                return prompt['temperature']
        return None

    def load_prompts_from_log(self):
        try:
            with open(self.log_file, 'r') as file:
                self.prompts = json.load(file)
        except FileNotFoundError:
            print("No file found. Starting from scratch.")
            pass  # Ignore if the log file is not found or cannot be read

    def save_prompts_to_log(self):
        with open(self.log_file, 'w') as file:
            json.dump(self.prompts, file)
            
# Accessing prompts and temperatures
# print(llm_prompts.get_prompt("LLM_2"))  # Output: Write a short story about a detective solving a mysterious murder case.
# print(llm_prompts.get_temperature("LLM_2"))  # Output: 0.7


# Adding a new prompt with temperature
# llm_prompts.add_prompt("LLM_5", "Explain the concept of artificial intelligence.", 0.5)

# Set the filepath for the log
log_file_path = '/drive/My Drive/Colab Notebooks/llm_prompts_log.json'
sys_prompt = LLMPrompts(log_file_path)

# Print all prompts and temperatures
for prompt in sys_prompt.prompts:
   print(prompt['identity'], prompt['prompt'], prompt['temperature'])

# Want to add personas? Do that here!

# sys_prompt.add_prompt('LLM_2', "")




# Log the last conversation
convo_log_file_path = '/drive/My Drive/Colab Notebooks/last_conversation.json'

# Convert list to JSON object
json_object = json.dumps(context)

# Save JSON object to a file
with open('output.json', 'w') as file:
    file.write(json_object)

# Save list items as separate lines in a JSON
# with open(convo_log_file_path, 'w') as file:
#     for item in context:
#         file.write(json.dumps(item) + '\n')