Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload folder using huggingface_hub
Browse files- config.py +109 -48
- graph_helper.py +2 -0
- sanatan_assistant.py +25 -10
- tools.py +12 -2
config.py
CHANGED
|
@@ -14,10 +14,10 @@ class SanatanConfig:
|
|
| 14 |
"title": "Sri Vishnu Puranam",
|
| 15 |
"output_dir": "./output/vishnu_puranam",
|
| 16 |
"collection_name": "vishnu_puranam",
|
| 17 |
-
"metadata_fields"
|
| 18 |
-
{"name": "file", "datatype": "str"},
|
| 19 |
-
{"name": "num_chars", "datatype": "str"},
|
| 20 |
-
{"name": "page", "datatype": "int"},
|
| 21 |
],
|
| 22 |
"pdf_path": "./data/vishnu_puranam.pdf",
|
| 23 |
"source": "https://dn720005.ca.archive.org/0/items/vishnu-purana-sanskrit-english-ocr/VISHNU-PURANA-Sanskrit-English-OCR.pdf",
|
|
@@ -40,10 +40,10 @@ class SanatanConfig:
|
|
| 40 |
"title": "Shukla Yajur Vedam",
|
| 41 |
"output_dir": "./output/shukla_yajur_vedam",
|
| 42 |
"collection_name": "shukla_yajur_vedam",
|
| 43 |
-
"metadata_fields"
|
| 44 |
-
{"name": "file", "datatype": "str"},
|
| 45 |
-
{"name": "num_chars", "datatype": "str"},
|
| 46 |
-
{"name": "page", "datatype": "int"},
|
| 47 |
],
|
| 48 |
"pdf_path": "./data/shukla-yajur-veda.pdf",
|
| 49 |
"source": "https://www.thearyasamaj.org/uploads/book/2014/04/R1sSjG_eLb_sub_406_yajurveda.pdf",
|
|
@@ -64,10 +64,10 @@ class SanatanConfig:
|
|
| 64 |
"title": "Bhagavat Gita",
|
| 65 |
"output_dir": "./output/bhagavat_gita",
|
| 66 |
"collection_name": "bhagavat_gita",
|
| 67 |
-
"metadata_fields"
|
| 68 |
-
{"name": "file", "datatype": "str"},
|
| 69 |
-
{"name": "num_chars", "datatype": "str"},
|
| 70 |
-
{"name": "page", "datatype": "int"},
|
| 71 |
],
|
| 72 |
"pdf_path": "./data/bhagavat_gita.pdf",
|
| 73 |
"source": "https://dn790006.ca.archive.org/0/items/in.gov.ignca.279/279_text.pdf",
|
|
@@ -92,10 +92,10 @@ class SanatanConfig:
|
|
| 92 |
"title": "Valmiki Ramayanam",
|
| 93 |
"output_dir": "./output/valmiki_ramayanam",
|
| 94 |
"collection_name": "valmiki_ramayanam",
|
| 95 |
-
"metadata_fields"
|
| 96 |
-
{"name": "file", "datatype": "str"},
|
| 97 |
-
{"name": "num_chars", "datatype": "str"},
|
| 98 |
-
{"name": "page", "datatype": "int"},
|
| 99 |
],
|
| 100 |
"pdf_path": "./data/valmiki_ramayanam.pdf",
|
| 101 |
"source": "https://ia800509.us.archive.org/28/items/valmiki-ramayana-gita-press-english/Valmiki%20Ramayana%20Gita%20Press%20English.pdf",
|
|
@@ -120,13 +120,13 @@ class SanatanConfig:
|
|
| 120 |
"title": "Vishnu Sahasranamam",
|
| 121 |
"output_dir": "./output/vishnu_sahasranamam",
|
| 122 |
"collection_name": "vishnu_sahasranamam",
|
| 123 |
-
"metadata_fields"
|
| 124 |
-
{"name": "chapter", "datatype": "str"},
|
| 125 |
-
{"name": "page_number", "datatype": "int"},
|
| 126 |
-
{"name": "sanskrit", "datatype": "str"},
|
| 127 |
-
{"name": "translation", "datatype": "str"},
|
| 128 |
-
{"name": "transliteration", "datatype": "str"},
|
| 129 |
-
{"name": "verse", "datatype": "int"},
|
| 130 |
],
|
| 131 |
"pdf_path": "./data/vishnu_sahasranamam.pdf",
|
| 132 |
"source": "https://www.swami-krishnananda.org/vishnu/Sri_Vishnu_Sahasranama_Stotram.pdf",
|
|
@@ -143,17 +143,41 @@ class SanatanConfig:
|
|
| 143 |
"title": "4000 Divya Prabandham",
|
| 144 |
"output_dir": "./output/divya_prabandham",
|
| 145 |
"collection_name": "divya_prabandham",
|
| 146 |
-
"metadata_fields"
|
| 147 |
-
{
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
{
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
],
|
| 158 |
"pdf_path": "./data/divya_prabandham.pdf",
|
| 159 |
"source": "https://uveda.org",
|
|
@@ -176,10 +200,10 @@ class SanatanConfig:
|
|
| 176 |
"title": "Bhagavatha Puranam",
|
| 177 |
"output_dir": "./output/bhagavata_purana",
|
| 178 |
"collection_name": "bhagavata_purana",
|
| 179 |
-
"metadata_fields"
|
| 180 |
-
{"name": "file", "datatype": "str"},
|
| 181 |
-
{"name": "num_chars", "datatype": "str"},
|
| 182 |
-
{"name": "page", "datatype": "int"},
|
| 183 |
],
|
| 184 |
"pdf_path": "./data/bhagavata_purana.pdf",
|
| 185 |
"source": "https://dn790003.ca.archive.org/0/items/bhagavatapuranagitapress_201907/Bhagavata%20Purana%20-%20Gita%20Press_text.pdf",
|
|
@@ -195,14 +219,25 @@ class SanatanConfig:
|
|
| 195 |
"title": "Kamba Ramayanam (English)",
|
| 196 |
"output_dir": "./output/kamba_ramayanam",
|
| 197 |
"collection_name": "kamba_ramayanam_en",
|
| 198 |
-
"metadata_fields"
|
| 199 |
-
{
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
],
|
| 205 |
-
|
| 206 |
"pdf_path": "./data/kamba_ramayanam.pdf",
|
| 207 |
"source": "https://www.hindupedia.com/images/1/13/Kamba_Ramayanam_I.pdf",
|
| 208 |
"language": "tam",
|
|
@@ -226,9 +261,17 @@ class SanatanConfig:
|
|
| 226 |
"title": "Kamba Ramayanam (Tamil)",
|
| 227 |
"output_dir": "./output/kamba_ramayanam",
|
| 228 |
"collection_name": "kamba_ramayanam",
|
| 229 |
-
"metadata_fields"
|
| 230 |
-
{
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
],
|
| 233 |
"pdf_path": "./data/kamba_ramayanam.pdf",
|
| 234 |
"source": "https://archive.org/details/vrajeshkumar_gmail_061/01-%E0%AE%AA%E0%AE%BE%E0%AE%B2%20%E0%AE%95%E0%AE%BE%E0%AE%A3%E0%AF%8D%E0%AE%9F%E0%AE%AE%E0%AF%8D/page/n15/mode/2up",
|
|
@@ -249,3 +292,21 @@ class SanatanConfig:
|
|
| 249 |
],
|
| 250 |
},
|
| 251 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"title": "Sri Vishnu Puranam",
|
| 15 |
"output_dir": "./output/vishnu_puranam",
|
| 16 |
"collection_name": "vishnu_puranam",
|
| 17 |
+
"metadata_fields": [
|
| 18 |
+
{"name": "file", "datatype": "str"},
|
| 19 |
+
{"name": "num_chars", "datatype": "str"},
|
| 20 |
+
{"name": "page", "datatype": "int"},
|
| 21 |
],
|
| 22 |
"pdf_path": "./data/vishnu_puranam.pdf",
|
| 23 |
"source": "https://dn720005.ca.archive.org/0/items/vishnu-purana-sanskrit-english-ocr/VISHNU-PURANA-Sanskrit-English-OCR.pdf",
|
|
|
|
| 40 |
"title": "Shukla Yajur Vedam",
|
| 41 |
"output_dir": "./output/shukla_yajur_vedam",
|
| 42 |
"collection_name": "shukla_yajur_vedam",
|
| 43 |
+
"metadata_fields": [
|
| 44 |
+
{"name": "file", "datatype": "str"},
|
| 45 |
+
{"name": "num_chars", "datatype": "str"},
|
| 46 |
+
{"name": "page", "datatype": "int"},
|
| 47 |
],
|
| 48 |
"pdf_path": "./data/shukla-yajur-veda.pdf",
|
| 49 |
"source": "https://www.thearyasamaj.org/uploads/book/2014/04/R1sSjG_eLb_sub_406_yajurveda.pdf",
|
|
|
|
| 64 |
"title": "Bhagavat Gita",
|
| 65 |
"output_dir": "./output/bhagavat_gita",
|
| 66 |
"collection_name": "bhagavat_gita",
|
| 67 |
+
"metadata_fields": [
|
| 68 |
+
{"name": "file", "datatype": "str"},
|
| 69 |
+
{"name": "num_chars", "datatype": "str"},
|
| 70 |
+
{"name": "page", "datatype": "int"},
|
| 71 |
],
|
| 72 |
"pdf_path": "./data/bhagavat_gita.pdf",
|
| 73 |
"source": "https://dn790006.ca.archive.org/0/items/in.gov.ignca.279/279_text.pdf",
|
|
|
|
| 92 |
"title": "Valmiki Ramayanam",
|
| 93 |
"output_dir": "./output/valmiki_ramayanam",
|
| 94 |
"collection_name": "valmiki_ramayanam",
|
| 95 |
+
"metadata_fields": [
|
| 96 |
+
{"name": "file", "datatype": "str"},
|
| 97 |
+
{"name": "num_chars", "datatype": "str"},
|
| 98 |
+
{"name": "page", "datatype": "int"},
|
| 99 |
],
|
| 100 |
"pdf_path": "./data/valmiki_ramayanam.pdf",
|
| 101 |
"source": "https://ia800509.us.archive.org/28/items/valmiki-ramayana-gita-press-english/Valmiki%20Ramayana%20Gita%20Press%20English.pdf",
|
|
|
|
| 120 |
"title": "Vishnu Sahasranamam",
|
| 121 |
"output_dir": "./output/vishnu_sahasranamam",
|
| 122 |
"collection_name": "vishnu_sahasranamam",
|
| 123 |
+
"metadata_fields": [
|
| 124 |
+
{"name": "chapter", "datatype": "str"},
|
| 125 |
+
{"name": "page_number", "datatype": "int"},
|
| 126 |
+
{"name": "sanskrit", "datatype": "str"},
|
| 127 |
+
{"name": "translation", "datatype": "str"},
|
| 128 |
+
{"name": "transliteration", "datatype": "str"},
|
| 129 |
+
{"name": "verse", "datatype": "int"},
|
| 130 |
],
|
| 131 |
"pdf_path": "./data/vishnu_sahasranamam.pdf",
|
| 132 |
"source": "https://www.swami-krishnananda.org/vishnu/Sri_Vishnu_Sahasranama_Stotram.pdf",
|
|
|
|
| 143 |
"title": "4000 Divya Prabandham",
|
| 144 |
"output_dir": "./output/divya_prabandham",
|
| 145 |
"collection_name": "divya_prabandham",
|
| 146 |
+
"metadata_fields": [
|
| 147 |
+
{
|
| 148 |
+
"name": "prabandham",
|
| 149 |
+
"datatype": "str",
|
| 150 |
+
"description": "contains the short prabandham_code. e.g. `TPL` for `Thiruppallandu`",
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"name": "prabandham_name",
|
| 154 |
+
"datatype": "str",
|
| 155 |
+
"description": "contains the prabandham name. e.g. `Thiruppallandu`",
|
| 156 |
+
},
|
| 157 |
+
{
|
| 158 |
+
"name": "azhwar_name",
|
| 159 |
+
"datatype": "str",
|
| 160 |
+
"description": "contains the azhwar name. e.g. `Thirumangai Azhwar`",
|
| 161 |
+
},
|
| 162 |
+
{
|
| 163 |
+
"name": "divya_desams",
|
| 164 |
+
"datatype": "str",
|
| 165 |
+
"description": "comma separated list of divya desams. e.g. Thiruneermalai,Thiruvallikkeni",
|
| 166 |
+
},
|
| 167 |
+
# {"name": "html_url", "datatype": "str", "description" : "Reference link for the source"},
|
| 168 |
+
# {"name": "pasuram_en", "datatype": "str", "description" : "Transliteration of pasuram in english"},
|
| 169 |
+
# {"name": "pasuram_ta", "datatype": "str", "description" : "Pasuram lyrics in tamil"},
|
| 170 |
+
{
|
| 171 |
+
"name": "title",
|
| 172 |
+
"datatype": "str",
|
| 173 |
+
"description": "Title of this pasuram. for example `TVM 1.8.3`",
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"name": "verse",
|
| 177 |
+
"datatype": "int",
|
| 178 |
+
"description": "Verse number or pasuram number.",
|
| 179 |
+
},
|
| 180 |
+
# {"name": "wbw_ta", "datatype": "str", "description" : "Word by word meaning in tamil."},
|
| 181 |
],
|
| 182 |
"pdf_path": "./data/divya_prabandham.pdf",
|
| 183 |
"source": "https://uveda.org",
|
|
|
|
| 200 |
"title": "Bhagavatha Puranam",
|
| 201 |
"output_dir": "./output/bhagavata_purana",
|
| 202 |
"collection_name": "bhagavata_purana",
|
| 203 |
+
"metadata_fields": [
|
| 204 |
+
{"name": "file", "datatype": "str"},
|
| 205 |
+
{"name": "num_chars", "datatype": "str"},
|
| 206 |
+
{"name": "page", "datatype": "int"},
|
| 207 |
],
|
| 208 |
"pdf_path": "./data/bhagavata_purana.pdf",
|
| 209 |
"source": "https://dn790003.ca.archive.org/0/items/bhagavatapuranagitapress_201907/Bhagavata%20Purana%20-%20Gita%20Press_text.pdf",
|
|
|
|
| 219 |
"title": "Kamba Ramayanam (English)",
|
| 220 |
"output_dir": "./output/kamba_ramayanam",
|
| 221 |
"collection_name": "kamba_ramayanam_en",
|
| 222 |
+
"metadata_fields": [
|
| 223 |
+
{
|
| 224 |
+
"name": "file",
|
| 225 |
+
"datatype": "str",
|
| 226 |
+
"description": "The name of the Kandam or the chapter.",
|
| 227 |
+
},
|
| 228 |
+
{
|
| 229 |
+
"name": "padalam_en",
|
| 230 |
+
"datatype": "str",
|
| 231 |
+
"description": "The name of the Padalam (Episode) in English.",
|
| 232 |
+
},
|
| 233 |
+
{
|
| 234 |
+
"name": "padalam_ta",
|
| 235 |
+
"datatype": "str",
|
| 236 |
+
"description": "The name of the Padalam (Episode) in Tamil.",
|
| 237 |
+
},
|
| 238 |
+
{"name": "page", "datatype": "int"},
|
| 239 |
+
{"name": "verse_number", "datatype": "int"},
|
| 240 |
],
|
|
|
|
| 241 |
"pdf_path": "./data/kamba_ramayanam.pdf",
|
| 242 |
"source": "https://www.hindupedia.com/images/1/13/Kamba_Ramayanam_I.pdf",
|
| 243 |
"language": "tam",
|
|
|
|
| 261 |
"title": "Kamba Ramayanam (Tamil)",
|
| 262 |
"output_dir": "./output/kamba_ramayanam",
|
| 263 |
"collection_name": "kamba_ramayanam",
|
| 264 |
+
"metadata_fields": [
|
| 265 |
+
{
|
| 266 |
+
"name": "chunk_index",
|
| 267 |
+
"datatype": "int",
|
| 268 |
+
"description": "The index of the chunk",
|
| 269 |
+
},
|
| 270 |
+
{
|
| 271 |
+
"name": "filename",
|
| 272 |
+
"datatype": "str",
|
| 273 |
+
"description": "The name of the file.",
|
| 274 |
+
},
|
| 275 |
],
|
| 276 |
"pdf_path": "./data/kamba_ramayanam.pdf",
|
| 277 |
"source": "https://archive.org/details/vrajeshkumar_gmail_061/01-%E0%AE%AA%E0%AE%BE%E0%AE%B2%20%E0%AE%95%E0%AE%BE%E0%AE%A3%E0%AF%8D%E0%AE%9F%E0%AE%AE%E0%AF%8D/page/n15/mode/2up",
|
|
|
|
| 292 |
],
|
| 293 |
},
|
| 294 |
]
|
| 295 |
+
|
| 296 |
+
def get_scripture_by_collection(self, collection_name: str):
|
| 297 |
+
return [
|
| 298 |
+
scripture
|
| 299 |
+
for scripture in self.scriptures
|
| 300 |
+
if scripture["collection_name"] == collection_name
|
| 301 |
+
][0]
|
| 302 |
+
|
| 303 |
+
def is_metadata_field_allowed(self, collection_name: str, metadata_field: str):
|
| 304 |
+
scripture = self.get_scripture_by_collection(collection_name=collection_name)
|
| 305 |
+
if metadata_field not in [
|
| 306 |
+
field["name"] for field in scripture["metadata_fields"]
|
| 307 |
+
]:
|
| 308 |
+
raise Exception(
|
| 309 |
+
f"metadata_field: [{metadata_field}] not allowed in collection [{collection_name}]. Here are the allowed fields with their descriptions: {scripture["metadata_fields"]}"
|
| 310 |
+
)
|
| 311 |
+
else:
|
| 312 |
+
return True
|
graph_helper.py
CHANGED
|
@@ -6,6 +6,7 @@ from langchain_openai import ChatOpenAI
|
|
| 6 |
from langgraph.graph.state import CompiledStateGraph
|
| 7 |
from tools import (
|
| 8 |
tool_format_scripture_answer,
|
|
|
|
| 9 |
tool_search_db,
|
| 10 |
tool_search_web,
|
| 11 |
tool_push,
|
|
@@ -33,6 +34,7 @@ def generate_graph() -> CompiledStateGraph:
|
|
| 33 |
tool_search_db,
|
| 34 |
tool_format_scripture_answer,
|
| 35 |
tool_get_standardized_azhwar_names,
|
|
|
|
| 36 |
tool_get_standardized_divya_desam_names,
|
| 37 |
tool_search_db_by_metadata,
|
| 38 |
]
|
|
|
|
| 6 |
from langgraph.graph.state import CompiledStateGraph
|
| 7 |
from tools import (
|
| 8 |
tool_format_scripture_answer,
|
| 9 |
+
tool_get_standardized_prabandham_names,
|
| 10 |
tool_search_db,
|
| 11 |
tool_search_web,
|
| 12 |
tool_push,
|
|
|
|
| 34 |
tool_search_db,
|
| 35 |
tool_format_scripture_answer,
|
| 36 |
tool_get_standardized_azhwar_names,
|
| 37 |
+
tool_get_standardized_prabandham_names,
|
| 38 |
tool_get_standardized_divya_desam_names,
|
| 39 |
tool_search_db_by_metadata,
|
| 40 |
]
|
sanatan_assistant.py
CHANGED
|
@@ -15,7 +15,7 @@ allowedCollections = Literal[
|
|
| 15 |
|
| 16 |
|
| 17 |
def format_scripture_answer(
|
| 18 |
-
|
| 19 |
):
|
| 20 |
"""
|
| 21 |
Use this tool to generate a custom system prompt based on the scripture title, question, and query_tool_output.
|
|
@@ -25,14 +25,14 @@ def format_scripture_answer(
|
|
| 25 |
The generated prompt will guide the assistant to respond using only that scriptureβs content, with a clear format including Sanskrit/Tamil verses, English explanations, and source chapters.
|
| 26 |
"""
|
| 27 |
|
| 28 |
-
prompt = f"""You are a knowledgeable assistant on the scripture *{
|
| 29 |
|
| 30 |
-
You must answer the question using **only** the content from *{
|
| 31 |
- Do **not** bring in information from **any other scripture or source**, or from prior knowledge, even if the answer seems obvious or well-known.
|
| 32 |
- Do **not** quote any Sanskrit/Tamil verses unless they appear **explicitly** in the provided context.
|
| 33 |
- Do **not** use verse numbers or line references unless clearly mentioned in the context.
|
| 34 |
- If the answer cannot be found in the context, clearly say:
|
| 35 |
-
**"I do not have enough information from the {
|
| 36 |
|
| 37 |
If the answer is not directly stated in the verses but is present in explanatory notes within the context, you may interpret β but **explicitly mention that it is an interpretation**.
|
| 38 |
|
|
@@ -43,18 +43,27 @@ If the user query is not small talk, use the following response format (in Markd
|
|
| 43 |
- If it is an interpretation, say so explicitly.
|
| 44 |
|
| 45 |
### π Scripture
|
| 46 |
-
- Mention the scripture from which the references were taken.
|
| 47 |
|
| 48 |
### π Chapter
|
| 49 |
- Mention the chapter(s) from which the references were taken.
|
| 50 |
- Only mention chapters if they are explicitly part of the context.
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
### π Supporting Sanskrit/Tamil Verse(s)
|
| 53 |
-
- Quote
|
| 54 |
- Do **not** add verses from memory or outside the context.
|
| 55 |
-
- Format each verse clearly
|
| 56 |
-
- **
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
### π English Translation
|
| 60 |
- Provide the **corresponding English meaning** for each Sanskrit/Tamil verse shown.
|
|
@@ -163,7 +172,7 @@ def query_by_metadata_field(
|
|
| 163 |
- collection_name (str): The name of the scripture collection to search. ...
|
| 164 |
- query (str): The search query.
|
| 165 |
- metadata_field (str) : The name of the metadata field. e.g. azhwar_name
|
| 166 |
-
- metadata_search_operator (str) : The search operator e.g. $eq or $in
|
| 167 |
- metadata_value : Value to search for can be any primitive datatype like str or int (or a list[str] if metadata_search_operator = '$in'). for e.g. Thirumangai Azhwar or '2233' or 2233
|
| 168 |
- n_results (int): Number of results to return. Default is 5.
|
| 169 |
|
|
@@ -171,6 +180,12 @@ def query_by_metadata_field(
|
|
| 171 |
- A list of matching results.
|
| 172 |
"""
|
| 173 |
logger.info("Searching collection [%s] for [%s]", collection_name, query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
response = sanatanDatabase.search_by_metadata(
|
| 175 |
collection_name=collection_name,
|
| 176 |
query=query,
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
def format_scripture_answer(
|
| 18 |
+
collection_name: allowedCollections, question: str, query_tool_output: str
|
| 19 |
):
|
| 20 |
"""
|
| 21 |
Use this tool to generate a custom system prompt based on the scripture title, question, and query_tool_output.
|
|
|
|
| 25 |
The generated prompt will guide the assistant to respond using only that scriptureβs content, with a clear format including Sanskrit/Tamil verses, English explanations, and source chapters.
|
| 26 |
"""
|
| 27 |
|
| 28 |
+
prompt = f"""You are a knowledgeable assistant on the scripture *{collection_name}*, well-versed in **Sanskrit** , **English** and **Tamil**.
|
| 29 |
|
| 30 |
+
You must answer the question using **only** the content from *{collection_name}* provided in the context below.
|
| 31 |
- Do **not** bring in information from **any other scripture or source**, or from prior knowledge, even if the answer seems obvious or well-known.
|
| 32 |
- Do **not** quote any Sanskrit/Tamil verses unless they appear **explicitly** in the provided context.
|
| 33 |
- Do **not** use verse numbers or line references unless clearly mentioned in the context.
|
| 34 |
- If the answer cannot be found in the context, clearly say:
|
| 35 |
+
**"I do not have enough information from the {collection_name} to answer this."**
|
| 36 |
|
| 37 |
If the answer is not directly stated in the verses but is present in explanatory notes within the context, you may interpret β but **explicitly mention that it is an interpretation**.
|
| 38 |
|
|
|
|
| 43 |
- If it is an interpretation, say so explicitly.
|
| 44 |
|
| 45 |
### π Scripture
|
| 46 |
+
- Mention the scripture(s) from which the references were taken.
|
| 47 |
|
| 48 |
### π Chapter
|
| 49 |
- Mention the chapter(s) from which the references were taken.
|
| 50 |
- Only mention chapters if they are explicitly part of the context.
|
| 51 |
|
| 52 |
+
### π Verse Number
|
| 53 |
+
- Mention the *verse number* from which the references were taken.
|
| 54 |
+
|
| 55 |
+
### π Reference Link(s)
|
| 56 |
+
- Provide reference link(s) (`html_url`) if one is available in the context.
|
| 57 |
+
|
| 58 |
### π Supporting Sanskrit/Tamil Verse(s)
|
| 59 |
+
- Quote the **original** native verse(s) from the context as they were without any manipulation or transliteration.
|
| 60 |
- Do **not** add verses from memory or outside the context.
|
| 61 |
+
- Format each verse clearly.
|
| 62 |
+
- Do **not** provide English translation or transliterated text in this section.
|
| 63 |
+
|
| 64 |
+
### π English Transliteration
|
| 65 |
+
- Provide the **corresponding English transliteration** for each Sanskrit/Tamil verse shown.
|
| 66 |
+
- Keep it readable and aligned with the verse above.
|
| 67 |
|
| 68 |
### π English Translation
|
| 69 |
- Provide the **corresponding English meaning** for each Sanskrit/Tamil verse shown.
|
|
|
|
| 172 |
- collection_name (str): The name of the scripture collection to search. ...
|
| 173 |
- query (str): The search query.
|
| 174 |
- metadata_field (str) : The name of the metadata field. e.g. azhwar_name
|
| 175 |
+
- metadata_search_operator (str) : The search operator e.g. $eq or $in. DO NOT use $regex.
|
| 176 |
- metadata_value : Value to search for can be any primitive datatype like str or int (or a list[str] if metadata_search_operator = '$in'). for e.g. Thirumangai Azhwar or '2233' or 2233
|
| 177 |
- n_results (int): Number of results to return. Default is 5.
|
| 178 |
|
|
|
|
| 180 |
- A list of matching results.
|
| 181 |
"""
|
| 182 |
logger.info("Searching collection [%s] for [%s]", collection_name, query)
|
| 183 |
+
|
| 184 |
+
try:
|
| 185 |
+
SanatanConfig().is_metadata_field_allowed(collection_name=collection_name, metadata_field=metadata_field)
|
| 186 |
+
except:
|
| 187 |
+
raise
|
| 188 |
+
|
| 189 |
response = sanatanDatabase.search_by_metadata(
|
| 190 |
collection_name=collection_name,
|
| 191 |
query=query,
|
tools.py
CHANGED
|
@@ -20,8 +20,8 @@ tool_search_db = StructuredTool.from_function(
|
|
| 20 |
"Do a vector Search within a specific scripture collection. "
|
| 21 |
f"The collection_name must be one of: {', '.join(allowed_collections)}."
|
| 22 |
"Use this to find relevant scripture verses or explanations based on the given query."
|
| 23 |
-
"If the query doesn't yield any relevant results, then call `tool_search_db_by_metadata` tool to search specifically by a given metadata field (only if specific field from metadata has been mentioned)."
|
| 24 |
-
f"use this configuration for reference :\n{json.dumps(SanatanConfig.scriptures, indent=1)}\n"
|
| 25 |
),
|
| 26 |
)
|
| 27 |
|
|
@@ -59,6 +59,16 @@ tool_get_standardized_azhwar_names = StructuredTool.from_function(
|
|
| 59 |
),
|
| 60 |
)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
tool_get_standardized_divya_desam_names = StructuredTool.from_function(
|
| 64 |
get_standardized_divya_desam_names,
|
|
|
|
| 20 |
"Do a vector Search within a specific scripture collection. "
|
| 21 |
f"The collection_name must be one of: {', '.join(allowed_collections)}."
|
| 22 |
"Use this to find relevant scripture verses or explanations based on the given query."
|
| 23 |
+
# "If the query doesn't yield any relevant results, then call `tool_search_db_by_metadata` tool to search specifically by a given metadata field (only if specific field from metadata has been mentioned)."
|
| 24 |
+
# f"use this configuration for reference :\n{json.dumps(SanatanConfig.scriptures, indent=1)}\n"
|
| 25 |
),
|
| 26 |
)
|
| 27 |
|
|
|
|
| 59 |
),
|
| 60 |
)
|
| 61 |
|
| 62 |
+
tool_get_standardized_prabandham_names = StructuredTool.from_function(
|
| 63 |
+
get_standardized_azhwar_names,
|
| 64 |
+
name="tool_get_standardized_prabandham_names",
|
| 65 |
+
description=(
|
| 66 |
+
"Get a list of standardized prabandham names."
|
| 67 |
+
"Use this tool to standardize the names of the prabandhams when the user asks for pasurams from a specific prabandham."
|
| 68 |
+
"Usually this is followed by passing that `prabandham_name` for a metadata search using the `tool_search_db_by_metadata` tool."
|
| 69 |
+
"if you are passing the prabandham_code, make sure you use metadata field `prabandham` and NOT `prabandham_code` as argument to `tool_search_db_by_metadata` tool."
|
| 70 |
+
),
|
| 71 |
+
)
|
| 72 |
|
| 73 |
tool_get_standardized_divya_desam_names = StructuredTool.from_function(
|
| 74 |
get_standardized_divya_desam_names,
|