import gradio as gr from hf_mixtral_agent import agent_executor from innovation_pathfinder_ai.source_container.container import ( all_sources ) from innovation_pathfinder_ai.utils.utils import extract_urls from innovation_pathfinder_ai.utils import logger from innovation_pathfinder_ai.utils.utils import ( generate_uuid ) from langchain_community.vectorstores import Chroma import chromadb import dotenv import os dotenv.load_dotenv() logger = logger.get_console_logger("app") def initialize_chroma_db() -> Chroma: collection_name=os.getenv("CONVERSATION_COLLECTION_NAME") client = chromadb.PersistentClient() collection = client.get_or_create_collection( name=collection_name, ) return collection if __name__ == "__main__": current_id = generate_uuid() db = initialize_chroma_db() def add_text(history, text): history = history + [(text, None)] return history, "" def bot(history): response = infer(history[-1][0], history) sources = extract_urls(all_sources) src_list = '\n'.join(sources) response_w_sources = response['output']+"\n\n\n Sources: \n\n\n"+src_list history[-1][1] = response_w_sources return history def infer(question, history): query = question result = agent_executor.invoke( { "input": question, "chat_history": history } ) db.add( ids=[current_id], documents=[result['output']], metadatas=[ { "query":query, "intermediate_steps":result['intermediate_steps'].__str__() } ] ) return result def vote(data: gr.LikeData): if data.liked: print("You upvoted this response: " + data.value) else: print("You downvoted this response: " + data.value) css=""" #col-container {max-width: 700px; margin-left: auto; margin-right: auto;} """ title = """
Hello Dave, how can I help today?