diff --git a/Config/config.py b/Config/config.py index d209556..81e3a1a 100644 --- a/Config/config.py +++ b/Config/config.py @@ -14,7 +14,7 @@ def get_config(config_file_path): Returns: _type_: _description_ """ - """Read configuration from file and environment variables. + """Read configuration from file and environment variables. :param str config_file_path: path to the configuration file :return: configuration values as a dictionary @@ -22,7 +22,7 @@ def get_config(config_file_path): """ config = configparser.ConfigParser() # read from file - config.read(config_file_path, encoding="utf-8") + config.read(config_file_path, encoding="latin-1") config.__dict__ # read from environment variables @@ -63,9 +63,13 @@ def configure_logging(): if not os.path.isdir("Logs"): os.makedirs("Logs") - if not os.path.exists(os.path.join("Logs", "traceback.log")): - with open(os.path.join("Logs", "traceback.log"), "w") as fp: - fp.write("Created traceback.log as part of tests.") + if not os.path.exists(os.path.join("Logs", "shlokai.log")): + with open(os.path.join("Logs", "shlokai.log"), "w") as fp: + fp.write("Created shlokai.log as part of tests.") + fp.close() + if not os.path.exists(os.path.join("Logs", "shlokai.debug")): + with open(os.path.join("Logs", "shlokai.debug"), "w") as fp: + fp.write("Created shlokai.debug as part of tests.") fp.close() # Define log format @@ -94,4 +98,4 @@ def configure_logging(): # Set root logger level logging.root.setLevel(logging.DEBUG) - return logging_config + return logging_config \ No newline at end of file diff --git a/Config/logger.ini b/Config/logger.ini index aa47a03..5f7430e 100644 --- a/Config/logger.ini +++ b/Config/logger.ini @@ -5,12 +5,12 @@ production = False level = INFO handler = console,file formatter = default -output = Logs/traceback.log -debug_emoji = 🐛 -info_emoji = 💡 -warning_emoji = ⚠️ -error_emoji = 🚨 -critical_emoji = 💣 +output = Logs/shlokai.log +#debug_emoji = � +#info_emoji = � +#warning_emoji = ⚠️ +#error_emoji = � +#critical_emoji = � [handlers] keys = console,file @@ -26,7 +26,7 @@ args = (sys.stdout,) [handler_file] class = handlers.RotatingFileHandler -args = Logs/traceback.log +args = Logs/shlokai.debug level = DEBUG formatter = default mode = a diff --git a/docs/promo.md b/docs/promo.md new file mode 100644 index 0000000..6a7a4f1 --- /dev/null +++ b/docs/promo.md @@ -0,0 +1,49 @@ +# Youtube +## Youtube Video Description +Introducing Shlok-AI! + +Shlok-AI: Experience the richness of Vedic literature and Indian civilization with AI-powered insights. + +Have you ever wondered what the different Sanskrit Shlokas actually mean? +Have you ever been curious to unlock the timeless teachings of Sanatana Dharma, the eternal way of life for all Hindus? +Would you love to know more about the Indian heritage and it's cultures? + +Presenting Shlok-AI, a ready to use interface to understand the meaning of Vedic Shlokas and the culture of Bharat/India. + +This is a complex artificial intelligence algorithm that has captured the essence of the 5000 year old rich cultural heritage of India by training on timeless Sanskrit scriptures such as the Vedas, Upanishads and, other significant works such as Mahabharata and the Ramayana. + +0:00 - Understanding the meaning of a Shloka: 'Gayatri Mantra' +0:36 - Answering a generic question about Sanatana Dharma + + +If you enjoyed this video, please give it a thumbs up and leave a comment below. I would love to hear your feedback and suggestions for future videos. And don’t forget to subscribe to my channel for more videos on AI and Vedic shlokas. + +To learn more about Shlok-AI and start using it today, visit https://www.shlok-ai.com/ + +Thank you for watching! + +[Keywords] +#AI #vedic #vedas #shloka #shlokas #india #bharat + + +## Youtube Comment Promo +My humble attempt at furthering the cause of Sanatana Dharma 🙏 +Shlok-AI: Experience the richness of Vedic literature and Indian civilization with AI-powered insights. See how it works: https://www.youtube.com/watch?v=7SNpiyXNdIk. + +1. Have you ever wondered what the different Sanskrit Shlokas actually mean? +2. Have you ever been curious to unlock the timeless teachings of Sanatana Dharma, the eternal way of life for all Hindus? +3. Would you love to know more about the Indian heritage and it's cultures? + +Visit https://shlok-ai.com to start using it for FREE. +#AI #vedas #shloka #india #bharat #ShlokAI + +# X Tweets Promo +1. Have you ever wondered what the different Sanskrit Shlokas actually mean? +2. Have you ever been curious to unlock the timeless teachings of Sanatana Dharma, the eternal way of life for all Hindus? +3. Would you love to know more about the Indian heritage and it's cultures? +#AI + +Shlok-AI: Experience the richness of Vedic literature and Indian civilization with AI-powered insights. Watch this video to see how it works: https://www.youtube.com/watch?v=7SNpiyXNdIk. Then visit https://shlok-ai.com to start using it today. +#AI #vedas #shloka #india #bharat #ShlokAI + + diff --git a/run/shlok_ai_web.py b/run/shlok_ai_web.py index 07321c8..49cc2ca 100644 --- a/run/shlok_ai_web.py +++ b/run/shlok_ai_web.py @@ -1,38 +1,66 @@ import openai import json +import logging +import datetime from Common.utils import KeyFetcher from Common.utils import CostCalculator +# Set up logging +log_filename = 'shlokai.log' +logging.basicConfig(filename=log_filename, level=logging.INFO, + format='%(asctime)s - %(levelname)s - %(message)s') + +# Set up logging +log_filename = 'shlokai.debug' +logging.basicConfig(filename=log_filename, level=logging.DEBUG, + format='%(asctime)s - %(levelname)s - %(message)s') def shlokAI(user_prompt): # user_query = prompt keyfetch = KeyFetcher() openai.api_key = keyfetch.getOpenAIApiKey() - print(openai.api_key) + #logging.debug("OpenAI API Key: %s", openai.api_key) messages = [] model = "gpt-3.5-turbo" tokens_used = 0 # Prepare ShlokAI shlok_ai_instructions = f""" - You are a practising Hindu scholar in Sanskrit well versed in Vedic Dharma. You are well versed in all the sacred scriptures such as \ - Bhagavat Gita, Puranas, Vedas, Stotras, Upanishads, 4000 Divya Prabandham, etc., as well as all forms of Yogic practices. \ - I will be asking you the meaning of any verse and would like you to give me an easy to understand explanation. + You are a practising Hindu scholar in Sanskrit, well versed in the areas of expertise listed below. \ + I will be asking you the meaning of any Shloka or I would be asking a generic question related to my areas of expertise. \ + I expect you to follow the Output format listed below with only the fields that are relevant to the question asked. + + Areas of expertise: + - Bhagavat Gita + - Ramayana + - Mahabharata + - Vedas + - Upanishads + - Puranas + - Stotras + - 4000 Divya Prabandham + - Advaita philosophy + - Dvaita philosophy + - Yoga + + Types of requests allowed: + 1. Text of a shloka or verse to provide translation and meaning for + 2. Generic query regarding Hinduism and areas of expertise Output format in IETF RFC 8259 JSON specification: - - Verse in English - - Verse in Sanskrit - - Verse in Tamil - - Meaning - - Relevance - - Context - - Usage - - Source - - Author of Source - - Generic Explanation + - Verse in English + - Verse in Devanagiri + - Verse in Tamil + - Meaning + - Relevance + - Context + - Usage + - Source + - Author of Source + - Generic Explanation Follow the below conditions step by step, while providing the output: - 1. If the question is too generic or unrelated to India, Bharat, Yoga, Vedic, Spirituality, Hinduism, Culture etc., please respond with the message: \ - <"Error":"I am unable to provide an explanation for this query. Please ask a question related to Bharat, Yoga, Spirituality, Hindu Philosophy, Culture etc."> + 1. If the question is unrelated to the areas of expertise, please respond with the message: \ + <"Error":"I am unable to provide an explanation for this query! Please ask a question related to Bharat, Yoga, Spirituality, Hindu Philosophy, Culture etc."> 2. There must be no extra text except for what the output format requires. 3. If any value for the required keys is not available, do not add the key in the JSON output. 4. If you are unable to provide an explanation for an input for any other reason, please output response in IETF RFC 8259 JSON specification \ @@ -42,12 +70,12 @@ def shlokAI(user_prompt): # Set user submitted query user_prompt = user_prompt - print("User Prompt: ", user_prompt) + logging.info("User Prompt: %s", user_prompt) shlok_ai_prompt = f""" Follow the instructions delimited by triple backticks step by step. \ Instructions: ```{shlok_ai_instructions}``` \ Respond to user query delimited by angle brackets: <{user_prompt}>""" - print("ShlokAI Prompt: ", shlok_ai_prompt) + # print("ShlokAI Prompt: ", shlok_ai_prompt) # Query the model messages = [{"role": "user", "content": shlok_ai_prompt}] response_raw = openai.ChatCompletion.create( @@ -56,36 +84,31 @@ def shlokAI(user_prompt): temperature=0, # this is the degree of randomness of the model's output # stream=True ) - + query_response = response_raw.choices[0].message["content"] - print("query_response:", query_response) + logging.info("Query Response: %s", query_response) # response_content = ''.join(response_raw).strip() # print("response_content:", response_content) tokens_used = tokens_used + response_raw.usage["total_tokens"] - # TODO: Convert the below print statements to log statements using logger - print("Response: ", query_response) - print("Tokens Used: ", tokens_used) - try: json.loads(query_response) except Exception as e: - print("Response is not in proper JSON format. Please try again.") - print("Error: ", e) + logging.info("Response is not in proper JSON format. Please try again.") + logging.error("Error: %s", e) return json.dumps({"Error": e}) - + shlokai_output = json.loads(query_response) for key in shlokai_output: - print(key, ":", shlokai_output[key]) + #logging.debug("%s: %s", key, shlokai_output[key]) + print("%s: %s", key, shlokai_output[key]) # Instantiate CostCalculator costcalc = CostCalculator(tokens_used, model) cost = costcalc.calculateCost(tokens_used, model_name=model) - # Convert to logger - print("Cost: US$ ", cost) + logging.debug("Cost: US$ %s", cost) return query_response - # if __name__ == "__main__": # shlokAI(prompt)