diff --git a/.gitignore b/.gitignore index 6ab75ac..dad015d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ __pycache__ prep -.env +.env \ No newline at end of file diff --git a/5-rag-agent/.env.example b/5-rag-agent/.env.example new file mode 100644 index 0000000..42d19f6 --- /dev/null +++ b/5-rag-agent/.env.example @@ -0,0 +1,17 @@ +# Rename this file to .env once you have filled in the below environment variables! + +# Get your Hugging Face API token here: https://huggingface.co/settings/tokens +# After creating an account with Hugging Face +# Then run huggingface-cli login and enter the token in there too after installing Hugging Face +HUGGINGFACEHUB_API_TOKEN= + +# The local LLM to use from Hugging Face +# A good default to go with here is meta-llama/Meta-Llama-3.1-405B-Instruct +# Note that at the time of recording you need a pro HuggingFace account for the Llama 3.1 models! +# I don't mention that in the video because usually the new models are available to everyone +# after only a couple weeks. Feel free to use meta-llama/Meta-Llama-3-70B-Instruct as an alternative. +LLM_MODEL=meta-llama/Meta-Llama-3.1-405B-Instruct + +# The absolute or relative path to the folder that has all the files for retrieval +# If using a relative path, the path is relative to the directoy containing this .env.example file +DIRECTORY= \ No newline at end of file diff --git a/5-rag-agent/local-rag-agent.py b/5-rag-agent/local-rag-agent.py new file mode 100644 index 0000000..44f0535 --- /dev/null +++ b/5-rag-agent/local-rag-agent.py @@ -0,0 +1,128 @@ +from langchain_chroma import Chroma +from langchain_huggingface import HuggingFacePipeline, HuggingFaceEndpoint, ChatHuggingFace +from langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddings +from langchain_core.messages import SystemMessage, AIMessage, HumanMessage +from langchain_community.document_loaders import DirectoryLoader +from langchain_text_splitters import CharacterTextSplitter +from dotenv import load_dotenv +from datetime import datetime +import streamlit as st +import json +import os + +load_dotenv() + +model = os.getenv('LLM_MODEL', 'meta-llama/Meta-Llama-3.1-405B-Instruct') +rag_directory = os.getenv('DIRECTORY', 'meeting_notes') + +@st.cache_resource +def get_local_model(): + return HuggingFaceEndpoint( + repo_id=model, + task="text-generation", + max_new_tokens=1024, + do_sample=False + ) + + # If you want to run the model absolutely locally - VERY resource intense! + # return HuggingFacePipeline.from_model_id( + # model_id=model, + # task="text-generation", + # pipeline_kwargs={ + # "max_new_tokens": 1024, + # "top_k": 50, + # "temperature": 0.4 + # }, + # ) + +llm = get_local_model() + +def load_documents(directory): + # Load the PDF or txt documents from the directory + loader = DirectoryLoader(directory) + documents = loader.load() + + # Split the documents into chunks + text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0) + docs = text_splitter.split_documents(documents) + + return docs + +@st.cache_resource +def get_chroma_instance(): + # Get the documents split into chunks + docs = load_documents(rag_directory) + + # create the open-sourc e embedding function + embedding_function = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2") + + # load it into Chroma + return Chroma.from_documents(docs, embedding_function) + +db = get_chroma_instance() + +def query_documents(question): + """ + Uses RAG to query documents for information to answer a question + + Example call: + + query_documents("What are the action items from the meeting on the 20th?") + Args: + question (str): The question the user asked that might be answerable from the searchable documents + Returns: + str: The list of texts (and their sources) that matched with the question the closest using RAG + """ + similar_docs = db.similarity_search(question, k=5) + docs_formatted = list(map(lambda doc: f"Source: {doc.metadata.get('source', 'NA')}\nContent: {doc.page_content}", similar_docs)) + + return docs_formatted + +def prompt_ai(messages): + # Fetch the relevant documents for the query + user_prompt = messages[-1].content + retrieved_context = query_documents(user_prompt) + formatted_prompt = f"Context for answering the question:\n{retrieved_context}\nQuestion/user input:\n{user_prompt}" + + # Prompt the AI with the latest user message + doc_chatbot = ChatHuggingFace(llm=llm) + ai_response = doc_chatbot.invoke(messages[:-1] + [HumanMessage(content=formatted_prompt)]) + + return ai_response + +def main(): + st.title("Chat with Local Documents") + + # Initialize chat history + if "messages" not in st.session_state: + st.session_state.messages = [ + SystemMessage(content=f"You are a personal assistant who answers questions based on the context provided if the provided context can answer the question. You only provide the answer to the question/user input and nothing else. The current date is: {datetime.now().date()}") + ] + + # Display chat messages from history on app rerun + for message in st.session_state.messages: + message_json = json.loads(message.json()) + message_type = message_json["type"] + if message_type in ["human", "ai", "system"]: + with st.chat_message(message_type): + st.markdown(message_json["content"]) + + # React to user input + # Example question: What's included in the wellness program Emily proposed? + # Example question 2: What were the results of the team survey? + # Example question 3: What was discussed in the meeting on the 22nd? + if prompt := st.chat_input("What questions do you have?"): + # Display user message in chat message container + st.chat_message("user").markdown(prompt) + # Add user message to chat history + st.session_state.messages.append(HumanMessage(content=prompt)) + + # Display assistant response in chat message container + with st.chat_message("assistant"): + ai_response = prompt_ai(st.session_state.messages) + st.markdown(ai_response.content) + + st.session_state.messages.append(ai_response) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/5-rag-agent/meeting_notes/2024-07-18.pdf b/5-rag-agent/meeting_notes/2024-07-18.pdf new file mode 100644 index 0000000..fdf0900 Binary files /dev/null and b/5-rag-agent/meeting_notes/2024-07-18.pdf differ diff --git a/5-rag-agent/meeting_notes/2024-07-19.pdf b/5-rag-agent/meeting_notes/2024-07-19.pdf new file mode 100644 index 0000000..aee0c2c Binary files /dev/null and b/5-rag-agent/meeting_notes/2024-07-19.pdf differ diff --git a/5-rag-agent/meeting_notes/2024-07-20.txt b/5-rag-agent/meeting_notes/2024-07-20.txt new file mode 100644 index 0000000..0a21e37 --- /dev/null +++ b/5-rag-agent/meeting_notes/2024-07-20.txt @@ -0,0 +1,71 @@ +Meeting Notes +Date: July 20, 2024 +Time: 11:00 AM - 12:30 PM +Location: Conference Room C, Gaming HQ + +Attendees: + +Alex Thompson (CEO) +Maria Rodriguez (CTO) +Jamie Lee (Lead Game Designer) +Sam Patel (Marketing Director) +Chris Martin (Project Manager) +Tina Nguyen (Lead Programmer) +Emily Carter (HR Manager) +Michael Harris (QA Lead) +Laura Bennett (Finance Manager) +Agenda: + +Financial Review and Budget Allocation +Progress Update on Technical Issues +Marketing Campaign for Upcoming Beta +Team Building and Morale Boosting Initiatives +Community Event Planning +AOB (Any Other Business) +1. Financial Review and Budget Allocation: + +Laura Bennett: Presented the financial report for Q2: +Revenue exceeded projections by 15% due to the success of "Dragon's Quest." +Proposed budget allocation for the next quarter, prioritizing new hires, marketing campaigns, and technical upgrades. +Discussion: Team agreed to allocate additional funds towards the marketing campaign for the "Space Rangers" beta and the development of "Cyber Warriors." +2. Progress Update on Technical Issues: + +Tina Nguyen: Provided an update on the technical issues: +Memory leak problems in "Space Rangers" have been resolved. +Server stability has improved, with a new load-balancing system implemented. +Feedback: +Maria Rodriguez: Suggested conducting a stress test next week to ensure server robustness before the beta release. +Michael Harris: Confirmed that QA will schedule and oversee the stress test. +3. Marketing Campaign for Upcoming Beta: + +Sam Patel: Detailed the marketing campaign strategy for the "Space Rangers" beta: +Teaser trailers and gameplay videos to be released over the next two weeks. +Social media countdown to the beta launch, with daily posts and interactive content. +Collaboration with influencers to generate hype and attract beta testers. +Discussion: Team brainstormed additional promotional activities, such as a beta launch livestream and exclusive in-game rewards for beta participants. +4. Team Building and Morale Boosting Initiatives: + +Emily Carter: Presented proposals for boosting team morale: +Scheduled a team-building retreat for the first week of August. +Implementing flexible working hours starting next week. +Organizing monthly social events to foster a positive work environment. +Feedback: +Alex Thompson: Emphasized the importance of maintaining a healthy work-life balance and encouraged team members to take advantage of the new initiatives. +5. Community Event Planning: + +Jamie Lee: Discussed plans for the community event: +Proposed an in-game tournament with prizes for the top players. +Suggested holding a live Q&A session with the development team to engage with the community directly. +Sam Patel: Agreed to coordinate the event and manage logistics, with a tentative date set for mid-August. +6. AOB (Any Other Business): + +Alex Thompson: Reminded everyone to submit their presentation proposals for the industry conference by the end of the month. +Laura Bennett: Announced the approval of the budget for the new office in Berlin, with plans to start operations in September. +Next Meeting: Scheduled for August 5, 2024. +Action Items: + +Laura Bennett: Finalize budget allocations and distribute funds as agreed. +Tina Nguyen: Conduct a stress test for the "Space Rangers" servers next week and report results. +Sam Patel: Implement the marketing campaign for the beta and coordinate the community event. +Emily Carter: Organize the team-building retreat and implement flexible working hours policy. +Meeting Adjourned at 12:30 PM. \ No newline at end of file diff --git a/5-rag-agent/meeting_notes/2024-07-21.txt b/5-rag-agent/meeting_notes/2024-07-21.txt new file mode 100644 index 0000000..d2d2263 --- /dev/null +++ b/5-rag-agent/meeting_notes/2024-07-21.txt @@ -0,0 +1,71 @@ +Meeting Notes +Date: July 21, 2024 +Time: 10:00 AM - 11:30 AM +Location: Conference Room D, Gaming HQ + +Attendees: + +Alex Thompson (CEO) +Maria Rodriguez (CTO) +Jamie Lee (Lead Game Designer) +Sam Patel (Marketing Director) +Chris Martin (Project Manager) +Tina Nguyen (Lead Programmer) +Emily Carter (HR Manager) +Michael Harris (QA Lead) +Sarah Walker (Customer Support Manager) +Agenda: + +Review of Previous Action Items +Customer Support Enhancements +Final Preparations for "Space Rangers" Beta +"Cyber Warriors" Concept Feedback +Recruitment Status and Onboarding Plans +AOB (Any Other Business) +1. Review of Previous Action Items: + +Laura Bennett: Confirmed budget allocations are completed, with funds distributed to marketing and development. +Tina Nguyen: Reported the stress test for "Space Rangers" servers is scheduled for the upcoming Monday. +Sam Patel: Provided updates on the marketing campaign rollout, with teaser trailers receiving positive engagement. +Emily Carter: Confirmed the team-building retreat is booked, and flexible working hours policy is now in effect. +2. Customer Support Enhancements: + +Sarah Walker: Presented the current state of customer support: +Average response time reduced by 20%. +Feedback from players highlighted the need for more detailed FAQ sections and video tutorials. +Discussion: +Maria Rodriguez: Suggested integrating a chatbot to handle common queries and free up support agents for complex issues. +Chris Martin: Agreed to prioritize the development of a chatbot and assign a team for its implementation. +3. Final Preparations for "Space Rangers" Beta: + +Chris Martin: Outlined the final checklist for the beta launch: +Ensure all beta testers receive their access codes and instructions by July 25, 2024. +Conduct a final internal review of the game build. +Schedule a pre-beta meeting with the QA team to address any last-minute issues. +Michael Harris: Confirmed QA will be on standby during the beta launch to handle any critical bugs or crashes. +4. "Cyber Warriors" Concept Feedback: + +Jamie Lee: Shared findings from the market research for "Cyber Warriors": +Strong interest in the game's concept, especially the unique multiplayer feature. +Suggested conducting focus groups to gather more detailed feedback and refine the storyline. +Feedback: +Alex Thompson: Approved moving forward with focus groups and emphasized the need for a comprehensive development plan. +5. Recruitment Status and Onboarding Plans: + +Emily Carter: Updated on the recruitment process: +Two senior developers and one UX/UI designer have accepted offers and will start next month. +Onboarding plans include a comprehensive orientation program and assigning mentors to new hires. +Discussion: +Tina Nguyen: Highlighted the importance of quickly integrating new team members into ongoing projects to maintain momentum. +6. AOB (Any Other Business): + +Alex Thompson: Reminded the team about the upcoming industry conference and the importance of networking and learning from peers. +Sarah Walker: Proposed monthly training sessions for the customer support team to keep them updated on game features and best practices. +Next Meeting: Scheduled for August 6, 2024. +Action Items: + +Sarah Walker: Implement enhancements to the customer support system, including the development of a chatbot. +Chris Martin: Finalize preparations for the "Space Rangers" beta and coordinate with the QA team. +Jamie Lee: Organize focus groups for "Cyber Warriors" and gather detailed feedback. +Emily Carter: Ensure smooth onboarding for new hires and facilitate their integration into projects. +Meeting Adjourned at 11:30 AM. \ No newline at end of file diff --git a/5-rag-agent/meeting_notes/2024-07-22.txt b/5-rag-agent/meeting_notes/2024-07-22.txt new file mode 100644 index 0000000..125ba19 --- /dev/null +++ b/5-rag-agent/meeting_notes/2024-07-22.txt @@ -0,0 +1,78 @@ +Meeting Notes +Date: July 22, 2024 +Time: 3:00 PM - 4:30 PM +Location: Conference Room E, Gaming HQ + +Attendees: + +Alex Thompson (CEO) +Maria Rodriguez (CTO) +Jamie Lee (Lead Game Designer) +Sam Patel (Marketing Director) +Chris Martin (Project Manager) +Tina Nguyen (Lead Programmer) +Emily Carter (HR Manager) +Michael Harris (QA Lead) +Laura Bennett (Finance Manager) +David King (Art Director) +Agenda: + +Review of Previous Action Items +Art and Design Updates +Server Stress Test Preparation +Marketing Metrics and Adjustments +Focus Group Planning for "Cyber Warriors" +AOB (Any Other Business) +1. Review of Previous Action Items: + +Sarah Walker: Implementing the chatbot has begun, with an expected rollout in two weeks. +Chris Martin: Final preparations for "Space Rangers" beta are on track, with beta access codes ready to be distributed. +Jamie Lee: Scheduled focus groups for "Cyber Warriors" to begin next week. +Emily Carter: Onboarding process for new hires has been finalized, with mentors assigned. +2. Art and Design Updates: + +David King: Presented updates on art and design: +New character models for "Cyber Warriors" are 50% complete. +Concept art for the "Mystic Adventures" expansion pack has been finalized and is ready for review. +Feedback: +Jamie Lee: Suggested incorporating more diverse character designs to appeal to a broader audience. +Maria Rodriguez: Recommended scheduling regular review sessions to ensure art and design align with the overall vision of the games. +3. Server Stress Test Preparation: + +Tina Nguyen: Outlined the plan for the server stress test: +Scheduled for Monday, July 24, 2024. +Will simulate peak user loads to identify potential issues. +QA team will monitor performance and log any anomalies. +Discussion: +Michael Harris: Confirmed QA team is prepared and ready to support the stress test. +Alex Thompson: Emphasized the importance of ensuring server stability before the beta launch. +4. Marketing Metrics and Adjustments: + +Sam Patel: Shared metrics from the current marketing campaign: +Teaser trailers for "Space Rangers" have received high engagement. +Social media interactions have increased by 30% since the campaign launch. +Feedback: +Laura Bennett: Suggested reallocating part of the budget towards more targeted ads to maximize reach. +Sam Patel: Agreed and proposed additional influencer partnerships to maintain momentum. +5. Focus Group Planning for "Cyber Warriors": + +Jamie Lee: Provided details on the focus groups: +First session scheduled for July 28, 2024. +Participants selected from a diverse demographic to gather comprehensive feedback. +Focus will be on storyline, gameplay mechanics, and character customization. +Discussion: +Chris Martin: Suggested recording the sessions for detailed analysis and future reference. +Maria Rodriguez: Recommended involving the UX/UI team to gain insights on user experience. +6. AOB (Any Other Business): + +Alex Thompson: Announced that the Berlin office is now fully operational, with a team ready to support European operations. +Emily Carter: Proposed a wellness program for employees, including yoga sessions and mental health resources. +Next Meeting: Scheduled for August 8, 2024. +Action Items: + +David King: Finalize character models and concept art, and schedule regular review sessions. +Tina Nguyen: Execute the server stress test and report findings. +Sam Patel: Adjust marketing strategy based on metrics and explore additional influencer partnerships. +Jamie Lee: Conduct focus groups for "Cyber Warriors" and ensure UX/UI team involvement. +Emily Carter: Implement the wellness program and promote it among employees. +Meeting Adjourned at 4:30 PM. \ No newline at end of file diff --git a/5-rag-agent/requirements.txt b/5-rag-agent/requirements.txt new file mode 100644 index 0000000..b09f75c --- /dev/null +++ b/5-rag-agent/requirements.txt @@ -0,0 +1,11 @@ +openai==1.10.0 +python-dotenv==0.13.0 +langchain==0.2.6 +langchain-anthropic==0.1.16 +langchain-community==0.2.6 +langchain-core==0.2.10 +langchain-openai==0.1.10 +langchain-chroma==0.1.2 +streamlit==1.36.0 +pdfminer.six==20240706 +ustructured[all-docs] \ No newline at end of file