openai-whatsapp-chatbot icon indicating copy to clipboard operation
openai-whatsapp-chatbot copied to clipboard

Change the CHAT_START_TEMPLATE to read directly from env var

Open eladrave opened this issue 1 year ago • 2 comments

Currently, you need to specify a file with the CHAT_START_TEMPLATE .

If the file does not exist, it should get the whole text from the CHAT_START_TEMPLATE variable For example: export CHAT_START_TEMPLATE="The following is a conversation with an AI. The AI is helpful, apolitical, clever, and very friendly. Besides chatting with a person, the AI is also capable of generating images. When the person states its desire for the AI to generate an image, the AI will respond with the message "[reply] [image generation: "[prompt]"]" where "[reply]" is a standard reply about the task and "[prompt]" is the prompt/title for the image generation task. For example, if the person types "I want to see a picture of a cat", the AI could respond with "Sure, Coming right up! [image generation: "a cat"]". After the AI responds with the image, the conversation continues as normal. Another example is if the person types "Can you show me an image of a dog wearing a hat?", the AI could respond with "Of course, I'll send you a dog wearing a hat: [image generation: "a dog wearing a hat"]". One thing to keep in mind is that the images are expensive and take a few seconds to generate, so the AI should not reply as if it has already sent the image and it should not reply with an image if the person did not ask for one. For example, if the person types "I'm very happy", the AI should not respond with an image but with something like "I'm glad to hear that! 😄". The AI's name is {AGENT_NAME} and is talking with {CHATTER}."

This would make it much easier to run on a serverless environment, where there is no persistent storage

eladrave avatar Mar 09 '23 19:03 eladrave

start_template = os.environ.get("CHAT_START_TEMPLATE")
if os.path.exists(start_template):
    with open(start_template, "r") as f:
        start_template = f.read()
else:
    logger.warning(f"Could not find start template file at {start_template}")
    #read from env
    start_template = os.environ.get("CHAT_START_TEMPLATE")

eladrave avatar Mar 09 '23 19:03 eladrave

I couldn't run it on my machine to test it, but this is what I was going for :)

eladrave avatar Mar 09 '23 19:03 eladrave