Spaces:
Sleeping
Sleeping
samlonka
commited on
Commit
•
184b1eb
1
Parent(s):
309dfff
'tools'
Browse files- Data/veda_content_details.csv +3 -0
- Tools.py +59 -32
- app.py +12 -10
Data/veda_content_details.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ede28ae4fb8f2425f428e6e4a35aa1871e1076560e368154f622a2fa189277c3
|
3 |
+
size 13147788
|
Tools.py
CHANGED
@@ -20,6 +20,13 @@ VEDAMANTRA_CSV_PATH = "Data/veda_content_modified_v3.csv"
|
|
20 |
PADA_CSV_PATH = "Data/term_data_processed_v2.csv"
|
21 |
|
22 |
class ScriptureDescriptionToolSpec(BaseToolSpec):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
spec_functions = ["get_description"]
|
24 |
|
25 |
def __init__(self):
|
@@ -54,14 +61,19 @@ class ScriptureDescriptionToolSpec(BaseToolSpec):
|
|
54 |
|
55 |
class MantraToolSpec(BaseToolSpec):
|
56 |
'''
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
65 |
'''
|
66 |
spec_functions = ["get_vedamantra_details", "get_vedamantra_summary"]
|
67 |
|
@@ -76,31 +88,34 @@ class MantraToolSpec(BaseToolSpec):
|
|
76 |
except Exception as e:
|
77 |
raise ValueError(f"Failed to get mantra details: {e}")
|
78 |
|
79 |
-
def
|
80 |
try:
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
except Exception as e:
|
86 |
-
|
87 |
|
88 |
-
def _get_query_conditions(self, scripture_name, **kwargs):
|
89 |
-
conditions = (self.df_vedamantra['scripture_name'].str.lower() == scripture_name.lower())
|
90 |
-
for key, value in kwargs.items():
|
91 |
-
conditions &= (self.df_vedamantra[key] == value)
|
92 |
-
return conditions
|
93 |
|
94 |
def _get_mantra_id(self, scripture_name, **kwargs):
|
95 |
-
|
96 |
-
|
|
|
97 |
|
98 |
-
def get_vedamantra_details(self, mantraid=None, scripture_name=None
|
99 |
try:
|
100 |
if mantraid:
|
101 |
query = f"SELECT mantra_json FROM veda_content WHERE mantra_number = '{mantraid}'"
|
102 |
else:
|
103 |
mantra_id = self._get_mantra_id(scripture_name, **kwargs)
|
|
|
104 |
query = f"SELECT mantra_json FROM veda_content WHERE mantra_number = '{mantra_id}'"
|
105 |
return self._get_mantra_details(query)
|
106 |
except Exception as e:
|
@@ -112,6 +127,7 @@ class MantraToolSpec(BaseToolSpec):
|
|
112 |
query = f"SELECT mantra_json FROM veda_content WHERE mantra_number = '{mantraid}'"
|
113 |
else:
|
114 |
mantra_id = self._get_mantra_id(scripture_name, **kwargs)
|
|
|
115 |
query = f"SELECT mantra_json FROM veda_content WHERE mantra_number = '{mantra_id}'"
|
116 |
json_dict = get_details_mantra_json(query)
|
117 |
mantra_summary = json_dict['mantraSummary']['language']
|
@@ -128,11 +144,11 @@ class PadaToolSpec(BaseToolSpec):
|
|
128 |
'''
|
129 |
Purpose: To obtains a complete or meaningful meaning of a word or pada based on context information.
|
130 |
1. The function 'get_meaning_pada' used to get all the possible meanings of the pada based on the given information.
|
131 |
-
2. The function '
|
132 |
Use the context to generate a meaningful meaning of the pada in the vedamantra.
|
133 |
Sample query:
|
134 |
1. What is the meaning of the word apratidhṛṣṭa-śavasam?
|
135 |
-
2. What is the adibauatic meaning of the word
|
136 |
3. Whats the adidaivic meaning of the word apratidhṛṣṭa-śavasam?
|
137 |
4. What is the adyatmic meaning of the word apratidhṛṣṭa-śavasam?
|
138 |
'''
|
@@ -144,26 +160,34 @@ class PadaToolSpec(BaseToolSpec):
|
|
144 |
self.df_vedic_content = pd.read_csv(VEDAMANTRA_CSV_PATH,encoding = 'utf-8')
|
145 |
|
146 |
def _get_pada_details_by_scripture(self, pada, scripture_name=None, **kwargs):
|
147 |
-
pada = iast_process(pada)
|
148 |
try:
|
|
|
149 |
condition = (self.df_terms['Pada'] == pada)
|
|
|
150 |
if scripture_name:
|
151 |
condition &= (self.df_terms['scripture_name'].str.lower() == scripture_name.lower())
|
|
|
152 |
for key, value in kwargs.items():
|
153 |
-
|
154 |
-
|
155 |
filtered_df = self.df_terms[condition]
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
except Exception as e:
|
158 |
logging.error(f"Error in _get_pada_details_by_scripture: {e}")
|
159 |
-
|
|
|
160 |
|
161 |
def _get_vedamantra_meaning(self, mantraID, MahatmaName=None):
|
162 |
try:
|
163 |
query = f"SELECT mantra_json FROM veda_content WHERE mantra_number = '{mantraID}'"
|
164 |
-
print(query)
|
165 |
jsonDict = get_details_mantra_json(query)
|
166 |
-
print(jsonDict)
|
167 |
mantraSummary = jsonDict['mantraSummary']['language']
|
168 |
if MahatmaName is not None:
|
169 |
filtered_summary = [data_dict for data_dict in mantraSummary if data_dict.get('mahatma', {}).get('mahatmaName') == MahatmaName]
|
@@ -219,7 +243,10 @@ class PadaToolSpec(BaseToolSpec):
|
|
219 |
return {"error": f"Required meaning associated with pada is not available. {e}"}
|
220 |
|
221 |
|
222 |
-
def get_adibauatic_adidaivic_adhyatmic_meaning_of_pada(self, pada, mantraid=None, scripture_name=None,
|
|
|
|
|
|
|
223 |
pada = iast_process(pada)
|
224 |
try:
|
225 |
if mantraid:
|
|
|
20 |
PADA_CSV_PATH = "Data/term_data_processed_v2.csv"
|
21 |
|
22 |
class ScriptureDescriptionToolSpec(BaseToolSpec):
|
23 |
+
'''
|
24 |
+
To obtain the description of the vedic scriptures, mandalas, kandahas, shukta, Anuvaka etc.
|
25 |
+
Sample Query:
|
26 |
+
1. Describe RigVeda?
|
27 |
+
2. What is the summary of the first mandala from RigVeda?
|
28 |
+
3. What is the brief description of the 4th Shukta of the 2nd Kandah from AtharvaVeda?
|
29 |
+
'''
|
30 |
spec_functions = ["get_description"]
|
31 |
|
32 |
def __init__(self):
|
|
|
61 |
|
62 |
class MantraToolSpec(BaseToolSpec):
|
63 |
'''
|
64 |
+
You can retrieve detailed information about Vedic mantras, including details such as vedamantra, padapatha, devata, chandah,
|
65 |
+
and rishi, from all Vedas (RigVeda, AtharvaVeda, SamaVeda, KrishnaYajurVeda, and ShuklaYajurVeda) using the function
|
66 |
+
`get_vedamantra_details`. Additionally, you can access a summary of the mantra, including anvaya, mantraVishaya, and
|
67 |
+
adhibautic (or adhyatmic or adhidyvic) meaning (or bhavartha), purpose, usage, and tippani of the vedamantra with the function
|
68 |
+
`get_vedamantra_summary`.
|
69 |
+
|
70 |
+
Here's a sample query format:
|
71 |
+
|
72 |
+
1. Obtain the vedamantra of the mantra 1.1.1.1?
|
73 |
+
2. Retrieve the devata of the vedamantra from Rigveda, first mandala, first shukta, and first mantra.
|
74 |
+
3. Provide the meaning of the vedamantra from Rigveda, first mandala, first shukta, and first mantra written by Tulsi Ram.
|
75 |
+
4. Explain the adhibautic meaning of the first mantra from RigVeda, first mandala, and first shukta.
|
76 |
+
5. Identify the mantraVishaya of the vedamantra from RigVeda, first mandala, first shukta, and first mantra.
|
77 |
'''
|
78 |
spec_functions = ["get_vedamantra_details", "get_vedamantra_summary"]
|
79 |
|
|
|
88 |
except Exception as e:
|
89 |
raise ValueError(f"Failed to get mantra details: {e}")
|
90 |
|
91 |
+
def _get_mantra_details_by_scripture(self, scripture_name=None, **kwargs):
|
92 |
try:
|
93 |
+
if scripture_name:
|
94 |
+
condition = (self.df_vedamantra['scripture_name'].str.lower() == scripture_name.lower())
|
95 |
+
|
96 |
+
for key, value in kwargs.items():
|
97 |
+
condition &= (self.df_vedamantra[key] == value)
|
98 |
+
filtered_df = self.df_vedamantra[condition]
|
99 |
+
if not filtered_df.empty:
|
100 |
+
return filtered_df
|
101 |
+
else:
|
102 |
+
return None
|
103 |
except Exception as e:
|
104 |
+
logging.error(f"Error in _get_pada_details_by_scripture: {e}")
|
105 |
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
def _get_mantra_id(self, scripture_name, **kwargs):
|
108 |
+
filtered_df = self._get_mantra_details_by_scripture(scripture_name, **kwargs)
|
109 |
+
mantraID = filtered_df['mantra_number']
|
110 |
+
return mantraID.values[0]
|
111 |
|
112 |
+
def get_vedamantra_details(self, mantraid=None, scripture_name=None,**kwargs):
|
113 |
try:
|
114 |
if mantraid:
|
115 |
query = f"SELECT mantra_json FROM veda_content WHERE mantra_number = '{mantraid}'"
|
116 |
else:
|
117 |
mantra_id = self._get_mantra_id(scripture_name, **kwargs)
|
118 |
+
#print(mantra_id)
|
119 |
query = f"SELECT mantra_json FROM veda_content WHERE mantra_number = '{mantra_id}'"
|
120 |
return self._get_mantra_details(query)
|
121 |
except Exception as e:
|
|
|
127 |
query = f"SELECT mantra_json FROM veda_content WHERE mantra_number = '{mantraid}'"
|
128 |
else:
|
129 |
mantra_id = self._get_mantra_id(scripture_name, **kwargs)
|
130 |
+
print(mantra_id)
|
131 |
query = f"SELECT mantra_json FROM veda_content WHERE mantra_number = '{mantra_id}'"
|
132 |
json_dict = get_details_mantra_json(query)
|
133 |
mantra_summary = json_dict['mantraSummary']['language']
|
|
|
144 |
'''
|
145 |
Purpose: To obtains a complete or meaningful meaning of a word or pada based on context information.
|
146 |
1. The function 'get_meaning_pada' used to get all the possible meanings of the pada based on the given information.
|
147 |
+
2. The function 'get_adibauatic_adidaivic_adhyatmic_meaning_of_pada' used to get the adibhautic, adidaivic and sdyatmic meaning of a word based on context information.\
|
148 |
Use the context to generate a meaningful meaning of the pada in the vedamantra.
|
149 |
Sample query:
|
150 |
1. What is the meaning of the word apratidhṛṣṭa-śavasam?
|
151 |
+
2. What is the adibauatic meaning of the word agnim in the context of the vedamantra from Rigveda, first mandala, first shukta, and first mantra?
|
152 |
3. Whats the adidaivic meaning of the word apratidhṛṣṭa-śavasam?
|
153 |
4. What is the adyatmic meaning of the word apratidhṛṣṭa-śavasam?
|
154 |
'''
|
|
|
160 |
self.df_vedic_content = pd.read_csv(VEDAMANTRA_CSV_PATH,encoding = 'utf-8')
|
161 |
|
162 |
def _get_pada_details_by_scripture(self, pada, scripture_name=None, **kwargs):
|
|
|
163 |
try:
|
164 |
+
pada = iast_process(pada)
|
165 |
condition = (self.df_terms['Pada'] == pada)
|
166 |
+
|
167 |
if scripture_name:
|
168 |
condition &= (self.df_terms['scripture_name'].str.lower() == scripture_name.lower())
|
169 |
+
|
170 |
for key, value in kwargs.items():
|
171 |
+
condition &= (self.df_terms[key] == value)
|
172 |
+
|
173 |
filtered_df = self.df_terms[condition]
|
174 |
+
|
175 |
+
if not filtered_df.empty:
|
176 |
+
return filtered_df
|
177 |
+
else:
|
178 |
+
return None
|
179 |
+
|
180 |
+
except KeyError as ke:
|
181 |
+
logging.error(f"KeyError in _get_pada_details_by_scripture: {ke}")
|
182 |
except Exception as e:
|
183 |
logging.error(f"Error in _get_pada_details_by_scripture: {e}")
|
184 |
+
|
185 |
+
return None
|
186 |
|
187 |
def _get_vedamantra_meaning(self, mantraID, MahatmaName=None):
|
188 |
try:
|
189 |
query = f"SELECT mantra_json FROM veda_content WHERE mantra_number = '{mantraID}'"
|
|
|
190 |
jsonDict = get_details_mantra_json(query)
|
|
|
191 |
mantraSummary = jsonDict['mantraSummary']['language']
|
192 |
if MahatmaName is not None:
|
193 |
filtered_summary = [data_dict for data_dict in mantraSummary if data_dict.get('mahatma', {}).get('mahatmaName') == MahatmaName]
|
|
|
243 |
return {"error": f"Required meaning associated with pada is not available. {e}"}
|
244 |
|
245 |
|
246 |
+
def get_adibauatic_adidaivic_adhyatmic_meaning_of_pada(self, pada, mantraid=None, scripture_name=None,
|
247 |
+
KandahNumber=None,MandalaNumber=None, ArchikahNumber=None,
|
248 |
+
ShuktaNumber=None, PrapatakNumber=None, MantraNumber=None,
|
249 |
+
AnuvakNumber=None, AdhyayaNumber=None, **kwargs):
|
250 |
pada = iast_process(pada)
|
251 |
try:
|
252 |
if mantraid:
|
app.py
CHANGED
@@ -73,12 +73,13 @@ storage_context_pine = StorageContext.from_defaults(vector_store=vector_store_pi
|
|
73 |
index_store = VectorStoreIndex.from_vector_store(vector_store_pine,storage_context=storage_context_pine)
|
74 |
query_engine_vector = index_store.as_query_engine(similarity_top_k=10,vector_store_query_mode ='hybrid',alpha=0.6,inlcude_metadata = True)
|
75 |
|
76 |
-
VEDAMANTRA_CSV_PATH = "Data/
|
77 |
PADA_CSV_PATH = "Data/term_data_processed_v2.csv"
|
|
|
78 |
|
79 |
#pandas Engine
|
80 |
-
df_veda_details = pd.read_csv(
|
81 |
-
df_pada_details = pd.read_csv(PADA_CSV_PATH,encoding='utf-8')
|
82 |
query_engine_veda = PandasQueryEngine(df=df_veda_details)
|
83 |
query_engine_pada = PandasQueryEngine(df=df_pada_details)
|
84 |
|
@@ -146,16 +147,17 @@ tools = [*mantra_tools,*pada_tools,*description_tools,*query_engine_tools]
|
|
146 |
|
147 |
# context
|
148 |
context = """
|
149 |
-
You are an expert on Vedas and related scriptures
|
150 |
-
Your role is to respond to questions about vedic scriptures and associated information based on available sources.\
|
151 |
For every query, you must use tool first. If the input args, kwargs and tools for the given query is same as in the history or retrieved context is sufficient, then use the history as context.
|
152 |
-
Please provide well-informed answers.
|
|
|
153 |
Also, provide three follow-up questions based on the input query and the context in the following format.
|
154 |
*****
|
155 |
-
You may also try the following questions:
|
156 |
-
1. Question1
|
157 |
-
2. Question2
|
158 |
-
3. Question3
|
159 |
"""
|
160 |
|
161 |
# Function to create ReActAgent instance (change it based on your initialization logic)
|
|
|
73 |
index_store = VectorStoreIndex.from_vector_store(vector_store_pine,storage_context=storage_context_pine)
|
74 |
query_engine_vector = index_store.as_query_engine(similarity_top_k=10,vector_store_query_mode ='hybrid',alpha=0.6,inlcude_metadata = True)
|
75 |
|
76 |
+
VEDAMANTRA_CSV_PATH = "Data/veda_content_modified_v5.csv"
|
77 |
PADA_CSV_PATH = "Data/term_data_processed_v2.csv"
|
78 |
+
VEDACONTENT_CSV_PATH = "Data/veda_content_details.csv"
|
79 |
|
80 |
#pandas Engine
|
81 |
+
df_veda_details = pd.read_csv(VEDACONTENT_CSV_PATH,encoding='utf-8-sig')
|
82 |
+
df_pada_details = pd.read_csv(PADA_CSV_PATH,encoding='utf-8-sig')
|
83 |
query_engine_veda = PandasQueryEngine(df=df_veda_details)
|
84 |
query_engine_pada = PandasQueryEngine(df=df_pada_details)
|
85 |
|
|
|
147 |
|
148 |
# context
|
149 |
context = """
|
150 |
+
You are an expert on Vedas and related scriptures.
|
151 |
+
Your role is to respond to questions about vedic scriptures (RigVeda, AtharvaVeda, SamaVeda, ShuklaYajurVeda, and KrishnaYajurVeda) and associated information based on available sources.\
|
152 |
For every query, you must use tool first. If the input args, kwargs and tools for the given query is same as in the history or retrieved context is sufficient, then use the history as context.
|
153 |
+
Please provide well-informed answers. If the context or history is not sufficient, you can say that you don't have sufficient information. Don't use prior knowledge.
|
154 |
+
If your response is based on "Implicit" thought then you can say that you don't have sufficient information. Don't use prior knowledge.
|
155 |
Also, provide three follow-up questions based on the input query and the context in the following format.
|
156 |
*****
|
157 |
+
You may also try the following questions:
|
158 |
+
1. <i>Question1</i>
|
159 |
+
2. <i>Question2</i>
|
160 |
+
3. <i>Question3</i>
|
161 |
"""
|
162 |
|
163 |
# Function to create ReActAgent instance (change it based on your initialization logic)
|