Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Logging #15

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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
:rtype: dict
"""
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -94,4 +98,4 @@ def configure_logging():

# Set root logger level
logging.root.setLevel(logging.DEBUG)
return logging_config
return logging_config
14 changes: 7 additions & 7 deletions Config/logger.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
49 changes: 49 additions & 0 deletions docs/promo.md
Original file line number Diff line number Diff line change
@@ -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


85 changes: 54 additions & 31 deletions run/shlok_ai_web.py
Original file line number Diff line number Diff line change
@@ -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 <when question is not in English script>
- Verse in Devanagiri <when question is not in Devanagiri script>
- Verse in Tamil <when question is not in Tamil script>
- Meaning <required>
- Relevance <optional>
- Context <optional>
- Usage <optional>
- Source <when available>
- Author of Source <when available>
- Generic Explanation <optional>

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 \
Expand All @@ -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(
Expand All @@ -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)