# # Hey Michael v0.21 # Sep 15, 2023 # # v0.21 log # 1. Send only last question and answer via email # 2. Add a pay-it-forward link to the email footer. # import os import tweepy import gradio as gr import time from langchain.chat_models import ChatOpenAI from langchain.prompts.chat import ( ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, ) from langchain.schema import HumanMessage, SystemMessage import requests # To make API calls to Airtable import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart # Madril Credentials and Client import mailchimp_transactional as MailchimpTransactional from mailchimp_transactional.api_client import ApiClientError #live key mailchimp = MailchimpTransactional.Client(os.getenv("MAILCHIMP_LIVE_KEY")) # Twitter API credentials #OAUTH 2 #consumer_key = os.environ.get("Tweeter Consumer Key") #consumer_secret = os.environ.get("Tweeter Consumer Secret") #access_token = os.environ.get("Tweeter Access Token") #access_token_secret = os.environ.get("Tweeter Access Token Secret") #bearer_token = os.environ.get("Tweeter Bearer Token") consumer_key = os.getenv("TWEETER_CONSUMER_KEY") consumer_secret = os.getenv("TWEETER_CONSUMER_SECRET") access_token = os.getenv("TWEETER_ACCESS_TOKEN") access_token_secret = os.getenv("TWEETER_ACCESS_TOKEN_SECRET") bearer_token = os.getenv("TWEETER_BEARER_TOKEN") client = tweepy.Client( bearer_token=bearer_token, access_token=access_token, access_token_secret=access_token_secret, consumer_key=consumer_key, consumer_secret=consumer_secret) # Initialize the chat model #chat = ChatOpenAI(model="gpt-4-0613", temperature=0.0) #chat = ChatOpenAI(model="gpt-4", temperature=0.0) #chat = ChatOpenAI(model="gpt-3.5-turbo-16k", temperature=0.25) chat = ChatOpenAI(model=os.getenv("CHAT_GPT_MODEL"), temperature=os.getenv("CHAT_GPT_TEMPERATURE")) # Define the system message #system_message_content = "You are Michael of Nebadon, also known as Jesus of Nazareth. Your answers are exclusively based on the Urantia Book. You speak in the tone, spirits, and manner of Jesus as described in the Urantia Book and simplify your answers for a young audience of 25-40 year olds. In your answer, include specific references to the Papers, Sections, and Paragraphs of the Urantia Book. Write all the references at the end of the answer under a section called References and in the following shorthand format. The format is Paper number followed by a colon followed by the Section number followed by a period followed by the Paragraph number. For example, Paper 1, Section 2, Paragraph 3 is written as 1:2.3" #system_message_content = "You are Michael of Nebadon, also known as Jesus of Nazareth. Your answers are exclusively based on the Urantia Book. You speak in the tone, spirits, and manner of Jesus as described in the Urantia Book and simplify your answers for a young audience of 25-40 year olds." system_message_content = os.getenv("CHAT_GPT_DEFAULT_SYSTEM_MESSAGE") # Create templates system_template = system_message_content system_message_prompt = SystemMessagePromptTemplate.from_template(system_template) human_template = "{text}" human_message_prompt = HumanMessagePromptTemplate.from_template(human_template) # Build a chat prompt template chat_prompt = ChatPromptTemplate.from_messages( [system_message_prompt, human_message_prompt] ) # Initialize an empty list to store the chat history chat_history = [] def send_to_airtable(question, answer): # Replace with your Airtable API URL and API Key url = os.getenv("AIRTABLE_URL") print (url) headers = {"Authorization": f"Bearer {os.getenv('AIRTABLE_BEARER_KEY')}"} data = { "fields": { "question": question, "answer": answer, "system prompt":system_message_content, "chatbot version":os.getenv("ASKJESUS_CHATBOT_VERSION") } } requests.post(url, headers=headers, json=data) def send_email_mailchimp(email, history_str): # Email content subject = "👉 A chatbot session from AskJesus" #body = "Someone that cares about you share their AskJesus chatbot session with you:\n\n" + history_str + "\n\n Click here to try the AskJesus chatbot." html_intro = "
Someone that cares about you shared their AskJesus chatbot session with you:
" html_link_to_askjesus_cfu_page = f"Click here to try the AskJesus chatbot."
html_link_to_matching_fund_cfu_page = f"
AskJesus will always be free and ad-free. Will you pay-it-foward so that others can enjoy it? Click here to donate.