Spaces:
Sleeping
Sleeping
Commit
•
464a43e
1
Parent(s):
96702d3
modified prompts
Browse files
app.py
CHANGED
@@ -47,6 +47,7 @@ except KeyError as e:
|
|
47 |
#pinecone_api_key = st.secrets["PINECONE_API_KEY_SAM"]
|
48 |
|
49 |
#llm
|
|
|
50 |
llm_AI4 = OpenAI(temperature=0, model="gpt-4-1106-preview",api_key=openai_api_key, max_tokens=512)
|
51 |
token_counter = TokenCountingHandler(
|
52 |
tokenizer=tiktoken.encoding_for_model("gpt-4-1106-preview").encode
|
@@ -70,10 +71,12 @@ pinecone_index = pc.Index("pod-index")
|
|
70 |
vector_store_pine = PineconeVectorStore(pinecone_index=pinecone_index)
|
71 |
storage_context_pine = StorageContext.from_defaults(vector_store=vector_store_pine)
|
72 |
index_store = VectorStoreIndex.from_vector_store(vector_store_pine,storage_context=storage_context_pine)
|
73 |
-
query_engine_vector = index_store.as_query_engine(similarity_top_k=5,vector_store_query_mode ='hybrid',alpha=0.6)
|
74 |
#pandas Engine
|
75 |
df_veda_details = pd.read_csv("Data/veda_content_details.csv",encoding='utf-8')
|
76 |
-
|
|
|
|
|
77 |
|
78 |
# Query Engine Tools
|
79 |
query_engine_tools = [
|
@@ -95,20 +98,38 @@ query_engine_tools = [
|
|
95 |
),
|
96 |
),
|
97 |
QueryEngineTool(
|
98 |
-
query_engine=
|
99 |
metadata=ToolMetadata(
|
100 |
-
name="
|
101 |
description=(
|
102 |
-
'''
|
103 |
-
The column names as follows:\
|
104 |
'mantra_id', 'scripture_name', 'KandahNumber', 'PrapatakNumber','AnuvakNumber', 'MantraNumber', 'DevataName', 'RishiName', 'SwarahName', 'ChandaName',\
|
105 |
-
'padapatha', 'vedamantra', 'AdhyayaNumber', 'ArchikahNumber', 'ArchikahName', 'ShuktaNumber', 'keyShukta', 'ParyayaNumber', 'MandalaNumber'
|
106 |
-
|
107 |
Sample Query:\
|
108 |
1. How many mantras are there in RigVeda whose swarah is gāndhāraḥ?\
|
109 |
2. How many different devata present in rigveda?\
|
110 |
-
3. Which Kandah has the maximum number of in KrishnaYajurVeda
|
111 |
-
4.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
'''
|
113 |
),
|
114 |
),
|
@@ -124,14 +145,15 @@ tools = [*mantra_tools,*description_tools,*query_engine_tools]
|
|
124 |
context = """
|
125 |
You are an expert on Vedas and related scriptures.\
|
126 |
Your role is to respond to questions about vedic scriptures and associated information based on available sources.\
|
127 |
-
For every query, you must use either any one of the tool or use available history/context
|
|
|
128 |
Please provide well-informed answers. Don't use prior knowledge.
|
129 |
"""
|
130 |
|
131 |
# Function to create ReActAgent instance (change it based on your initialization logic)
|
132 |
@st.cache_resource(show_spinner=False) # Set allow_output_mutation to True for mutable objects like instances
|
133 |
def create_react_agent():
|
134 |
-
return ReActAgent.from_tools(tools, llm=llm_AI4, context=context, memory = memory, max_iterations =
|
135 |
|
136 |
# Example usage
|
137 |
react_agent_instance = create_react_agent()
|
|
|
47 |
#pinecone_api_key = st.secrets["PINECONE_API_KEY_SAM"]
|
48 |
|
49 |
#llm
|
50 |
+
llm_AI = OpenAI(temperature=0, model="gpt-4-1106-preview",api_key=openai_api_key, max_tokens=512)
|
51 |
llm_AI4 = OpenAI(temperature=0, model="gpt-4-1106-preview",api_key=openai_api_key, max_tokens=512)
|
52 |
token_counter = TokenCountingHandler(
|
53 |
tokenizer=tiktoken.encoding_for_model("gpt-4-1106-preview").encode
|
|
|
71 |
vector_store_pine = PineconeVectorStore(pinecone_index=pinecone_index)
|
72 |
storage_context_pine = StorageContext.from_defaults(vector_store=vector_store_pine)
|
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=5,vector_store_query_mode ='hybrid',alpha=0.6,inlcude_metadata = True)
|
75 |
#pandas Engine
|
76 |
df_veda_details = pd.read_csv("Data/veda_content_details.csv",encoding='utf-8')
|
77 |
+
df_pada_details = pd.read_csv("Data/term_grammar_v2.csv.csv",encoding='utf-8')
|
78 |
+
query_engine_veda_details = PandasQueryEngine(df=df_veda_details)
|
79 |
+
query_engine_pada_details = PandasQueryEngine(df=df_pada_details)
|
80 |
|
81 |
# Query Engine Tools
|
82 |
query_engine_tools = [
|
|
|
98 |
),
|
99 |
),
|
100 |
QueryEngineTool(
|
101 |
+
query_engine=query_engine_veda_details,
|
102 |
metadata=ToolMetadata(
|
103 |
+
name="pandas_veda_engine",
|
104 |
description=(
|
105 |
+
'''A powerful tool designed to handle queries related to counting information about vedic content document. This document is a .csv file with different columns as follows:\
|
|
|
106 |
'mantra_id', 'scripture_name', 'KandahNumber', 'PrapatakNumber','AnuvakNumber', 'MantraNumber', 'DevataName', 'RishiName', 'SwarahName', 'ChandaName',\
|
107 |
+
'padapatha', 'vedamantra', 'AdhyayaNumber', 'ArchikahNumber', 'ArchikahName', 'ShuktaNumber', 'keyShukta', 'ParyayaNumber', 'MandalaNumber'.\
|
108 |
+
Always provide the final answer after excuting pandas query which is equivalent to user query.\
|
109 |
Sample Query:\
|
110 |
1. How many mantras are there in RigVeda whose swarah is gāndhāraḥ?\
|
111 |
2. How many different devata present in rigveda?\
|
112 |
+
3. Which Kandah has the maximum number of in KrishnaYajurVeda?\
|
113 |
+
4. Find the number of mantras from AtharvaVeda whose devata is vācaspatiḥ and chandah is anuṣṭup?\
|
114 |
+
5. count the mantras in RigVeda whose swarah is gāndhāraḥ?
|
115 |
+
'''
|
116 |
+
),
|
117 |
+
),
|
118 |
+
),
|
119 |
+
QueryEngineTool(
|
120 |
+
query_engine=query_engine_pada_details,
|
121 |
+
metadata=ToolMetadata(
|
122 |
+
name="pandas_pada_engine",
|
123 |
+
description=(
|
124 |
+
'''Helpful to answer the queries related to count on padas/terms/words from vedic scriptures based on csv files.\
|
125 |
+
Different columns from csv file containing comprehensive information about the padas.\
|
126 |
+
The column names as follows:\
|
127 |
+
'scripture_name', 'mantra_level_1', 'mantra_level_2', 'mantra_level_3',\
|
128 |
+
'mantra_level_4', 'mantra_number', 'mantra_id', 'word_index',\
|
129 |
+
'segmentation', 'term_json_new', 'word'.\
|
130 |
+
Sample Query:\
|
131 |
+
1. How many times the word yāsyan appeared in RigVeda?\
|
132 |
+
2. How many total distrinct terms are there in AtharvaVeda?
|
133 |
'''
|
134 |
),
|
135 |
),
|
|
|
145 |
context = """
|
146 |
You are an expert on Vedas and related scriptures.\
|
147 |
Your role is to respond to questions about vedic scriptures and associated information based on available sources.\
|
148 |
+
For every query, you must use either any one of the tool or use available history/context.\
|
149 |
+
User expect the responses based on vedic scriptures or related vedas.\
|
150 |
Please provide well-informed answers. Don't use prior knowledge.
|
151 |
"""
|
152 |
|
153 |
# Function to create ReActAgent instance (change it based on your initialization logic)
|
154 |
@st.cache_resource(show_spinner=False) # Set allow_output_mutation to True for mutable objects like instances
|
155 |
def create_react_agent():
|
156 |
+
return ReActAgent.from_tools(tools, llm=llm_AI4, context=context, memory = memory, max_iterations = 100,verbose=True)
|
157 |
|
158 |
# Example usage
|
159 |
react_agent_instance = create_react_agent()
|