|
|
|
|
|
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 |
|
|
|
def save_prompts_to_log(self): |
|
with open(self.log_file, 'w') as file: |
|
json.dump(self.prompts, file) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log_file_path = '/drive/My Drive/Colab Notebooks/llm_prompts_log.json' |
|
sys_prompt = LLMPrompts(log_file_path) |
|
|
|
|
|
for prompt in sys_prompt.prompts: |
|
print(prompt['identity'], prompt['prompt'], prompt['temperature']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
convo_log_file_path = '/drive/My Drive/Colab Notebooks/last_conversation.json' |
|
|
|
|
|
json_object = json.dumps(context) |
|
|
|
|
|
with open('output.json', 'w') as file: |
|
file.write(json_object) |
|
|
|
|
|
|
|
|
|
|