Dracomoth's picture
Update exporter.py
7492373
import os
from pathlib import Path
from conversation import conversationAgent
#******************************************************************************************************************************************************************
class exportAgent:
envVariables = None
memory = None
base_prompt = "please generate for me a HTML document with using all information in our conversation and the prior information you have. For this HTML document use the following template: /n/n"
def __init__(self, configuration, buffer):
self.envVariables = configuration
self.memory = buffer
def do_export(self, template_files):
generated_files = []
for template in template_files:
#open the template file and read it
template_file_path = template.name
text = ""
file = open(template_file_path, "r")
text = file.read()
file.close()
#we do the request to OpenAI using the template
agent = conversationAgent()
agent.create_conversation_with_buffer(self.envVariables, self.memory)
prompt = self.base_prompt + text
response = agent.do_conversation(prompt)
#save the response into a new document
generated_file_path = "gen_" + Path(template_file_path).stem + ".html"
file = open(generated_file_path, "w")
file.write(response)
file.close()
generated_files.append(generated_file_path)
return generated_files