Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload folder using huggingface_hub
Browse files- data/divya_desams.json +0 -0
- graph_helper.py +2 -0
- nalayiram_helper.py +28 -3
- tools.py +14 -2
data/divya_desams.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
graph_helper.py
CHANGED
|
@@ -11,6 +11,7 @@ from tools import (
|
|
| 11 |
tool_push,
|
| 12 |
tool_get_standardized_azhwar_names,
|
| 13 |
tool_search_db_by_metadata,
|
|
|
|
| 14 |
)
|
| 15 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 16 |
from langchain_core.messages import SystemMessage, ToolMessage, HumanMessage
|
|
@@ -32,6 +33,7 @@ def generate_graph() -> CompiledStateGraph:
|
|
| 32 |
tool_search_db,
|
| 33 |
tool_format_scripture_answer,
|
| 34 |
tool_get_standardized_azhwar_names,
|
|
|
|
| 35 |
tool_search_db_by_metadata,
|
| 36 |
]
|
| 37 |
llm = ChatOpenAI(model="gpt-4o-mini").bind_tools(tools)
|
|
|
|
| 11 |
tool_push,
|
| 12 |
tool_get_standardized_azhwar_names,
|
| 13 |
tool_search_db_by_metadata,
|
| 14 |
+
tool_get_standardized_divya_desam_names,
|
| 15 |
)
|
| 16 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 17 |
from langchain_core.messages import SystemMessage, ToolMessage, HumanMessage
|
|
|
|
| 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 |
]
|
| 39 |
llm = ChatOpenAI(model="gpt-4o-mini").bind_tools(tools)
|
nalayiram_helper.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
| 1 |
import json
|
| 2 |
from dataclasses import dataclass
|
| 3 |
|
|
|
|
| 4 |
@dataclass
|
| 5 |
class Pasuram:
|
| 6 |
-
prabandham_code
|
| 7 |
-
azhwar_name
|
| 8 |
-
prabandham_name
|
|
|
|
| 9 |
|
| 10 |
def get_standardized_azhwar_names() -> list[Pasuram]:
|
| 11 |
"""
|
|
@@ -19,5 +21,28 @@ def get_standardized_azhwar_names() -> list[Pasuram]:
|
|
| 19 |
|
| 20 |
return final_azhwars
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
if __name__ == "__main__":
|
| 23 |
print(get_standardized_azhwar_names())
|
|
|
|
| 1 |
import json
|
| 2 |
from dataclasses import dataclass
|
| 3 |
|
| 4 |
+
|
| 5 |
@dataclass
|
| 6 |
class Pasuram:
|
| 7 |
+
prabandham_code: str
|
| 8 |
+
azhwar_name: str
|
| 9 |
+
prabandham_name: str
|
| 10 |
+
|
| 11 |
|
| 12 |
def get_standardized_azhwar_names() -> list[Pasuram]:
|
| 13 |
"""
|
|
|
|
| 21 |
|
| 22 |
return final_azhwars
|
| 23 |
|
| 24 |
+
|
| 25 |
+
def get_standardized_divya_desam_names() -> list[dict]:
|
| 26 |
+
"""
|
| 27 |
+
Get a list of divya desam names in divya_prabandham
|
| 28 |
+
"""
|
| 29 |
+
with open("./data/divya_desams.json", "r", encoding="utf-8") as f:
|
| 30 |
+
divya_desams = json.load(f) # FIXED
|
| 31 |
+
|
| 32 |
+
selected_fields = [
|
| 33 |
+
"title",
|
| 34 |
+
"other_names",
|
| 35 |
+
"name_ta",
|
| 36 |
+
"alwars",
|
| 37 |
+
"area",
|
| 38 |
+
"state",
|
| 39 |
+
"thirukolam",
|
| 40 |
+
"direction",
|
| 41 |
+
"sampradayam",
|
| 42 |
+
"divya_desam",
|
| 43 |
+
]
|
| 44 |
+
return [{key : row[key] for key in selected_fields if key in row} for row in divya_desams["pageProps"]["hits"]]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
if __name__ == "__main__":
|
| 48 |
print(get_standardized_azhwar_names())
|
tools.py
CHANGED
|
@@ -3,7 +3,7 @@ from langchain.agents import Tool
|
|
| 3 |
from langchain_core.tools import StructuredTool
|
| 4 |
|
| 5 |
from config import SanatanConfig
|
| 6 |
-
from nalayiram_helper import get_standardized_azhwar_names
|
| 7 |
from push_notifications_helper import push
|
| 8 |
from serperdev_helper import search as search_web
|
| 9 |
from sanatan_assistant import format_scripture_answer, query, query_by_metadata_field
|
|
@@ -31,6 +31,7 @@ tool_search_db_by_metadata = StructuredTool.from_function(
|
|
| 31 |
" Use this to find relevant scripture verses or explanations."
|
| 32 |
"if the user asks for a specific azhwar, use the `tool_get_standardized_azhwar_names` tool to get the standard name first and then pass to this tool to filter pasurams based on azhwar_name."
|
| 33 |
"if the user asks for a specific prabandham name, use the `tool_get_standardized_azhwar_names` tool to get the standard prabandham name first and then pass to this tool to filter pasurams based on prabandham_name."
|
|
|
|
| 34 |
f"use this configuration for reference :\n{json.dumps(SanatanConfig.scriptures, indent=1)}\n"
|
| 35 |
# "be aware that verse numbers are sometimes stored as strings and sometimes as mumbers, so if str search does not yield results, try passing in the metadata_value as a number instead"
|
| 36 |
# "in the context of divya_prabandham, the verse/pasuram number is stored in metadata as the field `verse` and it is stored as an int."
|
|
@@ -48,10 +49,21 @@ tool_format_scripture_answer = StructuredTool.from_function(format_scripture_ans
|
|
| 48 |
|
| 49 |
tool_get_standardized_azhwar_names = StructuredTool.from_function(
|
| 50 |
get_standardized_azhwar_names,
|
| 51 |
-
name="
|
| 52 |
description=(
|
| 53 |
"Get a list of standardized azhwar names and the prabandhams they have written. "
|
| 54 |
"Use this tool to standardize the names of the azhwars when the user asks for pasurams written by a specific azhwar."
|
| 55 |
"Usually this is followed by passing that standardized azhwar_name for a metadata search using the `tool_search_db_by_metadata` tool."
|
| 56 |
),
|
| 57 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from langchain_core.tools import StructuredTool
|
| 4 |
|
| 5 |
from config import SanatanConfig
|
| 6 |
+
from nalayiram_helper import get_standardized_azhwar_names, get_standardized_divya_desam_names
|
| 7 |
from push_notifications_helper import push
|
| 8 |
from serperdev_helper import search as search_web
|
| 9 |
from sanatan_assistant import format_scripture_answer, query, query_by_metadata_field
|
|
|
|
| 31 |
" Use this to find relevant scripture verses or explanations."
|
| 32 |
"if the user asks for a specific azhwar, use the `tool_get_standardized_azhwar_names` tool to get the standard name first and then pass to this tool to filter pasurams based on azhwar_name."
|
| 33 |
"if the user asks for a specific prabandham name, use the `tool_get_standardized_azhwar_names` tool to get the standard prabandham name first and then pass to this tool to filter pasurams based on prabandham_name."
|
| 34 |
+
"if the user asks for a specific divya desam name, use the `tool_get_standardized_divya_desam_names` tool to get the standard divya desam name first and then pass to this tool to filter pasurams based on `divya_desams`."
|
| 35 |
f"use this configuration for reference :\n{json.dumps(SanatanConfig.scriptures, indent=1)}\n"
|
| 36 |
# "be aware that verse numbers are sometimes stored as strings and sometimes as mumbers, so if str search does not yield results, try passing in the metadata_value as a number instead"
|
| 37 |
# "in the context of divya_prabandham, the verse/pasuram number is stored in metadata as the field `verse` and it is stored as an int."
|
|
|
|
| 49 |
|
| 50 |
tool_get_standardized_azhwar_names = StructuredTool.from_function(
|
| 51 |
get_standardized_azhwar_names,
|
| 52 |
+
name="tool_get_standardized_azhwar_names",
|
| 53 |
description=(
|
| 54 |
"Get a list of standardized azhwar names and the prabandhams they have written. "
|
| 55 |
"Use this tool to standardize the names of the azhwars when the user asks for pasurams written by a specific azhwar."
|
| 56 |
"Usually this is followed by passing that standardized azhwar_name for a metadata search using the `tool_search_db_by_metadata` tool."
|
| 57 |
),
|
| 58 |
)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
tool_get_standardized_divya_desam_names = StructuredTool.from_function(
|
| 62 |
+
get_standardized_divya_desam_names,
|
| 63 |
+
name="tool_get_standardized_divya_desam_names",
|
| 64 |
+
description=(
|
| 65 |
+
"Get a list of standardized divya desam names. "
|
| 66 |
+
"Use this tool to standardize the names of the divya desams when the user asks for pasurams written on a specific divya desam."
|
| 67 |
+
"Usually this is followed by passing that standardized divya desam name for a metadata search using the `tool_search_db_by_metadata` tool by using the fiels `divya_desams`."
|
| 68 |
+
),
|
| 69 |
+
)
|