{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "from langchain_community.vectorstores import Qdrant" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from qdrant_client import QdrantClient, models\n", "\n", "client = QdrantClient(path=\"Qdrant_db\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from langchain_openai.embeddings import OpenAIEmbeddings\n", "\n", "embedding_model = OpenAIEmbeddings(model=\"text-embedding-3-small\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "collection_name = \"AML_act\"\n", "qdrant = Qdrant(client, collection_name, embedding_model)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "qdrant_retriever = qdrant.as_retriever()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[Document(page_content='• \\nElectronic funds transfer instructions must include certain \\ninformation about the origin of the transferred money. \\nAuthorised Version C2023C00383 registered 31/10/2023', metadata={'source': 'Data/C2023C00383.pdf', 'file_path': 'Data/C2023C00383.pdf', 'page': 145, 'total_pages': 380, 'format': 'PDF 1.4', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Aspose Ltd.', 'producer': 'Aspose.PDF for .NET 22.3.0', 'creationDate': \"D:20231030233312+00'00'\", 'modDate': \"D:20231030233758+00'00'\", 'trapped': '', '_id': 'c1c8fc0171174a4a9735884c62aaafd9', '_collection_name': 'AML_act'}),\n", " Document(page_content='the notice) to include required transfer information in all \\nfuture electronic funds transfer instructions passed on by the \\nordering institution to the beneficiary institution; \\nthe beneficiary institution must comply with the direction within \\n10 business days after the day on which the direction is given. \\nReport by beneficiary institution', metadata={'source': 'Data/C2023C00383.pdf', 'file_path': 'Data/C2023C00383.pdf', 'page': 150, 'total_pages': 380, 'format': 'PDF 1.4', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Aspose Ltd.', 'producer': 'Aspose.PDF for .NET 22.3.0', 'creationDate': \"D:20231030233312+00'00'\", 'modDate': \"D:20231030233758+00'00'\", 'trapped': '', '_id': 'e11b10d89d8c4db8a8ed185c353def33', '_collection_name': 'AML_act'}),\n", " Document(page_content='international electronic funds transfer instructions ........................ \\n134 \\nDivision 3—Only one institution involved in the transfer \\n137 \\n66 \\nElectronic funds transfer instructions—only one institution \\ninvolved in the transfer .................................................................. \\n137 \\nDivision 4—General provisions \\n139 \\n67 \\nExemptions', metadata={'source': 'Data/C2023C00383.pdf', 'file_path': 'Data/C2023C00383.pdf', 'page': 5, 'total_pages': 380, 'format': 'PDF 1.4', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Aspose Ltd.', 'producer': 'Aspose.PDF for .NET 22.3.0', 'creationDate': \"D:20231030233312+00'00'\", 'modDate': \"D:20231030233758+00'00'\", 'trapped': '', '_id': 'e9a739946a5245ba9d82436a16d2fd0e', '_collection_name': 'AML_act'}),\n", " Document(page_content='involved in the transfer \\nScope \\n \\n(1) This section applies to: \\n \\n(a) a multiple-institution person-to-person electronic funds \\ntransfer instruction; or \\n \\n(b) a multiple-institution same-person electronic funds transfer \\ninstruction. \\nNote: \\nFor exemptions, see section 67. \\nFunds transfer chain \\n \\n(2) For the purposes of this Act: \\n \\n(a) the following persons are taken to form a funds transfer', metadata={'source': 'Data/C2023C00383.pdf', 'file_path': 'Data/C2023C00383.pdf', 'page': 146, 'total_pages': 380, 'format': 'PDF 1.4', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Aspose Ltd.', 'producer': 'Aspose.PDF for .NET 22.3.0', 'creationDate': \"D:20231030233312+00'00'\", 'modDate': \"D:20231030233758+00'00'\", 'trapped': '', '_id': 'fa2f8bef0dc54678b10cadc77de6b863', '_collection_name': 'AML_act'})]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query = \"do i need transfer information when receiving an electronic funds transfer?\"\n", "qdrant_retriever.invoke(query)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "from langchain_openai import ChatOpenAI\n", "\n", "openai_chat_model = ChatOpenAI(model=\"gpt-3.5-turbo\")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "from langchain_core.prompts import ChatPromptTemplate" ] }, { "cell_type": "code", "execution_count": 126, "metadata": {}, "outputs": [], "source": [ "system_message = \"You are a helpful assistante, experienced lawyer and an expert reading SECURITIES AND EXCHANGE COMMISSION documents\"" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "RAG_PROMPT = \"\"\"\n", "\n", "CONTEXT:\n", "{context}\n", "\n", "QUERY:\n", "{question}\n", "\n", "Answer the query above using the context provided. If you don't know the answer responde with: I don't know\n", "\"\"\"\n", "\n", "rag_prompt = ChatPromptTemplate.from_template(RAG_PROMPT)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "from langchain.retrievers import MultiQueryRetriever\n", "\n", "advanced_retriever = MultiQueryRetriever.from_llm(retriever=qdrant_retriever, llm=openai_chat_model)\n" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ChatPromptTemplate(input_variables=['context', 'question', 'system_message'], messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['context', 'question', 'system_message'], template=\"\\n\\nSYSTEM:\\n{system_message}\\n\\nCONTEXT:\\n{context}\\n\\nQUERY:\\n{question}\\n\\nAnswer the query above only using the context provided. If you don't know the answer responde with: I don't know\\n\"))])" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rag_prompt" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "from operator import itemgetter\n", "from langchain.schema.output_parser import StrOutputParser\n", "from langchain.schema.runnable import RunnablePassthrough\n", "\n", "retrieval_augmented_qa_chain = (\n", " # INVOKE CHAIN WITH: {\"question\" : \"<>\"}\n", " # \"question\" : populated by getting the value of the \"question\" key\n", " # \"context\" : populated by getting the value of the \"question\" key and chaining it into the base_retriever\n", " {\"context\": itemgetter(\"question\") | advanced_retriever, \"question\": itemgetter(\"question\")}\n", " # \"context\" : is assigned to a RunnablePassthrough object (will not be called or considered in the next step)\n", " # by getting the value of the \"context\" key from the previous step\n", " | RunnablePassthrough.assign(context=itemgetter(\"context\"))\n", " # \"response\" : the \"context\" and \"question\" values are used to format our prompt object and then piped\n", " # into the LLM and stored in a key called \"response\"\n", " # \"context\" : populated by getting the value of the \"context\" key from the previous step\n", " | {\"response\": rag_prompt | openai_chat_model, \"context\": itemgetter(\"context\")}\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\"What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\"\n", "\n", "\"Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\"" ] }, { "cell_type": "code", "execution_count": 103, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "AIMessage(content=\"I don't know\", response_metadata={'token_usage': {'completion_tokens': 4, 'prompt_tokens': 49, 'total_tokens': 53}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3b956da36b', 'finish_reason': 'stop', 'logprobs': None}, id='run-6ad6e2e1-23e4-4aa7-a17c-12beea722db8-0')" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "retr = (rag_prompt | openai_chat_model)\n", "resp = retr.invoke({\"question\" : \"What was the total value \", \"context\": \"sdfsfsdfs\", \"system_message\" : \"dfgdfg\"})\n", "resp" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'The AML/CTF Rules are made by the AUSTRAC CEO through writing, as specified in the provided document.'" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "response = retrieval_augmented_qa_chain.invoke({\"question\" : \"where are the aml ctf rules?\"})\n", "response[\"response\"].content" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'response': AIMessage(content='The session that refers to receiving an electronic funds transfer is the \"Retention of records about electronic funds transfer instructions\" as mentioned in the provided context.', response_metadata={'token_usage': {'completion_tokens': 29, 'prompt_tokens': 1570, 'total_tokens': 1599}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-b94961ae-9987-4b48-aa9e-c9938670093c-0'),\n", " 'context': [Document(page_content='electronic funds transfer instructions \\nScope \\n \\n(1) This section applies to: \\n \\n(a) a multiple-institution person-to-person electronic funds \\ntransfer instruction; or \\n \\n(b) a multiple-institution same-person electronic funds transfer \\ninstruction; \\nif: \\n \\n(c) the instruction is accepted at or through a permanent \\nestablishment of the ordering institution in a foreign country; \\nand', metadata={'source': 'Data/C2023C00383.pdf', 'file_path': 'Data/C2023C00383.pdf', 'page': 149, 'total_pages': 380, 'format': 'PDF 1.4', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Aspose Ltd.', 'producer': 'Aspose.PDF for .NET 22.3.0', 'creationDate': \"D:20231030233312+00'00'\", 'modDate': \"D:20231030233758+00'00'\", 'trapped': '', '_id': 'f9116df7f5004004b74e1392c32938ad', '_collection_name': 'AML_act'}),\n", " Document(page_content='involved in the transfer \\nScope \\n \\n(1) This section applies to: \\n \\n(a) a same-institution person-to-person electronic funds transfer \\ninstruction; or \\n \\n(b) a same-institution same-person electronic funds transfer \\ninstruction if the instruction is to be carried out otherwise \\nthan by way of transferring money from an account held by', metadata={'source': 'Data/C2023C00383.pdf', 'file_path': 'Data/C2023C00383.pdf', 'page': 152, 'total_pages': 380, 'format': 'PDF 1.4', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Aspose Ltd.', 'producer': 'Aspose.PDF for .NET 22.3.0', 'creationDate': \"D:20231030233312+00'00'\", 'modDate': \"D:20231030233758+00'00'\", 'trapped': '', '_id': '1dd31cfc490b4ccea8345de08fcc36a8', '_collection_name': 'AML_act'}),\n", " Document(page_content='115 Retention of records about electronic funds transfer instructions \\nScope \\n \\n(1) This section applies if: \\n \\n(a) section 64 applies to: \\n \\n(i) a multiple-institution person-to-person electronic funds \\ntransfer instruction; or \\n \\n(ii) a multiple-institution same-person electronic funds \\ntransfer instruction; and \\n \\n(b) a person is in the funds transfer chain; and', metadata={'source': 'Data/C2023C00383.pdf', 'file_path': 'Data/C2023C00383.pdf', 'page': 227, 'total_pages': 380, 'format': 'PDF 1.4', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Aspose Ltd.', 'producer': 'Aspose.PDF for .NET 22.3.0', 'creationDate': \"D:20231030233312+00'00'\", 'modDate': \"D:20231030233758+00'00'\", 'trapped': '', '_id': '255c21868ac04f3eb88cf066c9e67b6c', '_collection_name': 'AML_act'}),\n", " Document(page_content='Same-institution person-to-person electronic funds transfer \\ninstruction \\n \\n(2) For the purposes of this Act, if: \\n \\n(a) a person (the payer) instructs a person (the ordering \\ninstitution) to transfer money controlled by the payer to a \\nthird person (the payee) on the basis that the transferred \\nmoney will be made available to the payee by:', metadata={'source': 'Data/C2023C00383.pdf', 'file_path': 'Data/C2023C00383.pdf', 'page': 78, 'total_pages': 380, 'format': 'PDF 1.4', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Aspose Ltd.', 'producer': 'Aspose.PDF for .NET 22.3.0', 'creationDate': \"D:20231030233312+00'00'\", 'modDate': \"D:20231030233758+00'00'\", 'trapped': '', '_id': 'a92121cf5edc4032a76471deb257e880', '_collection_name': 'AML_act'}),\n", " Document(page_content='• \\nElectronic funds transfer instructions must include certain \\ninformation about the origin of the transferred money. \\nAuthorised Version C2023C00383 registered 31/10/2023', metadata={'source': 'Data/C2023C00383.pdf', 'file_path': 'Data/C2023C00383.pdf', 'page': 145, 'total_pages': 380, 'format': 'PDF 1.4', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Aspose Ltd.', 'producer': 'Aspose.PDF for .NET 22.3.0', 'creationDate': \"D:20231030233312+00'00'\", 'modDate': \"D:20231030233758+00'00'\", 'trapped': '', '_id': 'c1c8fc0171174a4a9735884c62aaafd9', '_collection_name': 'AML_act'}),\n", " Document(page_content='involved in the transfer \\nScope \\n \\n(1) This section applies to: \\n \\n(a) a multiple-institution person-to-person electronic funds \\ntransfer instruction; or \\n \\n(b) a multiple-institution same-person electronic funds transfer \\ninstruction. \\nNote: \\nFor exemptions, see section 67. \\nFunds transfer chain \\n \\n(2) For the purposes of this Act: \\n \\n(a) the following persons are taken to form a funds transfer', metadata={'source': 'Data/C2023C00383.pdf', 'file_path': 'Data/C2023C00383.pdf', 'page': 146, 'total_pages': 380, 'format': 'PDF 1.4', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'creator': 'Aspose Ltd.', 'producer': 'Aspose.PDF for .NET 22.3.0', 'creationDate': \"D:20231030233312+00'00'\", 'modDate': \"D:20231030233758+00'00'\", 'trapped': '', '_id': 'fa2f8bef0dc54678b10cadc77de6b863', '_collection_name': 'AML_act'})]}" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "response" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q: do i need transfer information when receiving an electronic funds transfer\n", "A:\n", "\n", "Q:what session refers to receiving an electronic funds transfer?\n", "A:'The session that refers to receiving an electronic funds transfer is the \"Retention of records about electronic funds transfer instructions\" as mentioned in the provided context.'\n", "\n", "Q:Where can I find the specific requirements and procedures for Customer Due Diligence (CDD) under AML/CTF Act 2006 ?\n", "A:'You can find the specific requirements and procedures for Customer Due Diligence (CDD) under the AML/CTF Act 2006 in Part 2, Division 6, Section 36 of the Anti-Money Laundering and Counter-Terrorism Financing Act 2006.'\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] } ], "metadata": { "kernelspec": { "display_name": "Doc-Expert", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.19" } }, "nbformat": 4, "nbformat_minor": 2 }