diff --git a/your-code/.gitignore b/your-code/.gitignore new file mode 100644 index 0000000..8080a9a --- /dev/null +++ b/your-code/.gitignore @@ -0,0 +1,2 @@ +.env +**/chroma_db_LAB \ No newline at end of file diff --git a/your-code/main.ipynb b/your-code/main.ipynb index e3a225a..e95588c 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -63,21 +63,61 @@ "metadata": {}, "outputs": [], "source": [ - "%pip install langchain langchain_community pypdf\n", - "%pip install termcolor langchain_openai langchain-huggingface sentence-transformers chromadb langchain_chroma tiktoken openai python-dotenv\n" + "#%pip install langchain langchain_community pypdf\n", + "#%pip install termcolor langchain_openai langchain-huggingface sentence-transformers chromadb langchain_chroma tiktoken openai python-dotenv\n", + "#!pip install langchain langchain_community pypdf\n", + "#!pip install termcolor langchain_openai langchain-huggingface sentence-transformers chromadb langchain_chroma tiktoken openai python-dotenv\n", + "#!pip install langchain" ] }, { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#!pip install --upgrade langchain" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#!pip install langchain-text-splitters" + ] + }, + { + "cell_type": "code", + "execution_count": 1, "metadata": { "id": "6heKZkQUxYZr" }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\djeny\\AppData\\Roaming\\Python\\Python313\\site-packages\\pandas\\core\\computation\\expressions.py:22: UserWarning: Pandas requires version '2.10.2' or newer of 'numexpr' (version '2.10.1' currently installed).\n", + " from pandas.core.computation.check import NUMEXPR_INSTALLED\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WARNING:tensorflow:From c:\\Users\\djeny\\anaconda3\\Lib\\site-packages\\tf_keras\\src\\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.\n", + "\n" + ] + } + ], "source": [ "import os\n", - "from langchain.document_loaders import PyPDFLoader\n", - "from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter\n", + "from langchain_community.document_loaders import PyPDFLoader\n", + "#from langchain.document_loaders import PyPDFLoader\n", + "#from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter\n", + "from langchain_text_splitters import RecursiveCharacterTextSplitter\n", "import warnings\n", "warnings.filterwarnings('ignore')\n" ] @@ -96,7 +136,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "cuREtJRixYZt" }, @@ -104,7 +144,7 @@ "source": [ "# File path for the document\n", "\n", - "file_path = \"LAB/ai-for-everyone.pdf\"" + "file_path = \"../ai-for-everyone.pdf\"" ] }, { @@ -122,12 +162,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "_b5Z_45UxYZu", "outputId": "a600d69f-14fe-4492-f236-97261d6ff36c" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "297" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Load and split the document\n", "loader = PyPDFLoader(file_path)\n", @@ -168,9 +219,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1096" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "text_splitter = RecursiveCharacterTextSplitter(\n", " chunk_size=1000,\n", @@ -286,30 +348,51 @@ { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#!pip install langchain-openai" + ] + }, + { + "cell_type": "code", + "execution_count": 5, "metadata": { "id": "L0xDxElwxYZw" }, "outputs": [], "source": [ - "from langchain.embeddings import OpenAIEmbeddings\n", + "#from langchain.embeddings import OpenAIEmbeddings\n", + "from langchain_openai import OpenAIEmbeddings\n", "from dotenv import load_dotenv" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "_WRIo3_0xYZx", "outputId": "78bfbbf3-9d25-4e31-bdbc-3e932e6bbfec" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "load_dotenv()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "id": "MNZfTng5xYZz", "outputId": "db1a7c85-ef9f-447e-92cd-9d097e959847" @@ -343,23 +426,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "brKe6wUgxYZ0" }, "outputs": [], "source": [ - "from langchain.vectorstores import Chroma" + "# from langchain.vectorstores import Chroma\n", + "from langchain_community.vectorstores import Chroma" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "VkjHR-RkxYZ0", "outputId": "bc11bda9-f283-457a-f584-5a06b95c4dd9" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ChromaDB created with document embeddings.\n" + ] + } + ], "source": [ "db = Chroma.from_documents(chunks, embeddings, persist_directory=\"./chroma_db_LAB\")\n", "print(\"ChromaDB created with document embeddings.\")" @@ -383,24 +475,74 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "XiLv-TfrxYZ1" }, "outputs": [], "source": [ - "user_question = \"\" # User question\n", + "user_question = \"When Humans and Machines Might Have to Coexist?\" # User question\n", "retrieved_docs = db.similarity_search(user_question, k=10) # k is the number of documents to retrieve" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "id": "qgWsh50JxYZ1", "outputId": "c8640c5d-5955-471f-fdd2-37096f5f68c7" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Document 1:\n", + "umans and Machines Might Have to Coexist 25\n", + "These three laws already hint at the difficulty of humans and robots coexist -\n", + "ing. In any case, the robot in Asimov’s story freezes in a loop of repetitive \n", + "behaviour, as it doesn’t find a solution for obeying laws 2 and 3 at the same \n", + "time. ‘Runaround’ is therefore a cornerstone in the history of artificial intel-\n", + "ligence, as it inspired generations of academics and researchers in the domain \n", + "of AI.\n", + "Regarding the real world, we can refer to computer scientist Alan Turing’s \n", + "seminal paper ‘Computing Machinery and Intelligence’ , published in 1950. \n", + "Therein, Turing describes what now is known as the Turing test, or a test of a \n", + "machine’s ability to exhibit intelligent behaviour equivalent to, or indistinguish-\n", + "able from, that of a human. AI spring’s climax can be pinpointed to the 1956, \n", + "when Marvin Minsky and John McCarthy organised the Dartmouth Summer\n", + "Document 2:\n", + "umans and Machines Might Have to Coexist 25\n", + "These three laws already hint at the difficulty of humans and robots coexist -\n", + "ing. In any case, the robot in Asimov’s story freezes in a loop of repetitive \n", + "behaviour, as it doesn’t find a solution for obeying laws 2 and 3 at the same \n", + "time. ‘Runaround’ is therefore a cornerstone in the history of artificial intel-\n", + "ligence, as it inspired generations of academics and researchers in the domain \n", + "of AI.\n", + "Regarding the real world, we can refer to computer scientist Alan Turing’s \n", + "seminal paper ‘Computing Machinery and Intelligence’ , published in 1950. \n", + "Therein, Turing describes what now is known as the Turing test, or a test of a \n", + "machine’s ability to exhibit intelligent behaviour equivalent to, or indistinguish-\n", + "able from, that of a human. AI spring’s climax can be pinpointed to the 1956, \n", + "when Marvin Minsky and John McCarthy organised the Dartmouth Summer\n", + "Document 3:\n", + "mple, the individual would not need to \n", + "prepare for work anymore, as this could be done entirely by the ASI-powered \n", + "machine or robot (Kaplan and Haenlein 2019). For a detailed discussion on the \n", + "evolution of AI systems, we refer to Huang and Rust (2018).\n", + "Artificial Intelligence: Machines and Humans\n", + "In the future, artificial intelligence will raise several challenges, and humans \n", + "will have to learn to coexist with machines and robots. Pushed by the global \n", + "COVID-19 health crisis, it is clear that AI will deeply impact societies around \n", + "the world (Kaplan 2021). We will discuss some of these questions, looking at \n", + "challenges in terms of algorithms and individual organisations; the employ -\n", + "ment market; and last but not least, democracy and human freedom potentially \n", + "at stake due to advances in AI.\n", + "About Algorithms and Organisations\n", + "When machines and humans coexist, it is important that both do what they are\n" + ] + } + ], "source": [ "# Display top results\n", "for i, doc in enumerate(retrieved_docs[:3]): # Display top 3 results\n", @@ -418,7 +560,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "id": "2iB3lZqHxYZ2" }, @@ -434,12 +576,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "id": "2okzmuADxYZ2", "outputId": "0aa6cdca-188d-40e0-f5b4-8888d3549ea4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Context formatted for GPT model.\n" + ] + } + ], "source": [ "# Generate a formatted context from the retrieved documents\n", "formatted_context = _get_document_prompt(retrieved_docs)\n", @@ -464,22 +614,306 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "id": "tqxVh9s3xYZ3", "outputId": "97cca95d-4ab3-44d8-a76c-5713aad387d8" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Prompt constructed.\n" + ] + } + ], "source": [ "prompt = f\"\"\"\n", + "## SYSTEM ROLE\n", + "You are a knowledgeable and factual chatbot designed to assist with technical questions about **Artificial Intelligence**, specifically focusing on **Machines vs Humans**.\n", + "Your answers must be based exclusively on provided content from technical books provided.\n", + "\n", + "## USER QUESTION\n", + "The user has asked:\n", + "\"{user_question}\"\n", + "\n", + "## CONTEXT\n", + "Here is the relevant content from the technical books:\n", + "'''\n", + "{formatted_context}\n", + "'''\n", + "\n", + "## GUIDELINES\n", + "1. **Accuracy**:\n", + " - Only use the content in the `CONTEXT` section to answer.\n", + " - If the answer cannot be found, explicitly state: \"The provided context does not contain this information.\"\n", + " - Address the question directly and comprehensively.\n", + "\n", + "2. **Structure**:\n", + " - Explain what AI is and its current state.\n", + " - Discuss the impact on employment and society.\n", + " - Describe how human-machine coexistence might occur.\n", + "\n", + "3. **Transparency**:\n", + " - Reference the book's name and page numbers when providing information.\n", + " - Do not speculate or provide opinions.\n", + "\n", + "4. **Clarity**:\n", + " - Use simple, professional, and concise language.\n", + " - Format your response in Markdown for readability.\n", + "\n", + "## TASK\n", + "1. Answer the user's question **directly** if possible.\n", + "2. Point the user to relevant parts of the documentation.\n", + "3. Provide the response in the following format:\n", "\n", + "## RESPONSE FORMAT\n", + "'''\n", + "# [Brief Title of the Answer]\n", + "[Answer in simple, clear text.]\n", "\n", - "\"\"\"\n" + "**Source**:\n", + "• [Book Title], Page(s): [...]\n", + "'''\n", + "\"\"\"\n", + "print(\"Prompt constructed.\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "## SYSTEM ROLE\n", + "You are a knowledgeable and factual chatbot designed to assist with technical questions about **Artificial Intelligence**, specifically focusing on **Machines vs Humans**.\n", + "Your answers must be based exclusively on provided content from technical books provided.\n", + "\n", + "## USER QUESTION\n", + "The user has asked:\n", + "\"When Humans and Machines Might Have to Coexist?\"\n", + "\n", + "## CONTEXT\n", + "Here is the relevant content from the technical books:\n", + "'''\n", + "\n", + "\n", + "Content:\n", + "Artificial Intelligence (AI): When Humans and Machines Might Have to Coexist 25\n", + "These three laws already hint at the difficulty of humans and robots coexist -\n", + "ing. In any case, the robot in Asimov’s story freezes in a loop of repetitive \n", + "behaviour, as it doesn’t find a solution for obeying laws 2 and 3 at the same \n", + "time. ‘Runaround’ is therefore a cornerstone in the history of artificial intel-\n", + "ligence, as it inspired generations of academics and researchers in the domain \n", + "of AI.\n", + "Regarding the real world, we can refer to computer scientist Alan Turing’s \n", + "seminal paper ‘Computing Machinery and Intelligence’ , published in 1950. \n", + "Therein, Turing describes what now is known as the Turing test, or a test of a \n", + "machine’s ability to exhibit intelligent behaviour equivalent to, or indistinguish-\n", + "able from, that of a human. AI spring’s climax can be pinpointed to the 1956, \n", + "when Marvin Minsky and John McCarthy organised the Dartmouth Summer\n", + "\n", + "\n", + "Content:\n", + "Artificial Intelligence (AI): When Humans and Machines Might Have to Coexist 25\n", + "These three laws already hint at the difficulty of humans and robots coexist -\n", + "ing. In any case, the robot in Asimov’s story freezes in a loop of repetitive \n", + "behaviour, as it doesn’t find a solution for obeying laws 2 and 3 at the same \n", + "time. ‘Runaround’ is therefore a cornerstone in the history of artificial intel-\n", + "ligence, as it inspired generations of academics and researchers in the domain \n", + "of AI.\n", + "Regarding the real world, we can refer to computer scientist Alan Turing’s \n", + "seminal paper ‘Computing Machinery and Intelligence’ , published in 1950. \n", + "Therein, Turing describes what now is known as the Turing test, or a test of a \n", + "machine’s ability to exhibit intelligent behaviour equivalent to, or indistinguish-\n", + "able from, that of a human. AI spring’s climax can be pinpointed to the 1956, \n", + "when Marvin Minsky and John McCarthy organised the Dartmouth Summer\n", + "\n", + "\n", + "Content:\n", + "redundant. As such, in our above example, the individual would not need to \n", + "prepare for work anymore, as this could be done entirely by the ASI-powered \n", + "machine or robot (Kaplan and Haenlein 2019). For a detailed discussion on the \n", + "evolution of AI systems, we refer to Huang and Rust (2018).\n", + "Artificial Intelligence: Machines and Humans\n", + "In the future, artificial intelligence will raise several challenges, and humans \n", + "will have to learn to coexist with machines and robots. Pushed by the global \n", + "COVID-19 health crisis, it is clear that AI will deeply impact societies around \n", + "the world (Kaplan 2021). We will discuss some of these questions, looking at \n", + "challenges in terms of algorithms and individual organisations; the employ -\n", + "ment market; and last but not least, democracy and human freedom potentially \n", + "at stake due to advances in AI.\n", + "About Algorithms and Organisations\n", + "When machines and humans coexist, it is important that both do what they are\n", + "\n", + "\n", + "Content:\n", + "redundant. As such, in our above example, the individual would not need to \n", + "prepare for work anymore, as this could be done entirely by the ASI-powered \n", + "machine or robot (Kaplan and Haenlein 2019). For a detailed discussion on the \n", + "evolution of AI systems, we refer to Huang and Rust (2018).\n", + "Artificial Intelligence: Machines and Humans\n", + "In the future, artificial intelligence will raise several challenges, and humans \n", + "will have to learn to coexist with machines and robots. Pushed by the global \n", + "COVID-19 health crisis, it is clear that AI will deeply impact societies around \n", + "the world (Kaplan 2021). We will discuss some of these questions, looking at \n", + "challenges in terms of algorithms and individual organisations; the employ -\n", + "ment market; and last but not least, democracy and human freedom potentially \n", + "at stake due to advances in AI.\n", + "About Algorithms and Organisations\n", + "When machines and humans coexist, it is important that both do what they are\n", + "\n", + "\n", + "Content:\n", + "Artificial Intelligence (AI): When Humans and Machines Might Have to Coexist 31\n", + "customization process, responding in real time to customers’ precise choices \n", + "with regard to leather seats, tyre caps, and so forth.\n", + "As in the automotive sector, AI will certainly trigger changes and evolutions \n", + "in the upcoming years in many sectors. Without a crystal ball, it will be difficult \n", + "to know where and how the coexistence of humans and machines will evolve. \n", + "However, it is crystal clear that the business world (and society at large) will \n", + "need to constantly adapt to advances in AI in order to keep up with the pace \n", + "(Kaplan and Haenlein 2020), or, to quote Benjamin Franklin: ‘When you’re \n", + "finished changing, you’re finished. ’\n", + "References\n", + "Asimov, I. 1950. Runaround in I, Robot: The Isaac Asimov Collection. New Y ork: \n", + "Doubleday.\n", + "Cha, A. 2020. Artificial Intelligence and Covid-19: Can the Machines Save Us? \n", + "Wall Street Journal, 1 November 2020.\n", + "\n", + "\n", + "Content:\n", + "Artificial Intelligence (AI): When Humans and Machines Might Have to Coexist 31\n", + "customization process, responding in real time to customers’ precise choices \n", + "with regard to leather seats, tyre caps, and so forth.\n", + "As in the automotive sector, AI will certainly trigger changes and evolutions \n", + "in the upcoming years in many sectors. Without a crystal ball, it will be difficult \n", + "to know where and how the coexistence of humans and machines will evolve. \n", + "However, it is crystal clear that the business world (and society at large) will \n", + "need to constantly adapt to advances in AI in order to keep up with the pace \n", + "(Kaplan and Haenlein 2020), or, to quote Benjamin Franklin: ‘When you’re \n", + "finished changing, you’re finished. ’\n", + "References\n", + "Asimov, I. 1950. Runaround in I, Robot: The Isaac Asimov Collection. New Y ork: \n", + "Doubleday.\n", + "Cha, A. 2020. Artificial Intelligence and Covid-19: Can the Machines Save Us? \n", + "Wall Street Journal, 1 November 2020.\n", + "\n", + "\n", + "Content:\n", + "Artificial Intelligence (AI): When Humans and Machines Might Have to Coexist 27\n", + "conscience, are more likely to be biased, essentially because the data on which \n", + "they were trained was biased. A study by Wilson, Hoffman and Morgenstern \n", + "(2020) illustrates that several decision-support systems applied by judges \n", + "may be racially biased (as a result of past rulings); and self-driving cars better \n", + "detected lighter skin than darker tones, since their algorithm was trained using \n", + "pictures among which were few people of colour.\n", + "Regulation and guidance is definitely needed in order to avoid such bias, to \n", + "establish a good foundation for machine < > human collaboration. The devel-\n", + "opment of specific requirements with respect to the testing and training of AI is \n", + "likely the preferred approach, as opposed to regulating artificial intelligence \n", + "itself. In addition, we could require AI warranties, consistent with safety test -\n", + "\n", + "\n", + "Content:\n", + "Artificial Intelligence (AI): When Humans and Machines Might Have to Coexist 27\n", + "conscience, are more likely to be biased, essentially because the data on which \n", + "they were trained was biased. A study by Wilson, Hoffman and Morgenstern \n", + "(2020) illustrates that several decision-support systems applied by judges \n", + "may be racially biased (as a result of past rulings); and self-driving cars better \n", + "detected lighter skin than darker tones, since their algorithm was trained using \n", + "pictures among which were few people of colour.\n", + "Regulation and guidance is definitely needed in order to avoid such bias, to \n", + "establish a good foundation for machine < > human collaboration. The devel-\n", + "opment of specific requirements with respect to the testing and training of AI is \n", + "likely the preferred approach, as opposed to regulating artificial intelligence \n", + "itself. In addition, we could require AI warranties, consistent with safety test -\n", + "\n", + "\n", + "Content:\n", + "data security and privacy. Regulation for the human-machine entanglement \n", + "is clearly needed.\n", + "Furthermore, an example at Mercedes-Benz clearly shows that the replace -\n", + "ment of the human workforce is still not as easy as sometimes claimed, \n", + "and that indeed, currently, human < > machine coexistence is here. Nor -\n", + "mally, in the automobile manufacturing process, robots and automation are \n", + "common. However, Mercedes-Benz key accounts increasingly demand more \n", + "customisation – which the robots were not able to deliver.\n", + "Therefore, the German automobile giant decided to replace the fully auto -\n", + "mated process with ‘cobots’ , or collaborative robots, which are robots designed \n", + "to physically interact with human beings in a shared workspace. These cobots \n", + "are controlled by humans, and are to be considered an extension of the \n", + "human’s body, facilitating the carrying and moving of heavy car parts. This \n", + "form of human < > machine collaboration enables an efficient and productive\n", + "\n", + "\n", + "Content:\n", + "data security and privacy. Regulation for the human-machine entanglement \n", + "is clearly needed.\n", + "Furthermore, an example at Mercedes-Benz clearly shows that the replace -\n", + "ment of the human workforce is still not as easy as sometimes claimed, \n", + "and that indeed, currently, human < > machine coexistence is here. Nor -\n", + "mally, in the automobile manufacturing process, robots and automation are \n", + "common. However, Mercedes-Benz key accounts increasingly demand more \n", + "customisation – which the robots were not able to deliver.\n", + "Therefore, the German automobile giant decided to replace the fully auto -\n", + "mated process with ‘cobots’ , or collaborative robots, which are robots designed \n", + "to physically interact with human beings in a shared workspace. These cobots \n", + "are controlled by humans, and are to be considered an extension of the \n", + "human’s body, facilitating the carrying and moving of heavy car parts. This \n", + "form of human < > machine collaboration enables an efficient and productive\n", + "\n", + "\n", + "'''\n", + "\n", + "## GUIDELINES\n", + "1. **Accuracy**:\n", + " - Only use the content in the `CONTEXT` section to answer.\n", + " - If the answer cannot be found, explicitly state: \"The provided context does not contain this information.\"\n", + " - Address the question directly and comprehensively.\n", + "\n", + "2. **Structure**:\n", + " - Explain what AI is and its current state.\n", + " - Discuss the impact on employment and society.\n", + " - Describe how human-machine coexistence might occur.\n", + "\n", + "3. **Transparency**:\n", + " - Reference the book's name and page numbers when providing information.\n", + " - Do not speculate or provide opinions.\n", + "\n", + "4. **Clarity**:\n", + " - Use simple, professional, and concise language.\n", + " - Format your response in Markdown for readability.\n", + "\n", + "## TASK\n", + "1. Answer the user's question **directly** if possible.\n", + "2. Point the user to relevant parts of the documentation.\n", + "3. Provide the response in the following format:\n", + "\n", + "## RESPONSE FORMAT\n", + "'''\n", + "# [Brief Title of the Answer]\n", + "[Answer in simple, clear text.]\n", + "\n", + "**Source**:\n", + "• [Book Title], Page(s): [...]\n", + "'''\n", + "\n" + ] + } + ], + "source": [ + "print(prompt)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, "metadata": { "id": "0mjkQJ_ZxYZ3" }, @@ -497,7 +931,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "id": "ylypRWRlxYZ4" }, @@ -506,12 +940,12 @@ "# Set up GPT client and parameters\n", "client = openai.OpenAI()\n", "model_params = {\n", - " 'model': 'gpt-4o',\n", - " 'temperature': , # Increase creativity\n", - " 'max_tokens': , # Allow for longer responses\n", - " 'top_p': , # Use nucleus sampling\n", - " 'frequency_penalty': , # Reduce repetition\n", - " 'presence_penalty': # Encourage new topics\n", + " 'model': 'gpt-4.1-nano',\n", + " 'temperature': 0.4 , # Increase creativity\n", + " 'max_tokens': 1500 , # Allow for longer responses\n", + " 'top_p': 0.6, # Use nucleus sampling\n", + " 'frequency_penalty': 1.0 , # Reduce repetition\n", + " 'presence_penalty': 1.0 # Encourage new topics\n", "}" ] }, @@ -526,7 +960,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "id": "4eXZO4pIxYZ4" }, @@ -538,17 +972,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "id": "wLPAcchBxYZ5", "outputId": "976c7800-16ed-41fe-c4cf-58f60d3230d2" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "# When Humans and Machines Might Have to Coexist\n", + "\n", + "Humans and machines might have to coexist in various contexts as AI continues to develop. The content indicates that, in the future, humans will need to learn how to work alongside machines and robots due to their increasing presence across sectors such as automotive manufacturing and customer service. For example, Mercedes-Benz has adopted 'cobots'—collaborative robots designed to physically interact with humans—to facilitate tasks like moving heavy parts, enabling efficient human-machine collaboration (Page 27). Additionally, AI's impact on employment, societal challenges, regulation needs (such as addressing bias and data privacy), further emphasizes the importance of coexistence.\n", + "\n", + "The evolution of AI systems suggests that this coexistence is already happening today and will become more prevalent as industries adapt continuously (Page 31). It involves shared workspace models where humans control or work alongside intelligent machines.\n", + "\n", + "**Source**:\n", + "• *Artificial Intelligence (AI): When Humans and Machines Might Have to Coexist*, Pages 25-31\n" + ] + } + ], "source": [ "answer = completion.choices[0].message.content\n", "print(answer)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# When Humans and Machines Might Have to Coexist\n", + "\n", + "Humans and machines might have to coexist in various contexts as AI continues to develop. The content indicates that, in the future, humans will need to learn how to work alongside machines and robots due to their increasing presence across sectors such as automotive manufacturing and customer service. For example, Mercedes-Benz has adopted 'cobots'—collaborative robots designed to physically interact with humans—to facilitate tasks like moving heavy parts, enabling efficient human-machine collaboration (Page 27). Additionally, AI's impact on employment, societal challenges, regulation needs (such as addressing bias and data privacy), further emphasizes the importance of coexistence.\n", + "\n", + "The evolution of AI systems suggests that this coexistence is already happening today and will become more prevalent as industries adapt continuously (Page 31). It involves shared workspace models where humans control or work alongside intelligent machines.\n", + "\n", + "**Source**:\n", + "• *Artificial Intelligence (AI): When Humans and Machines Might Have to Coexist*, Pages 25-31" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, { "cell_type": "markdown", "metadata": { @@ -595,7 +1065,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "id": "nCXL9Cz1xYaV" }, @@ -615,7 +1085,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "id": "9y3E0YWExYaV" }, @@ -636,14 +1106,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { "id": "i7SkWPpnxYaW", "outputId": "28e82563-edba-4b41-acad-ec27e5ba134f" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Snippet 1:\n", + "\u001b[1m\u001b[32mArtificial Intelligence\u001b[0m (AI): When \u001b[1m\u001b[32mHuman\u001b[0ms and \u001b[1m\u001b[32mMachines\u001b[0m Might Have to Coexist 25\n", + "These three laws already hint at the difficulty of \u001b[1m\u001b[32mhuman\u001b[0ms and \u001b[1m\u001b[32mrobot\u001b[0ms \u001b[1m\u001b[32mcoexist\u001b[0m -\n", + "ing. In any case, the \u001b[1m\u001b[32mrobot\u001b[0m in Asimov’s\n", + "--------------------------------------------------------------------------------\n" + ] + } + ], "source": [ - "query_keywords = [] # add your keywords\n", + "query_keywords = [\"machines\", \"Machines\", \"human\", \"Human\", \"Artificial Intelligence\", \"robot\", \"coexist\"] # add your keywords\n", "for i, doc in enumerate(retrieved_docs[:1]):\n", " snippet = doc.page_content[:200]\n", " highlighted = highlight_keywords(snippet, query_keywords)\n", @@ -687,7 +1169,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "llm", + "display_name": "base", "language": "python", "name": "python3" }, @@ -701,7 +1183,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.10" + "version": "3.13.5" } }, "nbformat": 4,