-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from AllenNeuralDynamics/persistence
Persistence/Memory/Efficiency
- Loading branch information
Showing
9 changed files
with
266 additions
and
147 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
"""Init package""" | ||
__version__ = "0.0.12" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Import the Streamlit library | ||
import streamlit as st | ||
import asyncio | ||
import uuid | ||
|
||
# import sys | ||
# import os | ||
# sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
|
||
from async_workflow import async_workflow | ||
from react_agent import astream_input | ||
|
||
from langchain_core.messages import HumanMessage, AIMessage | ||
|
||
import warnings | ||
warnings.filterwarnings('ignore') | ||
|
||
#run on terminal with streamlit run c:/Users/sreya.kumar/Documents/GitHub/metadata-chatbot/src/metadata_chatbot/agents/app.py [ARGUMENTS] | ||
|
||
unique_id = str(uuid.uuid4()) | ||
|
||
async def main(): | ||
st.title("GAMER: Generative Analysis of Metadata Retrieval") | ||
|
||
message = st.chat_message("assistant") | ||
message.write("Hello! How can I help you?") | ||
|
||
query = st.chat_input("Ask a question about the AIND Metadata!") | ||
|
||
if "messages" not in st.session_state: | ||
st.session_state.messages = [] | ||
|
||
model = async_workflow.compile() | ||
|
||
for message in st.session_state.messages: | ||
if isinstance(message, HumanMessage): | ||
with st.chat_message("user"): | ||
st.markdown(message.content) | ||
else: | ||
with st.chat_message("assistant"): | ||
st.markdown(message.content) | ||
|
||
if query is not None and query != '': | ||
st.session_state.messages.append(HumanMessage(query)) | ||
|
||
with st.chat_message("user"): | ||
st.markdown(query) | ||
|
||
with st.chat_message("assistant"): | ||
async def main(query: str): | ||
chat_history = st.session_state.messages | ||
#config = {"configurable":{"thread_id": st.session_state.unique_id}} | ||
inputs = { | ||
"messages": chat_history, | ||
} | ||
async for output in model.astream(inputs): | ||
for key, value in output.items(): | ||
if key != "database_query": | ||
yield value['messages'][0].content | ||
else: | ||
try: | ||
query = str(chat_history) + query | ||
async for result in astream_input(query = query): | ||
response = result['type'] | ||
if response == 'intermediate_steps': | ||
yield result['content'] | ||
if response == 'agg_pipeline': | ||
yield f"The MongoDB pipeline used to on the database is: {result['content']}" | ||
if response == 'tool_response': | ||
yield f"Retrieved output from MongoDB: {result['content']}" | ||
if response == 'final_answer': | ||
yield result['content'] | ||
|
||
except Exception as e: | ||
yield f"An error has occured with the retrieval from DocDB: {e}. Try structuring your query another way." | ||
# for response in value['messages']: | ||
# yield response.content | ||
# yield value['generation'] | ||
|
||
prev = None | ||
generation = None | ||
async for result in main(query): | ||
if prev != None: | ||
st.markdown(prev) | ||
prev = result | ||
generation = prev | ||
st.markdown(generation) | ||
st.session_state.messages.append(AIMessage(generation)) | ||
# response = await llm.streamlit_astream(query, unique_id = unique_id) | ||
# st.markdown(response) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
Oops, something went wrong.