Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -47,18 +47,19 @@ if "search_tool" not in st.session_state:
|
|
47 |
serper_api_key=str(os.getenv('SERPER_API')))
|
48 |
|
49 |
|
50 |
-
def get_answer(query):
|
51 |
new_search_query = st.session_state.llm.invoke(
|
52 |
f"Convert below query to english for Ahmedabad Municipal Corporation (AMC) You just need to give translated query. Don't add any additional details.\n Query: {query}").content
|
53 |
search_result = st.session_state.search_tool.run(
|
54 |
f"{new_search_query} site:https://ahmedabadcity.gov.in/")
|
55 |
|
56 |
-
system_prompt = """You are a helpful assistance for The Ahmedabad Municipal Corporation (AMC). which asnwer user query from given context only. Output language should be as same as `original_query_from_user`.
|
57 |
context: {context}
|
58 |
original_query_from_user: {original_query}
|
|
|
59 |
query: {query}"""
|
60 |
|
61 |
-
return st.session_state.llm.invoke(system_prompt.format(context=search_result, query=new_search_query, original_query=query)).content
|
62 |
|
63 |
|
64 |
session_manager.set_session_state(st.session_state)
|
@@ -96,13 +97,13 @@ if prompt := st.chat_input("Enter your query here... "):
|
|
96 |
if message['role'] == 'assistant':
|
97 |
current_conversation += f"""ai: {message['content']}\n"""
|
98 |
|
99 |
-
current_conversation += f"""user: {prompt}\n"""
|
100 |
|
101 |
print("****************************************** Messages ******************************************")
|
102 |
print("messages", current_conversation)
|
103 |
print()
|
104 |
print()
|
105 |
-
response = get_answer(current_conversation)
|
106 |
print("******************************************************** Response ********************************************************")
|
107 |
print("MY RESPONSE IS:", response)
|
108 |
|
|
|
47 |
serper_api_key=str(os.getenv('SERPER_API')))
|
48 |
|
49 |
|
50 |
+
def get_answer(conversation, query):
|
51 |
new_search_query = st.session_state.llm.invoke(
|
52 |
f"Convert below query to english for Ahmedabad Municipal Corporation (AMC) You just need to give translated query. Don't add any additional details.\n Query: {query}").content
|
53 |
search_result = st.session_state.search_tool.run(
|
54 |
f"{new_search_query} site:https://ahmedabadcity.gov.in/")
|
55 |
|
56 |
+
system_prompt = """You are a helpful assistance for The Ahmedabad Municipal Corporation (AMC). which asnwer user query from given context only. Output language should be as same as language of `original_query_from_user`.
|
57 |
context: {context}
|
58 |
original_query_from_user: {original_query}
|
59 |
+
history: {history}
|
60 |
query: {query}"""
|
61 |
|
62 |
+
return st.session_state.llm.invoke(system_prompt.format(context=search_result, history=conversation, query=new_search_query, original_query=query)).content
|
63 |
|
64 |
|
65 |
session_manager.set_session_state(st.session_state)
|
|
|
97 |
if message['role'] == 'assistant':
|
98 |
current_conversation += f"""ai: {message['content']}\n"""
|
99 |
|
100 |
+
# current_conversation += f"""user: {prompt}\n"""
|
101 |
|
102 |
print("****************************************** Messages ******************************************")
|
103 |
print("messages", current_conversation)
|
104 |
print()
|
105 |
print()
|
106 |
+
response = get_answer(current_conversation,prompt)
|
107 |
print("******************************************************** Response ********************************************************")
|
108 |
print("MY RESPONSE IS:", response)
|
109 |
|