├── .cache ├── 43 │ └── cache.db ├── 50 │ └── cache.db ├── 54 │ └── cache.db ├── 57 │ └── cache.db ├── 59 │ ├── cache.db │ ├── cache.db-shm │ └── cache.db-wal ├── 60 │ └── cache.db ├── 70 │ └── cache.db ├── 77 │ └── cache.db ├── 90 │ └── cache.db ├── 99 │ └── cache.db └── 100 │ └── cache.db ├── AI safety summit 2023 agent trace v2.txt ├── __pycache__ └── utils.cpython-39.pyc ├── archive ├── autogen_tutorial.ipynb ├── autogen_tutorial_v2.ipynb ├── autogen_tutorial_v3.ipynb ├── autogen_tutorial_v4.ipynb └── autogen_tutorial_v5.ipynb ├── autogen_tutorial_notebook.ipynb ├── configurations.json ├── indexes ├── Docs from Wikipedia ├── docstore.json ├── graph_store.json ├── index_store.json ├── retrieved_context.json └── vector_store.json ├── q2 How many Germans live in the colonial agent trace.txt └── requirements.txt /.cache/100/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/100/cache.db -------------------------------------------------------------------------------- /.cache/43/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/43/cache.db -------------------------------------------------------------------------------- /.cache/50/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/50/cache.db -------------------------------------------------------------------------------- /.cache/54/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/54/cache.db -------------------------------------------------------------------------------- /.cache/57/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/57/cache.db -------------------------------------------------------------------------------- /.cache/59/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/59/cache.db -------------------------------------------------------------------------------- /.cache/59/cache.db-shm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/59/cache.db-shm -------------------------------------------------------------------------------- /.cache/59/cache.db-wal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/59/cache.db-wal -------------------------------------------------------------------------------- /.cache/60/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/60/cache.db -------------------------------------------------------------------------------- /.cache/70/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/70/cache.db -------------------------------------------------------------------------------- /.cache/77/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/77/cache.db -------------------------------------------------------------------------------- /.cache/90/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/90/cache.db -------------------------------------------------------------------------------- /.cache/99/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/.cache/99/cache.db -------------------------------------------------------------------------------- /AI safety summit 2023 agent trace v2.txt: -------------------------------------------------------------------------------- 1 | chat_manager (to chat_manager): 2 | 3 | What were the key points raised in the 2023 AI safety Summit? 4 | 5 | -------------------------------------------------------------------------------- 6 | analyst (to chat_manager): 7 | 8 | ***** Suggested function Call: search_and_index_wikipedia ***** 9 | Arguments: 10 | {"hops":["2023 AI safety Summit","Key points raised in the 2023 AI safety Summit"]} 11 | *************************************************************** 12 | 13 | -------------------------------------------------------------------------------- 14 | 15 | >>>>>>>> EXECUTING FUNCTION search_and_index_wikipedia... 16 | Searching Wikipedia for: 2023 AI safety Summit - Found: ['2023 AI Safety Summit', 'AI safety'] 17 | Searching Wikipedia for: Key points raised in the 2023 AI safety Summit - Found: ['2023 AI Safety Summit', 'Regulation of artificial intelligence'] 18 | Preparing to index Wikipages: ['2023 AI Safety Summit', 'AI safety', '2023 AI Safety Summit', 'Regulation of artificial intelligence'] 19 | Preparing to Download:['2023 AI Safety Summit', 'AI safety', '2023 AI Safety Summit', 'Regulation of artificial intelligence'] 20 | Finished downloading pages 21 | ['2023 AI Safety Summit', 'AI safety', '2023 AI Safety Summit', 'Regulation of artificial intelligence'] have been indexed. 22 | user_proxy (to chat_manager): 23 | 24 | ***** Response from calling function "search_and_index_wikipedia" ***** 25 | ['2023 AI Safety Summit', 'AI safety', '2023 AI Safety Summit', 'Regulation of artificial intelligence'] 26 | *********************************************************************** 27 | 28 | -------------------------------------------------------------------------------- 29 | analyst (to chat_manager): 30 | 31 | ***** Suggested function Call: query_wiki_index ***** 32 | Arguments: 33 | {"hops":["2023 AI safety Summit","Key points raised in the 2023 AI safety Summit"]} 34 | ***************************************************** 35 | 36 | -------------------------------------------------------------------------------- 37 | 38 | >>>>>>>> EXECUTING FUNCTION query_wiki_index... 39 | user_proxy (to chat_manager): 40 | 41 | ***** Response from calling function "query_wiki_index" ***** 42 | {'042edef9-b751-4724-8c31-1b1c502bdbc4': {'texts': ['The AI Safety Summit was an international conference discussing the safety and regulation of artificial intelligence. It was held at Bletchley Park, Milton Keynes, United Kingdom, on 1–2 November 2023. It was the first ever global summit on artificial intelligence.\n\n\n== Background ==\nThe prime minister of the United Kingdom, Rishi Sunak, has made AI one of the priorities of his government, announcing that the UK would host a global AI Safety conference in autumn 2023.', 'The AI Safety Summit was an international conference discussing the safety and regulation of artificial intelligence. It was held at Bletchley Park, Milton Keynes, United Kingdom, on 1–2 November 2023. It was the first ever global summit on artificial intelligence.\n\n\n== Background ==\nThe prime minister of the United Kingdom, Rishi Sunak, has made AI one of the priorities of his government, announcing that the UK would host a global AI Safety conference in autumn 2023.'], 'sources': ['https://en.wikipedia.org/wiki/2023_AI_Safety_Summit', 'https://en.wikipedia.org/wiki/2023_AI_Safety_Summit']}, 'eb7882f6-cda1-4c50-b0de-c670755f0775': {'texts': ['The AI Safety Summit was an international conference discussing the safety and regulation of artificial intelligence. It was held at Bletchley Park, Milton Keynes, United Kingdom, on 1–2 November 2023. It was the first ever global summit on artificial intelligence.\n\n\n== Background ==\nThe prime minister of the United Kingdom, Rishi Sunak, has made AI one of the priorities of his government, announcing that the UK would host a global AI Safety conference in autumn 2023.', 'The AI Safety Summit was an international conference discussing the safety and regulation of artificial intelligence. It was held at Bletchley Park, Milton Keynes, United Kingdom, on 1–2 November 2023. It was the first ever global summit on artificial intelligence.\n\n\n== Background ==\nThe prime minister of the United Kingdom, Rishi Sunak, has made AI one of the priorities of his government, announcing that the UK would host a global AI Safety conference in autumn 2023.'], 'sources': ['https://en.wikipedia.org/wiki/2023_AI_Safety_Summit', 'https://en.wikipedia.org/wiki/2023_AI_Safety_Summit']}, '3aca4643-ff45-4ebb-a3bf-a2d0e7770665': {'texts': ['The US government also announced the creation of an American AI Safety Institute, as part of the National Institute of Standards and Technology.\n\n\n== Future ==\nThe next AI Safety Summit is planned to be hosted by South Korea in mid-2024, followed by France around late-2024.\n\n\n== Notable attendees ==\nThe following individuals are expected to attend the summit:\nRishi Sunak, prime minister of the United Kingdom\nKamala Harris, vice president of the United States\nCharles III, king of the United Kingdom (attending virtually)\nElon Musk, CEO of Tesla,'], 'sources': ['https://en.wikipedia.org/wiki/2023_AI_Safety_Summit']}, 'fd8e1107-a286-4a48-8433-ce7067338e76': {'texts': ['The US government also announced the creation of an American AI Safety Institute, as part of the National Institute of Standards and Technology.\n\n\n== Future ==\nThe next AI Safety Summit is planned to be hosted by South Korea in mid-2024, followed by France around late-2024.\n\n\n== Notable attendees ==\nThe following individuals are expected to attend the summit:\nRishi Sunak, prime minister of the United Kingdom\nKamala Harris, vice president of the United States\nCharles III, king of the United Kingdom (attending virtually)\nElon Musk, CEO of Tesla,'], 'sources': ['https://en.wikipedia.org/wiki/2023_AI_Safety_Summit']}, '7c9c08cc-729b-46a0-9d97-9db67fd7a53f': {'texts': ['== Agenda ==\nThe tech entrepreneur Elon Musk and Sunak did a live interview on AI safety on 2 November on X.\n\n\n== Outcomes ==\n28 countries at the summit, including the United States, China, and the European Union, have issued an agreement known as the Bletchley Declaration, calling for international co-operation to manage the challenges and risks of artificial intelligence. Emphasis has been placed on regulating "Frontier AI", a term for the latest and most powerful AI systems.', '== Agenda ==\nThe tech entrepreneur Elon Musk and Sunak did a live interview on AI safety on 2 November on X.\n\n\n== Outcomes ==\n28 countries at the summit, including the United States, China, and the European Union, have issued an agreement known as the Bletchley Declaration, calling for international co-operation to manage the challenges and risks of artificial intelligence. Emphasis has been placed on regulating "Frontier AI", a term for the latest and most powerful AI systems.'], 'sources': ['https://en.wikipedia.org/wiki/2023_AI_Safety_Summit', 'https://en.wikipedia.org/wiki/2023_AI_Safety_Summit']}, '46660992-36a4-450e-bc57-4871f3733ad0': {'texts': ['Emphasis has been placed on regulating "Frontier AI", a term for the latest and most powerful AI systems. Concerns that have been raised at the summit include the potential use of AI for terrorism, criminal activity, and warfare, as well as existential risk posed to humanity as a whole.\nThe president of the United States, Joe Biden, signed an executive order requiring AI developers to share safety results with the US government. The US government also announced the creation of an American AI Safety Institute, as part of the National Institute of Standards and Technology.'], 'sources': ['https://en.wikipedia.org/wiki/2023_AI_Safety_Summit']}, '0d299ea1-def4-4e06-8320-c1c351cefe01': {'texts': ['Emphasis has been placed on regulating "Frontier AI", a term for the latest and most powerful AI systems. Concerns that have been raised at the summit include the potential use of AI for terrorism, criminal activity, and warfare, as well as existential risk posed to humanity as a whole.\nThe president of the United States, Joe Biden, signed an executive order requiring AI developers to share safety results with the US government. The US government also announced the creation of an American AI Safety Institute, as part of the National Institute of Standards and Technology.'], 'sources': ['https://en.wikipedia.org/wiki/2023_AI_Safety_Summit']}} 43 | ************************************************************* 44 | 45 | -------------------------------------------------------------------------------- 46 | reporter (to chat_manager): 47 | 48 | The 2023 AI Safety Summit was a landmark international conference that focused on discussing the safety and regulation of artificial intelligence. The key points raised during this event are significant in guiding the future of AI governance. Here's an outline of the crucial issues highlighted at the summit: 49 | 50 | 1. The Bletchley Declaration: 28 countries, including the United States, China, and the European Union, issued the Bletchley Declaration, which calls for international cooperation to address the challenges and risks posed by artificial intelligence. The declaration put a strong emphasis on regulating "Frontier AI," which refers to the most advanced and powerful AI systems[1][5]. 51 | 52 | 2. Regulation of Frontier AI: This term was used at the summit to describe the latest and most powerful AI technologies. The summit underscored the need to ensure that these technologies are developed and used in ways that are safe and beneficial for society[5][6]. 53 | 54 | 3. Potential Dangers of AI: The summit discussed the potential utilization of AI for terrorism, criminal activities, and warfare. There was also a conversation about the existential risks that AI could pose to humanity as a whole[6][7]. 55 | 56 | 4. US Initiatives: In response to the discussions at the summit, the President of the United States, Joe Biden, signed an executive order requiring AI developers to share safety results with the US government. Additionally, the US government announced the creation of an American AI Safety Institute under the National Institute of Standards and Technology[3][6]. 57 | 58 | 5. Notable Attendees and Future Summits: Attendees included prominent figures like Rishi Sunak, the Prime Minister of the United Kingdom; Kamala Harris, the Vice President of the United States; and Elon Musk, the CEO of Tesla. The next AI Safety Summit is planned to be hosted by South Korea in mid-2024, followed by one in France around late-2024[3][4]. 59 | 60 | 6. Live Interview on AI Safety: Elon Musk and Rishi Sunak participated in a live interview on AI safety on the second day of the summit, further emphasizing the importance of the topic[5]. 61 | 62 | The 2023 AI Safety Summit at Bletchley Park marked the first global summit dedicated to artificial intelligence, setting a precedent for the international community's approach to AI safety and regulation[1][2]. 63 | 64 | PLEASE REVIEW 65 | 66 | References 67 | 1. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 68 | 2. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 69 | 3. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 70 | 4. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 71 | 5. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 72 | 6. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 73 | 7. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 74 | 75 | -------------------------------------------------------------------------------- 76 | moderator (to chat_manager): 77 | 78 | The answer requires revisions for the following reasons: 79 | 80 | A. Precision: The answer addresses the user's question regarding the key points raised at the 2023 AI Safety Summit. 81 | 82 | B. Depth: The answer provides comprehensive information about the key points discussed at the summit, but there are duplicate citations for the same source. 83 | 84 | C. Citing: The citations need to be corrected to comply with the Vancouver citation style. Each citation should correspond to a unique reference, and they should be listed at the end of the document in numerical order as they appear in the text. 85 | 86 | D. Clarity: The information is presented logically and coherently. 87 | 88 | Reporter, please revise the answer by ensuring each citation number corresponds to a unique reference and is listed at the end of the report in numerical order as they appear in the text. Remove duplicate citations and correct the citation style accordingly. 89 | 90 | -------------------------------------------------------------------------------- 91 | reporter (to chat_manager): 92 | 93 | The 2023 AI Safety Summit was a significant international conference that delved into the safety and regulation of artificial intelligence. The key points raised during the summit are critical for shaping the future framework of AI oversight. Here are the main issues that were highlighted: 94 | 95 | 1. The Bletchley Declaration: Countries that participated in the summit, which included the United States, China, and the European Union among the 28 in total, issued an agreement called the Bletchley Declaration. This declaration emphasized the need for international cooperation to manage the challenges and risks associated with artificial intelligence, with a particular focus on the regulation of "Frontier AI," the term used to describe the most advanced AI systems[1]. 96 | 97 | 2. Regulation of Frontier AI: The discussions at the summit underlined the importance of regulating these advanced AI technologies to ensure their safety and benefit to society[2]. 98 | 99 | 3. Addressing Dangers of AI: There was a conversation about the potential misuse of AI for terrorism, criminal activities, and warfare, as well as the existential threats that AI could pose to humanity[2]. 100 | 101 | 4. US Response: Following the summit discussions, President Joe Biden of the United States signed an executive order that mandates AI developers to disclose safety results to the US government. The US also took initiative by announcing the establishment of an American AI Safety Institute under the National Institute of Standards and Technology[3]. 102 | 103 | 5. Future Summits and Notable Participants: The summit was attended by key figures such as Rishi Sunak, Prime Minister of the United Kingdom; Kamala Harris, Vice President of the United States; and Elon Musk, CEO of Tesla. Plans for future AI Safety Summits include one to be hosted by South Korea in mid-2024, and another in France towards the end of 2024[4]. 104 | 105 | 6. Highlight on AI Safety: A noteworthy event at the summit was a live interview on AI safety featuring Elon Musk and Rishi Sunak, which took place on November 2nd[5]. 106 | 107 | Hosted at Bletchley Park, the 2023 AI Safety Summit marked the first-ever global meeting focused on the topic of artificial intelligence, establishing a foundational dialogue for international collaboration on AI safety and regulation[1]. 108 | 109 | PLEASE REVIEW 110 | 111 | References 112 | 1. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 113 | 2. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 114 | 3. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 115 | 4. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 116 | 5. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 117 | 118 | -------------------------------------------------------------------------------- 119 | moderator (to chat_manager): 120 | 121 | The answer requires revisions for the following reasons: 122 | 123 | C. Citing: The citations still need to be corrected to comply with the Vancouver citation style. Each citation should correspond to a unique reference. Since all the citations refer to the same Wikipedia page, they should be consolidated into a single reference listed at the end of the document. Each point should be followed by the citation number once, rather than repeating the same citation for each point. 124 | 125 | Reporter, please revise the answer by consolidating the citations into a single reference and ensure that the citation number corresponds to it. Use the citation number once at the end of the report, rather than repeating it for each point. 126 | 127 | -------------------------------------------------------------------------------- 128 | reporter (to chat_manager): 129 | 130 | The 2023 AI Safety Summit was a pivotal international conference focused on discussing the safety and regulation of artificial intelligence. Here are the primary issues that were brought to the forefront during this event: 131 | 132 | 1. The Bletchley Declaration: The summit led to the issuance of the Bletchley Declaration by 28 countries, including the United States, China, and the European Union. This agreement calls for international cooperation to tackle the challenges and risks associated with artificial intelligence, with special attention given to "Frontier AI," which refers to the latest and most advanced AI systems[1]. 133 | 134 | 2. Concerns About Frontier AI: The summit discussions stressed the importance of regulating these cutting-edge AI technologies to ensure they are developed and utilized in a manner that is safe and beneficial for society[1]. 135 | 136 | 3. AI and Potential Misuse: Risks associated with the potential use of AI for terrorism, criminal activities, and warfare were addressed. Additionally, the existential threat that AI could pose to humanity was acknowledged[1]. 137 | 138 | 4. US Government's Response: In response to the summit, President Joe Biden of the United States signed an executive order requiring AI developers to report safety results to the US government. The creation of an American AI Safety Institute, as part of the National Institute of Standards and Technology, was also announced[1]. 139 | 140 | 5. Notable Attendees and Future Summits: Notable figures such as Rishi Sunak, Prime Minister of the United Kingdom; Kamala Harris, Vice President of the United States; and Elon Musk, CEO of Tesla were in attendance. The next AI Safety Summits are planned to be hosted by South Korea in mid-2024, followed by France later that year[1]. 141 | 142 | 6. Focus on AI Safety: A key event at the summit was a live interview on AI safety conducted with Elon Musk and Rishi Sunak on November 2nd[1]. 143 | 144 | The 2023 AI Safety Summit at Bletchley Park was the first global summit dedicated exclusively to the subject of artificial intelligence, setting a precedent for international collaboration and discourse on AI safety and regulation[1]. 145 | 146 | PLEASE REVIEW 147 | 148 | References 149 | 1. Wikipedia. Available from: https://en.wikipedia.org/wiki/2023_AI_Safety_Summit 150 | 151 | -------------------------------------------------------------------------------- 152 | moderator (to chat_manager): 153 | 154 | The answer is approved. 155 | 156 | -------------------------------------------------------------------------------- 157 | user_proxy (to chat_manager): 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- 162 | reporter (to chat_manager): 163 | 164 | TERMINATE 165 | 166 | -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /__pycache__/utils.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/john-adeojo/autogen_tutorial/58c469de718da7c07213c0247bf7fc5aa0905cdb/__pycache__/utils.cpython-39.pyc -------------------------------------------------------------------------------- /archive/autogen_tutorial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Auto Gen Tutorial\n", 8 | "Note book written by John Adeojo\n", 9 | "Founder, and Chief Data Scientist at [Data-centric Solutions](https://www.data-centric-solutions.com/)\n" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 1, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "import autogen\n", 19 | "import yaml\n", 20 | "import openai \n", 21 | "import os\n", 22 | "\n", 23 | "script_dir = \"C:/Users/johna/OneDrive/Documents/api_keys/\"\n", 24 | "index_path = \"G:/My Drive/Data-Centric Solutions/07. Blog Posts/AutoGen/autogen_tutorial/indexes/\"\n", 25 | "configurations_path = \"G:/My Drive/Data-Centric Solutions/07. Blog Posts/AutoGen/autogen_tutorial/\"\n", 26 | "\n", 27 | "config_list = autogen.config_list_from_json(\n", 28 | " env_or_file=\"configurations.json\",\n", 29 | " file_location=configurations_path,\n", 30 | " filter_dict={\n", 31 | " \"model\": [\"gpt-3.5-turbo-16k\"],\n", 32 | " },\n", 33 | ")\n", 34 | "\n", 35 | "def get_apikey(script_dir=script_dir):\n", 36 | " \"\"\"\n", 37 | " Reads API key from a configuration file.\n", 38 | "\n", 39 | " This function opens a configuration file named \"apikeys.yml\", reads the API key for OpenAI\n", 40 | "\n", 41 | " Returns:\n", 42 | " api_key (str): The OpenAI API key.\n", 43 | " \"\"\"\n", 44 | " # Update the script_dir path to point to the correct location in your Google Drive\n", 45 | " script_dir = script_dir\n", 46 | " file_path = os.path.join(script_dir, \"apikeys.yml\")\n", 47 | "\n", 48 | " with open(file_path, 'r') as yamlfile:\n", 49 | " loaded_yamlfile = yaml.safe_load(yamlfile)\n", 50 | " API_KEY = loaded_yamlfile['openai']['api_key']\n", 51 | "\n", 52 | " return API_KEY\n", 53 | "\n", 54 | "# Call the function to get the API key\n", 55 | "openai.api_key = get_apikey()" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 2, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "# Tool 1: Does a query based search for Wikipages\n", 65 | "from typing import Any, List\n", 66 | "import wikipedia\n", 67 | "from llama_index import download_loader, VectorStoreIndex, ServiceContext\n", 68 | "from llama_index.node_parser import SimpleNodeParser\n", 69 | "from llama_index.text_splitter import get_default_text_splitter\n", 70 | "import openai\n", 71 | "from pydantic import BaseModel\n", 72 | "from llama_index.program import OpenAIPydanticProgram\n", 73 | "from utils import get_apikey\n", 74 | "from typing import Callable, Dict, Optional, Union, List, Tuple, Any\n", 75 | "from llama_hub.wikipedia.base import WikipediaReader\n", 76 | "from llama_index import StorageContext\n", 77 | "from llama_index import load_index_from_storage\n", 78 | "import json\n", 79 | "from llama_index.llms.openai import OpenAI\n", 80 | "\n", 81 | "def load_index(filepath: str):\n", 82 | " # rebuild storage context\n", 83 | " storage_context = StorageContext.from_defaults(persist_dir=index_path)\n", 84 | " # load index\n", 85 | " return load_index_from_storage(storage_context)\n", 86 | "\n", 87 | "def read_json_file(file_path: str) -> dict:\n", 88 | " with open(file_path, 'r') as f:\n", 89 | " data = json.load(f)\n", 90 | " return data\n", 91 | "\n", 92 | "def create_wikidocs(wikipage_requests):\n", 93 | " print(f\"Preparing to Download:{wikipage_requests}\")\n", 94 | " WikipediaReader = download_loader(\"WikipediaReader\")\n", 95 | " loader = WikipediaReader()\n", 96 | " documents = loader.load_data(pages=wikipage_requests)\n", 97 | " print(\"Finished downloading pages\")\n", 98 | " return documents\n", 99 | "\n", 100 | "def index_wikipedia_pages(wikipage_requests):\n", 101 | " print(f\"Preparing to index Wikipages: {wikipage_requests}\")\n", 102 | " documents = create_wikidocs(wikipage_requests)\n", 103 | " text_splits = get_default_text_splitter(chunk_size=150, chunk_overlap=45)\n", 104 | " parser = SimpleNodeParser.from_defaults(text_splitter=text_splits)\n", 105 | " service_context = ServiceContext.from_defaults(node_parser=parser)\n", 106 | " index = VectorStoreIndex.from_documents(documents, service_context=service_context, show_progress=False)\n", 107 | " index.storage_context.persist(index_path)\n", 108 | " print(f\"{wikipage_requests} have been indexed.\")\n", 109 | " return index\n", 110 | "\n", 111 | "def search_and_index_wikipedia(\n", 112 | " query: str, lang: str = \"en\", results_limit: int = 5, **load_kwargs: Any\n", 113 | " ) -> List[List]:\n", 114 | " wikipedia.set_lang(lang)\n", 115 | " wikipage_requests = wikipedia.search(query, results=results_limit)\n", 116 | " index_wikipedia_pages(wikipage_requests)\n", 117 | " return print(f\"Finished indexing: {wikipage_requests}\")\n", 118 | "\n", 119 | "def query_vector_db(\n", 120 | " search_string: str,\n", 121 | " file_path = index_path,\n", 122 | " n_results: int = 10\n", 123 | ") -> None: \n", 124 | " index = load_index(filepath=index_path)\n", 125 | " query_engine = index.as_query_engine(\n", 126 | " response_mode=\"compact\", verbose=True, similarity_top_k=n_results\n", 127 | " )\n", 128 | " nodes = query_engine.query(search_string).source_nodes\n", 129 | " retrieved_context = {\n", 130 | " # \"ids\": [],\n", 131 | " \"text\": []\n", 132 | " }\n", 133 | " for node in nodes:\n", 134 | " # retrieved_context[\"ids\"].append(node.node.id_)\n", 135 | " retrieved_context[\"text\"].append(node.node.text)\n", 136 | " \n", 137 | " file_path = index_path + \"retrieved_context.json\"\n", 138 | " with open(file_path, 'w') as f:\n", 139 | " json.dump(retrieved_context, f)\n", 140 | " \n", 141 | " return retrieved_context\n", 142 | "\n", 143 | "def generate_response(task:str):\n", 144 | " openai.api_key = get_apikey()\n", 145 | " context = read_json_file(index_path + \"retrieved_context.json\")\n", 146 | " response = openai.ChatCompletion.create(\n", 147 | " model=\"gpt-3.5-turbo-16k\", \n", 148 | " messages=[\n", 149 | " {\"role\": \"system\", \"content\": \"You are a helpful assistant, you think step by step to help you respond\"},\n", 150 | " {\"role\": \"user\", \"content\": task},\n", 151 | " {\"role\": \"assistant\", \"content\": f\"Use the information `{context}` to help you respond to the `{task}`\"}\n", 152 | " ]\n", 153 | " )\n", 154 | " return response['choices'][0]['message']['content']" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 3, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "llm_config = {\n", 164 | " \"functions\": [\n", 165 | " {\n", 166 | " \"name\": \"search_and_index_wikipedia\",\n", 167 | " \"description\": \"Use this to search for and index relevant wikipedia pages.\",\n", 168 | " \"parameters\": {\n", 169 | " \"type\": \"object\",\n", 170 | " \"properties\": {\n", 171 | " \"query\": {\n", 172 | " \"type\": \"string\",\n", 173 | " \"description\": \"A search string for relevant Wikipedia pages.\",\n", 174 | " }\n", 175 | " },\n", 176 | " \"required\": [\"query\"],\n", 177 | " },\n", 178 | " },\n", 179 | " \n", 180 | " {\n", 181 | " \"name\": \"query_vector_db\",\n", 182 | " \"description\": \"Useful for retrieving relevant context from the Wikipedia index.\",\n", 183 | " \"parameters\": {\n", 184 | " \"type\": \"object\",\n", 185 | " \"properties\": {\n", 186 | " \"search_string\": {\n", 187 | " \"type\": \"string\",\n", 188 | " \"description\": \"A query to find relevant context from the Wikipedia index.\",\n", 189 | " }\n", 190 | " },\n", 191 | " \"required\": [\"search_string\"],\n", 192 | " },\n", 193 | " },\n", 194 | "\n", 195 | " {\n", 196 | " \"name\": \"generate_response\",\n", 197 | " \"description\": \"Useful to generate a response based on additional context provided by wikipedia search.\",\n", 198 | " \"parameters\": {\n", 199 | " \"type\": \"object\",\n", 200 | " \"properties\": {\n", 201 | " \"task\": {\n", 202 | " \"type\": \"string\",\n", 203 | " \"task\": \"Your understanding of the task.\",\n", 204 | " }\n", 205 | " },\n", 206 | " \"required\": [\"task\"],\n", 207 | " },\n", 208 | " }, \n", 209 | " ],\n", 210 | " \"config_list\": config_list,\n", 211 | " \"request_timeout\": 120,\n", 212 | " # \"seed\":43\n", 213 | "}" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 5, 219 | "metadata": {}, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 226 | "\n", 227 | "Which was the first bank to default in the 2023 US banking Crsis?\n", 228 | "\n", 229 | "--------------------------------------------------------------------------------\n", 230 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 231 | "\n", 232 | "\u001b[32m***** Suggested function Call: search_and_index_wikipedia *****\u001b[0m\n", 233 | "Arguments: \n", 234 | "{\n", 235 | " \"query\": \"2023 US banking crisis\"\n", 236 | "}\n", 237 | "\u001b[32m***************************************************************\u001b[0m\n", 238 | "\n", 239 | "--------------------------------------------------------------------------------\n", 240 | "\u001b[35m\n", 241 | ">>>>>>>> EXECUTING FUNCTION search_and_index_wikipedia...\u001b[0m\n", 242 | "Preparing to index Wikipages: ['2023 United States banking crisis', 'List of banking crises', 'Venezuelan banking crisis of 1994', 'Ghana banking crisis', 'Bank run']\n", 243 | "Preparing to Download:['2023 United States banking crisis', 'List of banking crises', 'Venezuelan banking crisis of 1994', 'Ghana banking crisis', 'Bank run']\n", 244 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 245 | "\n", 246 | "\u001b[32m***** Response from calling function \"search_and_index_wikipedia\" *****\u001b[0m\n", 247 | "Error: Page id \"back run\" does not match any pages. Try another id!\n", 248 | "\u001b[32m***********************************************************************\u001b[0m\n", 249 | "\n", 250 | "--------------------------------------------------------------------------------\n", 251 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 252 | "\n", 253 | "\u001b[32m***** Suggested function Call: search_and_index_wikipedia *****\u001b[0m\n", 254 | "Arguments: \n", 255 | "{\n", 256 | " \"query\": \"2023 US banking crisis default bank\"\n", 257 | "}\n", 258 | "\u001b[32m***************************************************************\u001b[0m\n", 259 | "\n", 260 | "--------------------------------------------------------------------------------\n", 261 | "\u001b[35m\n", 262 | ">>>>>>>> EXECUTING FUNCTION search_and_index_wikipedia...\u001b[0m\n", 263 | "Preparing to index Wikipages: ['2023 United States banking crisis', 'Bank run', '2020–2023 Chinese property sector crisis', 'Sri Lankan economic crisis (2019–present)', 'Ghana banking crisis']\n", 264 | "Preparing to Download:['2023 United States banking crisis', 'Bank run', '2020–2023 Chinese property sector crisis', 'Sri Lankan economic crisis (2019–present)', 'Ghana banking crisis']\n", 265 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 266 | "\n", 267 | "\u001b[32m***** Response from calling function \"search_and_index_wikipedia\" *****\u001b[0m\n", 268 | "Error: Page id \"back run\" does not match any pages. Try another id!\n", 269 | "\u001b[32m***********************************************************************\u001b[0m\n", 270 | "\n", 271 | "--------------------------------------------------------------------------------\n", 272 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 273 | "\n", 274 | "\u001b[32m***** Suggested function Call: search_and_index_wikipedia *****\u001b[0m\n", 275 | "Arguments: \n", 276 | "{\n", 277 | " \"query\": \"first bank to default in 2023 US banking crisis\"\n", 278 | "}\n", 279 | "\u001b[32m***************************************************************\u001b[0m\n", 280 | "\n", 281 | "--------------------------------------------------------------------------------\n", 282 | "\u001b[35m\n", 283 | ">>>>>>>> EXECUTING FUNCTION search_and_index_wikipedia...\u001b[0m\n", 284 | "Preparing to index Wikipages: ['2023 United States banking crisis', 'Bank run', '2020–2023 Chinese property sector crisis', 'Currency crisis', 'Sri Lankan economic crisis (2019–present)']\n", 285 | "Preparing to Download:['2023 United States banking crisis', 'Bank run', '2020–2023 Chinese property sector crisis', 'Currency crisis', 'Sri Lankan economic crisis (2019–present)']\n", 286 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 287 | "\n", 288 | "\u001b[32m***** Response from calling function \"search_and_index_wikipedia\" *****\u001b[0m\n", 289 | "Error: Page id \"back run\" does not match any pages. Try another id!\n", 290 | "\u001b[32m***********************************************************************\u001b[0m\n", 291 | "\n", 292 | "--------------------------------------------------------------------------------\n", 293 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 294 | "\n", 295 | "I'm sorry, but I couldn't find any information about the first bank to default in the 2023 US banking crisis.\n", 296 | "\n", 297 | "--------------------------------------------------------------------------------\n", 298 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 299 | "\n", 300 | "\n", 301 | "\n", 302 | "--------------------------------------------------------------------------------\n", 303 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 304 | "\n", 305 | "\u001b[32m***** Suggested function Call: search_and_index_wikipedia *****\u001b[0m\n", 306 | "Arguments: \n", 307 | "{\n", 308 | " \"query\": \"2023 US banking crisis\"\n", 309 | "}\n", 310 | "\u001b[32m***************************************************************\u001b[0m\n", 311 | "\n", 312 | "--------------------------------------------------------------------------------\n", 313 | "\u001b[35m\n", 314 | ">>>>>>>> EXECUTING FUNCTION search_and_index_wikipedia...\u001b[0m\n", 315 | "Preparing to index Wikipages: ['2023 United States banking crisis', 'List of banking crises', 'Venezuelan banking crisis of 1994', 'Ghana banking crisis', 'Bank run']\n", 316 | "Preparing to Download:['2023 United States banking crisis', 'List of banking crises', 'Venezuelan banking crisis of 1994', 'Ghana banking crisis', 'Bank run']\n", 317 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 318 | "\n", 319 | "\u001b[32m***** Response from calling function \"search_and_index_wikipedia\" *****\u001b[0m\n", 320 | "Error: Page id \"back run\" does not match any pages. Try another id!\n", 321 | "\u001b[32m***********************************************************************\u001b[0m\n", 322 | "\n", 323 | "--------------------------------------------------------------------------------\n", 324 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 325 | "\n", 326 | "\u001b[32m***** Suggested function Call: search_and_index_wikipedia *****\u001b[0m\n", 327 | "Arguments: \n", 328 | "{\n", 329 | " \"query\": \"2023 US banking crisis\"\n", 330 | "}\n", 331 | "\u001b[32m***************************************************************\u001b[0m\n", 332 | "\n", 333 | "--------------------------------------------------------------------------------\n" 334 | ] 335 | } 336 | ], 337 | "source": [ 338 | "import autogen \n", 339 | "user_proxy = autogen.UserProxyAgent(\n", 340 | " name=\"user_proxy\",\n", 341 | " is_termination_msg=lambda x: x.get(\"content\", \"\") and x.get(\"content\", \"\").rstrip().endswith(\"TERMINATE\"),\n", 342 | " human_input_mode=\"NEVER\",\n", 343 | " max_consecutive_auto_reply=5,\n", 344 | " system_message= '''Your job is to use agents to complete the task.\n", 345 | " You will give a final response once you are satisfied with the answer''',\n", 346 | " # llm_config=llm_config,\n", 347 | " \n", 348 | ")\n", 349 | "\n", 350 | "assistant = autogen.AssistantAgent(\n", 351 | " name=\"assistant\",\n", 352 | " system_message='''Your job is to come up with search queries to find relevant Wikipedia pages''',\n", 353 | " llm_config=llm_config,\n", 354 | " human_input_mode=\"NEVER\"\n", 355 | ")\n", 356 | "\n", 357 | "# index_creator_agent = autogen.AssistantAgent(\n", 358 | "# name=\"index_creator_agent\",\n", 359 | "# system_message='''Your job is to find and index relevant Wikipedia pages to help you respond to the task.\n", 360 | "# You should use the search_and_index_wikipedia tool for this.\n", 361 | "# Reply `TERMINATE` in the end when everything is done.''',\n", 362 | "# llm_config=llm_config,\n", 363 | "# human_input_mode=\"NEVER\"\n", 364 | "# )\n", 365 | "\n", 366 | "# retrieve_agent = autogen.AssistantAgent(\n", 367 | "# name=\"retrieve_agent\",\n", 368 | "# system_message='''You are an information retrieval agent. Your job is to retrieve relevant information from the index \n", 369 | "# created by wikisearch_agent using the query_vector_db tool.\n", 370 | "# Reply `TERMINATE` in the end when everything is done.''',\n", 371 | "# llm_config=llm_config,\n", 372 | "# human_input_mode=\"NEVER\"\n", 373 | "\n", 374 | "# )\n", 375 | "\n", 376 | "# response_agent = autogen.AssistantAgent(\n", 377 | "# name=\"response_agent\",\n", 378 | "# system_message='''Your job is to generate a final response to the task based using the generate_response tool.\n", 379 | "# Reply `TERMINATE` in the end when everything is done.''',\n", 380 | "# llm_config=llm_config,\n", 381 | "# human_input_mode=\"NEVER\"\n", 382 | "\n", 383 | "# )\n", 384 | "\n", 385 | "user_proxy.register_function(\n", 386 | " function_map={\n", 387 | " \"search_and_index_wikipedia\": search_and_index_wikipedia,\n", 388 | " \"query_vector_db\":query_vector_db,\n", 389 | " \"generate_response\":generate_response\n", 390 | " }\n", 391 | ")\n", 392 | "\n", 393 | "\n", 394 | "user_proxy.initiate_chat(\n", 395 | " assistant,\n", 396 | " message=\"\"\"Which was the first bank to default in the 2023 US banking Crsis?\"\"\",\n", 397 | ")\n", 398 | "\n", 399 | "# groupchat = autogen.GroupChat(agents=[user_proxy, index_creator_agent, retrieve_agent, response_agent], messages=[], max_round=20)\n", 400 | "# manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)\n", 401 | "# user_proxy.initiate_chat(manager, message=\"What is the population of Paris?\")\n" 402 | ] 403 | }, 404 | { 405 | "cell_type": "code", 406 | "execution_count": null, 407 | "metadata": {}, 408 | "outputs": [], 409 | "source": [] 410 | } 411 | ], 412 | "metadata": { 413 | "kernelspec": { 414 | "display_name": "autogen_env", 415 | "language": "python", 416 | "name": "python3" 417 | }, 418 | "language_info": { 419 | "codemirror_mode": { 420 | "name": "ipython", 421 | "version": 3 422 | }, 423 | "file_extension": ".py", 424 | "mimetype": "text/x-python", 425 | "name": "python", 426 | "nbconvert_exporter": "python", 427 | "pygments_lexer": "ipython3", 428 | "version": "3.9.18" 429 | } 430 | }, 431 | "nbformat": 4, 432 | "nbformat_minor": 2 433 | } 434 | -------------------------------------------------------------------------------- /archive/autogen_tutorial_v3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Auto Gen Tutorial\n", 8 | "Note book written by John Adeojo\n", 9 | "Founder, and Chief Data Scientist at [Data-centric Solutions](https://www.data-centric-solutions.com/)\n" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 21, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "import autogen\n", 19 | "import yaml\n", 20 | "import openai \n", 21 | "import os\n", 22 | "\n", 23 | "script_dir = \"C:/Users/johna/OneDrive/Documents/api_keys/\"\n", 24 | "index_path = \"G:/My Drive/Data-Centric Solutions/07. Blog Posts/AutoGen/autogen_tutorial/indexes/\"\n", 25 | "configurations_path = \"G:/My Drive/Data-Centric Solutions/07. Blog Posts/AutoGen/autogen_tutorial/\"\n", 26 | "\n", 27 | "config_list = autogen.config_list_from_json(\n", 28 | " env_or_file=\"configurations.json\",\n", 29 | " file_location=configurations_path,\n", 30 | " filter_dict={\n", 31 | " \"model\": [\"gpt-4\", \"gpt-3.5-turbo-16k\"],\n", 32 | " },\n", 33 | ")\n", 34 | "\n", 35 | "def get_apikey(script_dir=script_dir):\n", 36 | "\n", 37 | " script_dir = script_dir\n", 38 | " file_path = os.path.join(script_dir, \"apikeys.yml\")\n", 39 | "\n", 40 | " with open(file_path, 'r') as yamlfile:\n", 41 | " loaded_yamlfile = yaml.safe_load(yamlfile)\n", 42 | " API_KEY = loaded_yamlfile['openai']['api_key']\n", 43 | "\n", 44 | " return API_KEY\n", 45 | "\n", 46 | "openai.api_key = get_apikey()" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 22, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "# Tool 1: Does a query based search for Wikipages\n", 56 | "from typing import Any, List\n", 57 | "import wikipedia\n", 58 | "from llama_index import download_loader, VectorStoreIndex, ServiceContext\n", 59 | "from llama_index.node_parser import SimpleNodeParser\n", 60 | "from llama_index.text_splitter import get_default_text_splitter\n", 61 | "import openai\n", 62 | "from pydantic import BaseModel\n", 63 | "from llama_index.program import OpenAIPydanticProgram\n", 64 | "from utils import get_apikey\n", 65 | "from typing import Callable, Dict, Optional, Union, List, Tuple, Any\n", 66 | "from llama_hub.wikipedia.base import WikipediaReader\n", 67 | "from llama_index import StorageContext\n", 68 | "from llama_index import load_index_from_storage\n", 69 | "import json\n", 70 | "from llama_index.llms.openai import OpenAI\n", 71 | "\n", 72 | "def load_index(filepath: str):\n", 73 | " # rebuild storage context\n", 74 | " storage_context = StorageContext.from_defaults(persist_dir=index_path)\n", 75 | " # load index\n", 76 | " return load_index_from_storage(storage_context)\n", 77 | "\n", 78 | "def read_json_file(file_path: str) -> dict:\n", 79 | " with open(file_path, 'r') as f:\n", 80 | " data = json.load(f)\n", 81 | " return data\n", 82 | "\n", 83 | "def create_wikidocs(wikipage_requests):\n", 84 | " print(f\"Preparing to Download:{wikipage_requests}\")\n", 85 | " WikipediaReader = download_loader(\"WikipediaReader\")\n", 86 | " loader = WikipediaReader()\n", 87 | " documents = loader.load_data(pages=wikipage_requests)\n", 88 | " print(\"Finished downloading pages\")\n", 89 | " return documents\n", 90 | "\n", 91 | "def index_wikipedia_pages(wikipage_requests):\n", 92 | " print(f\"Preparing to index Wikipages: {wikipage_requests}\")\n", 93 | " documents = create_wikidocs(wikipage_requests)\n", 94 | " text_splits = get_default_text_splitter(chunk_size=150, chunk_overlap=45)\n", 95 | " parser = SimpleNodeParser.from_defaults(text_splitter=text_splits)\n", 96 | " service_context = ServiceContext.from_defaults(node_parser=parser)\n", 97 | " index = VectorStoreIndex.from_documents(documents, service_context=service_context, show_progress=False)\n", 98 | " index.storage_context.persist(index_path)\n", 99 | " print(f\"{wikipage_requests} have been indexed.\")\n", 100 | " return index\n", 101 | "\n", 102 | "def search_and_index_wikipedia(\n", 103 | " query: str, lang: str = \"en\", results_limit: int = 3, **load_kwargs: Any\n", 104 | " ):\n", 105 | " wikipedia.set_lang(lang)\n", 106 | " wikipage_requests = wikipedia.search(query, results=results_limit)\n", 107 | " print (f\"I have found on Wikipedia: {wikipage_requests}\")\n", 108 | " index_wikipedia_pages(wikipage_requests)\n", 109 | " return f\"Finished indexing: {type(wikipage_requests)}\"\n", 110 | "\n", 111 | "\n", 112 | "def query_wiki_index(search_string: str, file_path = index_path,\n", 113 | " n_results: int = 20\n", 114 | "): \n", 115 | " index = load_index(filepath=index_path)\n", 116 | " query_engine = index.as_query_engine(\n", 117 | " response_mode=\"compact\", verbose=True, similarity_top_k=n_results\n", 118 | " )\n", 119 | " nodes = query_engine.query(search_string).source_nodes\n", 120 | " retrieved_context = {\n", 121 | " # \"ids\": [],\n", 122 | " \"text\": []\n", 123 | " }\n", 124 | " for node in nodes:\n", 125 | " # retrieved_context[\"ids\"].append(node.node.id_)\n", 126 | " retrieved_context[\"text\"].append(node.node.text)\n", 127 | " \n", 128 | " file_path = index_path + \"retrieved_context.json\"\n", 129 | " with open(file_path, 'w') as f:\n", 130 | " json.dump(retrieved_context, f)\n", 131 | " \n", 132 | " return retrieved_context" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 23, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "llm_config = {\n", 142 | " \"functions\": [\n", 143 | " {\n", 144 | " \"name\": \"search_and_index_wikipedia\",\n", 145 | " \"description\": \"Indexes Wikipedia pages based on a specified query to build a knowledge base for future reference. Use before query_wiki_index.\",\n", 146 | " \"parameters\": {\n", 147 | " \"type\": \"object\",\n", 148 | " \"properties\": {\n", 149 | " \"query\": {\n", 150 | " \"type\": \"string\",\n", 151 | " \"description\": \"The search query for identifying relevant Wikipedia pages to index.\",\n", 152 | " }\n", 153 | " },\n", 154 | " \"required\": [\"query\"],\n", 155 | " },\n", 156 | " },\n", 157 | " {\n", 158 | " \"name\": \"query_wiki_index\",\n", 159 | " \"description\": \"Queries the indexed Wikipedia knowledge base to retrieve pertinent information\",\n", 160 | " \"parameters\": {\n", 161 | " \"type\": \"object\",\n", 162 | " \"properties\": {\n", 163 | " \"search_string\": {\n", 164 | " \"type\": \"string\",\n", 165 | " \"description\": \"The query to search the indexed Wikipedia knowledge base for relevant information.\",\n", 166 | " }\n", 167 | " },\n", 168 | " \"required\": [\"search_string\"],\n", 169 | " },\n", 170 | " },\n", 171 | " ],\n", 172 | " \"config_list\": config_list,\n", 173 | " \"request_timeout\": 120,\n", 174 | " \"seed\":43\n", 175 | "}" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 24, 181 | "metadata": {}, 182 | "outputs": [ 183 | { 184 | "name": "stdout", 185 | "output_type": "stream", 186 | "text": [ 187 | "\u001b[33muser_proxy\u001b[0m (to chat_manager):\n", 188 | "\n", 189 | "When did SVB default?\n", 190 | "\n", 191 | "--------------------------------------------------------------------------------\n", 192 | "\u001b[33mmoderator\u001b[0m (to chat_manager):\n", 193 | "\n", 194 | "In order to answer this question accurately, the assistant would need more information about SVB. SVB could stand for Silicon Valley Bank, Swedish Volleyball, or any number of entities. Once we know which SVB is referred to, we can search for relevant facts in a trusted data source such as Wikipedia. Unfortunately, current knowledge does not have data on SVB default. Would you provide more details?\n", 195 | "\n", 196 | "--------------------------------------------------------------------------------\n", 197 | "\u001b[33muser_proxy\u001b[0m (to chat_manager):\n", 198 | "\n", 199 | "\n", 200 | "\n", 201 | "--------------------------------------------------------------------------------\n", 202 | "\u001b[33mmoderator\u001b[0m (to chat_manager):\n", 203 | "\n", 204 | "Apologies for the confusion earlier. Let's move ahead and find the exact detail you are looking for. To find specific events like a default of SVB (assuming it refers to Silicon Valley Bank), we may need to utilize the 'search_and_index_wikipedia' function first with a relevant query such as 'Silicon Valley Bank default'. This would index Wikipedia articles related to the event, if any exist.\n", 205 | "\n", 206 | "After this, we can use the 'query_wiki_index' function with a specific search string such as 'Silicon Valley Bank default date' to extract pertinent information.\n", 207 | "\n", 208 | "--------------------------------------------------------------------------------\n", 209 | "\u001b[33massistant\u001b[0m (to chat_manager):\n", 210 | "\n", 211 | "\u001b[32m***** Suggested function Call: search_and_index_wikipedia *****\u001b[0m\n", 212 | "Arguments: \n", 213 | "{\n", 214 | " \"query\": \"Silicon Valley Bank default\"\n", 215 | "}\n", 216 | "\u001b[32m***************************************************************\u001b[0m\n", 217 | "\n", 218 | "--------------------------------------------------------------------------------\n", 219 | "\u001b[35m\n", 220 | ">>>>>>>> EXECUTING FUNCTION search_and_index_wikipedia...\u001b[0m\n", 221 | "I have found on Wikipedia: ['2023 United States banking crisis', 'Brex', 'List of bank runs']\n", 222 | "Preparing to index Wikipages: ['2023 United States banking crisis', 'Brex', 'List of bank runs']\n", 223 | "Preparing to Download:['2023 United States banking crisis', 'Brex', 'List of bank runs']\n", 224 | "Finished downloading pages\n", 225 | "['2023 United States banking crisis', 'Brex', 'List of bank runs'] have been indexed.\n", 226 | "\u001b[33muser_proxy\u001b[0m (to chat_manager):\n", 227 | "\n", 228 | "\u001b[32m***** Response from calling function \"search_and_index_wikipedia\" *****\u001b[0m\n", 229 | "Finished indexing: \n", 230 | "\u001b[32m***********************************************************************\u001b[0m\n", 231 | "\n", 232 | "--------------------------------------------------------------------------------\n", 233 | "\u001b[33mmoderator\u001b[0m (to chat_manager):\n", 234 | "\n", 235 | "\u001b[32m***** Suggested function Call: query_wiki_index *****\u001b[0m\n", 236 | "Arguments: \n", 237 | "{\n", 238 | " \"search_string\": \"Silicon Valley Bank default date\"\n", 239 | "}\n", 240 | "\u001b[32m*****************************************************\u001b[0m\n", 241 | "\n", 242 | "--------------------------------------------------------------------------------\n", 243 | "\u001b[35m\n", 244 | ">>>>>>>> EXECUTING FUNCTION query_wiki_index...\u001b[0m\n", 245 | "\u001b[33muser_proxy\u001b[0m (to chat_manager):\n", 246 | "\n", 247 | "\u001b[32m***** Response from calling function \"query_wiki_index\" *****\u001b[0m\n", 248 | "{'text': [\"Over the course of five days in March 2023, three small- to mid-size U.S. banks failed, triggering a sharp decline in global bank stock prices and swift response by regulators to prevent potential global contagion. Silicon Valley Bank (SVB) failed when a bank run was triggered after it sold its Treasury bond portfolio at a large loss, causing depositor concerns about the bank's liquidity. The bonds had lost significant value as market interest rates rose after the bank had shifted its portfolio to longer-maturity bonds. The bank's clientele was primarily technology companies and wealthy individuals holding large deposits, but balances exceeding $250,000 were not insured by the Federal Deposit Insurance Corporation (FDIC).\", '== Collapse of Silicon Valley Bank ==\\n\\n\\n=== Background ===\\nSilicon Valley Bank (SVB) was a commercial bank founded in 1983 and headquartered in Santa Clara, California. Until its collapse, SVB was the 16th largest bank in the United States and was heavily skewed toward serving companies and individuals from the technology industry. Nearly half of U.S. venture capital-backed healthcare and technology companies were financed by SVB. Companies such as Airbnb, Cisco, Fitbit, Pinterest, and Block, Inc. have been clients of the bank.', 'The announcement, coupled with warnings from prominent Silicon Valley investors, caused a bank run as customers withdrew funds totaling US$42 billion by the following day.On March 10, 2023, as a result of the bank run, the California Department of Financial Protection and Innovation (DFPI) seized SVB and placed it under the receivership of the FDIC. The FDIC established a deposit insurance national bank, the Deposit Insurance National Bank of Santa Clara, to service insured deposits and announced that it would start paying dividends for uninsured deposits the following week; the dividends were funded by proceeds from the sale of SVB assets.', \"According to Signature Bank board member Barney Frank, Signature Bank was hit with a multi-billion dollar bank run on Friday, March 10, with depositors expressing concern about cryptocurrency-related risks affecting the bank. Investor confidence in the bank was also badly shaken, and the bank's stock declined by 23% on that Friday—the day on which Silicon Valley bank collapsed—marking the then-largest single-day decline of the Signature Bank's value in its 22-year history.On March 12, 2023, two days after the collapse of Silicon Valley Bank, Signature Bank was closed by regulators from the New York State Department of Financial Services in what is the third-biggest banking collapse in U.S. history.\", 'Silvergate faced tight financial constraints in the coming months, selling assets at a loss and borrowing $3.6 billion from the Federal Home Loan Bank of San Francisco to maintain its liquidity. Silvergate wrote in a regulatory filing on March 1 that the bank risked losing its status as a well-capitalized bank and that the bank faced risks relating to its ability to continue operating.Facing continued losses from sales of securities at mark-to-market price, Silvergate released a public notice on March 8, 2023, saying that it would undergo voluntary liquidation and would return all deposited funds to their respective owners.\\n\\n\\n== Collapse of Silicon Valley Bank ==', \"The FDIC rejected this offer and plans to hold a second auction to attract bids from major banks, now that the bank's systemic risk designation allows the FDIC to insure all deposits. The bank was later reopened as a newly organized bridge bank, Silicon Valley Bridge Bank, N. A.On March 26, 2023, the FDIC announced that First Citizens BancShares would acquire the commercial banking business of SVB. As part of the deal, First Citizens brought around $56.5 billion in deposits and $72 billion of SVB's loans discounted by $16.5 billion, while around $90 billion of SVB's securities continue to remain in receivership.\", 'venture capital-backed healthcare and technology companies were financed by SVB. Companies such as Airbnb, Cisco, Fitbit, Pinterest, and Block, Inc. have been clients of the bank. In addition to financing venture-backed companies, SVB was well known as a source of private banking, personal credit lines, and mortgages to tech entrepreneurs. According to the FDIC, it had $209 billion in assets at the end of 2022.Silicon Valley Bank recorded an increase of its deposit holdings during the COVID-19 pandemic, when the tech sector experienced a period of growth. In 2021, it purchased long-term Treasury bonds to capitalize on the increased deposits.', 'In 2021, it purchased long-term Treasury bonds to capitalize on the increased deposits. However, the current market value of these bonds decreased as the Federal Reserve raised interest rates to curb the 2021–2023 inflation surge. Higher interest rates also raised borrowing costs throughout the economy and some Silicon Valley Bank clients started pulling money out to meet their liquidity needs.\\n\\n\\n=== Events ===\\nTo raise cash to pay withdrawals by its depositors, SVB announced on March 8 that it had sold over US$21 billion worth of securities, borrowed US$15 billion, and would hold an emergency sale of some of its treasury stock to raise US$2.25 billion.', 'On 27 February 2022, the sanctions against Russia during the 2022 Russian invasion of Ukraine and the removal of Russian banks from the SWIFT system led to a banking panic across multiple Russian banks.\\nOn 9 March 2023, a US$42 billion bank run on Silicon Valley Bank led to the closure of the bank by California and United States regulators, with FDIC-insured deposits assumed by the Deposit Insurance National Bank of Santa Clara. This is currently the biggest bank run in history.\\n\\n\\n== See also ==\\nList of banking crises\\nList of economic crises\\nBank failure (includes list)\\n\\n\\n== References ==', \"==== U.S. investigations ====\\nThe collapse of Silicon Valley Bank itself has also spurred federal investigations from the U.S. Securities and Exchange Commission as well as the United States Department of Justice. Within the scope of both probes is the sales of stock made by senior officers of Silicon Valley Bank shortly before the bank failed, while the SEC's investigation also includes a review of past financial- and other risk-related disclosures made by Silicon Valley Bank to evaluate their accuracy and completeness.Internal investigations at the FDIC and Federal Reserve noted that deregulation, not subjecting medium-sized banks to high scrutiny, reduced enforcement of remaining regulations, and government staffing shortages weakened oversight and allowed mismanagement of banks to cause their collapse.\", 'Two days later, upon announcement of an attempt to raise capital, a bank run occurred at Silicon Valley Bank, causing it to collapse and be seized by regulators that day. Signature Bank, a bank that frequently did business with cryptocurrency firms, was closed by regulators two days later on March 12, with regulators citing systemic risks.', '=== Economic impact ===\\nAs depositors began to move money en masse from smaller banks to larger banks, on Monday, March 13, shares of regional banks fell.\\nFollowing SVB and Signature\\'s collapses, Western Alliance Bancorporation share price fell 47% and PacWest Bancorp was down 21% recovering after their trading was halted. Moody\\'s downgraded its outlook on the U.S. banking system to negative, citing what it described as \"rapid deterioration\" of the sector\\'s financial footing.', \"Some 89 percent of the bank's US$172 billion in deposit liabilities exceeded the maximum insured by the FDIC. Two days after the failure, the FDIC received exceptional authority from the Treasury and announced jointly with other agencies that all depositors would have full access to their funds the next morning. An initial auction of Silicon Valley Bank assets on the same day attracted a single bid, after PNC Financial Services and RBC Bank backed away from making offers. The FDIC rejected this offer and plans to hold a second auction to attract bids from major banks, now that the bank's systemic risk designation allows the FDIC to insure all deposits.\", 'Signature Bank, a bank that frequently did business with cryptocurrency firms, was closed by regulators two days later on March 12, with regulators citing systemic risks. The collapses of First Republic Bank, Silicon Valley Bank and Signature Bank were the second-, third- and fourth-largest bank failures in the history of the United States, respectively, smaller only than the collapse of Washington Mutual during the 2007–2008 financial crisis.In 2019, the Federal Reserve\\'s \"Tailoring rules\" changed, increasing minimum asset threshold from $50 billion to $100 billion and reduced the number of required stress testing scenarios, allowing banks with under $100 billion to have reduced liquidity standards.', \"banking crisis. The Federal Reserve discount window liquidity facility had experienced approximately $150 billion in borrowing from various banks by March 16.Soon after the bank run at SVB, depositors quickly began withdrawing cash from San Francisco-based First Republic Bank (FRB), which focused on private banking to wealthy clientele. Like SVB, FRB had substantial uninsured deposits exceeding $250,000; such deposits constituted 68% of the bank's total at year-end 2022, declining to 27% by the end of March, as $100 billion in uninsured deposits were withdrawn.\", 'federal bank regulators announced in a joint communiqué that extraordinary measures would be taken to ensure that all deposits at Silicon Valley Bank and Signature Bank would be honored. The Federal Reserve established a Bank Term Funding Program (BTFP) to offer loans of up to one year to eligible depository institutions pledging qualifying assets as collateral.To prevent the situation from affecting more banks, global industry regulators, including the Federal Reserve, the Bank of Canada, Bank of England, Bank of Japan, European Central Bank, and Swiss National Bank intervened to provide extraordinary liquidity.By March 16, large interbank flows of funds were occurring to shore up bank balance sheets and some analysts were talking of a possibly broader U.S. banking crisis.', \"Japan's central bank held a crisis meeting in mid-March while the Topix banks index fell 17%. The fall was led by fears over the SVB collapse and the risks in Japan's regional banking sector, partly because of exposure to US interest rate hikes.The cost to insure against default on Deutsche Bank debt rose substantially on Friday, 24 March, with the 5-year CDS for the bank's debt rising 70%. The ECB and other European central banks raised interest rates the same day. The European STOXX 600 index fell around 4% with shares in Deutsche Bank down more than 14% at one point, closing the day at a loss of around 8%.\", \"The bank's clientele was primarily technology companies and wealthy individuals holding large deposits, but balances exceeding $250,000 were not insured by the Federal Deposit Insurance Corporation (FDIC). Silvergate Bank and Signature Bank, both with significant exposure to cryptocurrency, failed in the midst of turbulence in that market.\\nIn response to the bank failures, the three major U.S. federal bank regulators announced in a joint communiqué that extraordinary measures would be taken to ensure that all deposits at Silicon Valley Bank and Signature Bank would be honored.\", 'Also, several banks gained market exposure to cryptocurrency and cryptocurrency-related firms prior to and during the COVID-19 pandemic; the 2020–2022 cryptocurrency bubble popped in late 2022. In this environment, three such banks failed or were shut down by regulators: The first bank to fail, cryptocurrency-focused Silvergate Bank, announced it would wind down on March 8, 2023 due to losses suffered in its loan portfolio. Two days later, upon announcement of an attempt to raise capital, a bank run occurred at Silicon Valley Bank, causing it to collapse and be seized by regulators that day.', \"Treasuries, agency debt and mortgage-backed securities, and other qualifying assets as collateral. The program is designed to provide liquidity to financial institutions, following the collapse of Silicon Valley Bank and other bank failures, and to reduce the risks associated with current unrealized losses in the U.S. banking system that totaled over $600 billion at the time of the program's launch. Funded through the Deposit Insurance Fund, the program offers loans of up to one year to eligible borrowers who pledge as collateral certain types of securities including U.S. Treasuries, agency debt, and mortgage-backed securities.\"]}\n", 249 | "\u001b[32m*************************************************************\u001b[0m\n", 250 | "\n", 251 | "--------------------------------------------------------------------------------\n", 252 | "\u001b[33mmoderator\u001b[0m (to chat_manager):\n", 253 | "\n", 254 | "SVB, Silicon Valley Bank, defaulted on March 10, 2023, after a bank run was triggered when it sold its Treasury bond portfolio at a large loss. This caused concerns amongst depositors regarding the bank's liquidity, leading to large withdrawals. Silicon Valley Bank had a mainly clientele of technology companies and wealthy individuals. Balances exceeding $250,000 were not insured by the Federal Deposit Insurance Corporation (FDIC). Consequently, the California Department of Financial Protection and Innovation seized SVB and placed it under the receivership of the FDIC. TERMINATE\n", 255 | "\n", 256 | "--------------------------------------------------------------------------------\n" 257 | ] 258 | } 259 | ], 260 | "source": [ 261 | "import autogen \n", 262 | "user_proxy = autogen.UserProxyAgent(\n", 263 | " name=\"user_proxy\",\n", 264 | " is_termination_msg=lambda x: x.get(\"content\", \"\") and x.get(\"content\", \"\").rstrip().endswith(\"TERMINATE\"),\n", 265 | " human_input_mode=\"NEVER\",\n", 266 | " max_consecutive_auto_reply=5,\n", 267 | " # system_message= '''Use the tools available to respond to queries.''',\n", 268 | " # llm_config=llm_config,\n", 269 | " \n", 270 | ")\n", 271 | "\n", 272 | "assistant = autogen.AssistantAgent(\n", 273 | " name=\"assistant\",\n", 274 | " system_message='''Complete the task. Begin by utilising the `search_and_index_wikipedia` function to \n", 275 | " index the relevant Wikipedia Knowledge Base, followed by using the `query_wiki_index` \n", 276 | " function to retrieve pertinent information to aid in task completion. \n", 277 | " Conclude with TERMINATE once the answer has been delivered.\n", 278 | " ''',\n", 279 | " llm_config=llm_config,\n", 280 | " # human_input_mode=\"NEVER\"\n", 281 | ")\n", 282 | "\n", 283 | "moderator = autogen.AssistantAgent(\n", 284 | " name=\"moderator\",\n", 285 | " system_message='''Your role is to guide the `assistant` by suggesting what information may be \n", 286 | " necessary to effectively address the query.\n", 287 | " Ensure the assistant is making accurate and relevant queries \n", 288 | " to each function to retrieve the needed information for task completion.\n", 289 | " Conclude with TERMINATE once the answer has been delivered.\n", 290 | " ''',\n", 291 | " llm_config=llm_config,\n", 292 | " # human_input_mode=\"NEVER\"\n", 293 | ")\n", 294 | "\n", 295 | "user_proxy.register_function(\n", 296 | " function_map={\n", 297 | " \"search_and_index_wikipedia\": search_and_index_wikipedia,\n", 298 | " \"query_wiki_index\":query_wiki_index,\n", 299 | " # \"generate_response\":generate_response\n", 300 | " }\n", 301 | ")\n", 302 | "\n", 303 | "# user_proxy.initiate_chat(\n", 304 | "# assistant,\n", 305 | "# message=\"\"\"When did croatia adopt the euro?\"\"\",\n", 306 | "# )\n", 307 | "\n", 308 | "groupchat = autogen.GroupChat(agents=[user_proxy, moderator, assistant], messages=[], max_round=20)\n", 309 | "manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)\n", 310 | "user_proxy.initiate_chat(manager, message=\"When did SVB default?\")\n" 311 | ] 312 | }, 313 | { 314 | "cell_type": "code", 315 | "execution_count": null, 316 | "metadata": {}, 317 | "outputs": [], 318 | "source": [] 319 | } 320 | ], 321 | "metadata": { 322 | "kernelspec": { 323 | "display_name": "autogen_env", 324 | "language": "python", 325 | "name": "python3" 326 | }, 327 | "language_info": { 328 | "codemirror_mode": { 329 | "name": "ipython", 330 | "version": 3 331 | }, 332 | "file_extension": ".py", 333 | "mimetype": "text/x-python", 334 | "name": "python", 335 | "nbconvert_exporter": "python", 336 | "pygments_lexer": "ipython3", 337 | "version": "3.9.18" 338 | } 339 | }, 340 | "nbformat": 4, 341 | "nbformat_minor": 2 342 | } 343 | -------------------------------------------------------------------------------- /archive/autogen_tutorial_v4.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Auto Gen Tutorial\n", 8 | "Note book written by John Adeojo\n", 9 | "Founder, and Chief Data Scientist at [Data-centric Solutions](https://www.data-centric-solutions.com/)\n" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 96, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "import autogen\n", 19 | "import yaml\n", 20 | "import openai \n", 21 | "import os\n", 22 | "\n", 23 | "script_dir = \"C:/Users/johna/OneDrive/Documents/api_keys/\"\n", 24 | "index_path = \"G:/My Drive/Data-Centric Solutions/07. Blog Posts/AutoGen/autogen_tutorial/indexes/\"\n", 25 | "configurations_path = \"G:/My Drive/Data-Centric Solutions/07. Blog Posts/AutoGen/autogen_tutorial/\"\n", 26 | "\n", 27 | "config_list = autogen.config_list_from_json(\n", 28 | " env_or_file=\"configurations.json\",\n", 29 | " file_location=configurations_path,\n", 30 | " filter_dict={\n", 31 | " \"model\": [\"gpt-3.5-turbo-16k\"],\n", 32 | " },\n", 33 | ")\n", 34 | "\n", 35 | "def get_apikey(script_dir=script_dir):\n", 36 | "\n", 37 | " script_dir = script_dir\n", 38 | " file_path = os.path.join(script_dir, \"apikeys.yml\")\n", 39 | "\n", 40 | " with open(file_path, 'r') as yamlfile:\n", 41 | " loaded_yamlfile = yaml.safe_load(yamlfile)\n", 42 | " API_KEY = loaded_yamlfile['openai']['api_key']\n", 43 | "\n", 44 | " return API_KEY\n", 45 | "\n", 46 | "openai.api_key = get_apikey()" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 97, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "# Tool 1: Does a query based search for Wikipages\n", 56 | "from typing import Any, List\n", 57 | "import wikipedia\n", 58 | "from llama_index import download_loader, VectorStoreIndex, ServiceContext\n", 59 | "from llama_index.node_parser import SimpleNodeParser\n", 60 | "from llama_index.text_splitter import get_default_text_splitter\n", 61 | "import openai\n", 62 | "from pydantic import BaseModel\n", 63 | "from llama_index.program import OpenAIPydanticProgram\n", 64 | "from utils import get_apikey\n", 65 | "from typing import Callable, Dict, Optional, Union, List, Tuple, Any\n", 66 | "from llama_hub.wikipedia.base import WikipediaReader\n", 67 | "from llama_index import StorageContext\n", 68 | "from llama_index import load_index_from_storage\n", 69 | "import json\n", 70 | "from llama_index.llms.openai import OpenAI\n", 71 | "\n", 72 | "def load_index(filepath: str):\n", 73 | " # rebuild storage context\n", 74 | " storage_context = StorageContext.from_defaults(persist_dir=index_path)\n", 75 | " # load index\n", 76 | " return load_index_from_storage(storage_context)\n", 77 | "\n", 78 | "def read_json_file(file_path: str) -> dict:\n", 79 | " with open(file_path, 'r') as f:\n", 80 | " data = json.load(f)\n", 81 | " return data\n", 82 | "\n", 83 | "def create_wikidocs(wikipage_requests):\n", 84 | " print(f\"Preparing to Download:{wikipage_requests}\")\n", 85 | " WikipediaReader = download_loader(\"WikipediaReader\")\n", 86 | " loader = WikipediaReader()\n", 87 | " documents = loader.load_data(pages=wikipage_requests)\n", 88 | " print(\"Finished downloading pages\")\n", 89 | " return documents\n", 90 | "\n", 91 | "def index_wikipedia_pages(wikipage_requests):\n", 92 | " print(f\"Preparing to index Wikipages: {wikipage_requests}\")\n", 93 | " documents = create_wikidocs(wikipage_requests)\n", 94 | " text_splits = get_default_text_splitter(chunk_size=150, chunk_overlap=45)\n", 95 | " parser = SimpleNodeParser.from_defaults(text_splitter=text_splits)\n", 96 | " service_context = ServiceContext.from_defaults(node_parser=parser)\n", 97 | " index = VectorStoreIndex.from_documents(documents, service_context=service_context, show_progress=False)\n", 98 | " index.storage_context.persist(index_path)\n", 99 | " print(f\"{wikipage_requests} have been indexed.\")\n", 100 | " return index\n", 101 | "\n", 102 | "def search_and_index_wikipedia(\n", 103 | " query: str, lang: str = \"en\", results_limit: int = 3, **load_kwargs: Any\n", 104 | " ) -> List[List]:\n", 105 | " wikipedia.set_lang(lang)\n", 106 | " wikipage_requests = wikipedia.search(query, results=results_limit)\n", 107 | " print (f\"I have found on Wikipedia: {wikipage_requests}\")\n", 108 | " index_wikipedia_pages(wikipage_requests)\n", 109 | " return print(f\"Finished indexing: {type(wikipage_requests)}\")\n", 110 | "\n", 111 | "\n", 112 | "def query_wiki_index(search_string: str, file_path = index_path,\n", 113 | " n_results: int = 20\n", 114 | ") -> None: \n", 115 | " index = load_index(filepath=index_path)\n", 116 | " query_engine = index.as_query_engine(\n", 117 | " response_mode=\"compact\", verbose=True, similarity_top_k=n_results\n", 118 | " )\n", 119 | " nodes = query_engine.query(search_string).source_nodes\n", 120 | " retrieved_context = {\n", 121 | " # \"ids\": [],\n", 122 | " \"text\": []\n", 123 | " }\n", 124 | " for node in nodes:\n", 125 | " # retrieved_context[\"ids\"].append(node.node.id_)\n", 126 | " retrieved_context[\"text\"].append(node.node.text)\n", 127 | " \n", 128 | " file_path = index_path + \"retrieved_context.json\"\n", 129 | " with open(file_path, 'w') as f:\n", 130 | " json.dump(retrieved_context, f)\n", 131 | " \n", 132 | " return retrieved_context" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 98, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "llm_config = {\n", 142 | " \"functions\": [\n", 143 | " {\n", 144 | " \"name\": \"search_and_index_wikipedia\",\n", 145 | " \"description\": \"Indexes Wikipedia pages based on a specified query to build a knowledge base for future reference. Use before query_wiki_index.\",\n", 146 | " \"parameters\": {\n", 147 | " \"type\": \"object\",\n", 148 | " \"properties\": {\n", 149 | " \"query\": {\n", 150 | " \"type\": \"string\",\n", 151 | " \"description\": \"The search query for identifying relevant Wikipedia pages to index.\",\n", 152 | " }\n", 153 | " },\n", 154 | " \"required\": [\"query\"],\n", 155 | " },\n", 156 | " },\n", 157 | " {\n", 158 | " \"name\": \"query_wiki_index\",\n", 159 | " \"description\": \"Queries the indexed Wikipedia knowledge base to retrieve pertinent information\",\n", 160 | " \"parameters\": {\n", 161 | " \"type\": \"object\",\n", 162 | " \"properties\": {\n", 163 | " \"search_string\": {\n", 164 | " \"type\": \"string\",\n", 165 | " \"description\": \"The query to search the indexed Wikipedia knowledge base for relevant information.\",\n", 166 | " }\n", 167 | " },\n", 168 | " \"required\": [\"search_string\"],\n", 169 | " },\n", 170 | " },\n", 171 | " ],\n", 172 | " \"config_list\": config_list,\n", 173 | " \"request_timeout\": 120,\n", 174 | " \"seed\":43\n", 175 | "}" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 99, 181 | "metadata": {}, 182 | "outputs": [ 183 | { 184 | "name": "stdout", 185 | "output_type": "stream", 186 | "text": [ 187 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 188 | "\n", 189 | "When did croatia adopt the euro?\n", 190 | "\n", 191 | "--------------------------------------------------------------------------------\n", 192 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 193 | "\n", 194 | "\u001b[32m***** Suggested function Call: search_and_index_wikipedia *****\u001b[0m\n", 195 | "Arguments: \n", 196 | "{\n", 197 | " \"query\": \"Croatia adoption of euro\"\n", 198 | "}\n", 199 | "\u001b[32m***************************************************************\u001b[0m\n", 200 | "\n", 201 | "--------------------------------------------------------------------------------\n", 202 | "\u001b[31m\n", 203 | ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", 204 | "\u001b[35m\n", 205 | ">>>>>>>> EXECUTING FUNCTION search_and_index_wikipedia...\u001b[0m\n", 206 | "I have found on Wikipedia: ['Croatia and the euro', 'Enlargement of the eurozone', 'Eurozone']\n", 207 | "Preparing to index Wikipages: ['Croatia and the euro', 'Enlargement of the eurozone', 'Eurozone']\n", 208 | "Preparing to Download:['Croatia and the euro', 'Enlargement of the eurozone', 'Eurozone']\n", 209 | "Finished downloading pages\n", 210 | "['Croatia and the euro', 'Enlargement of the eurozone', 'Eurozone'] have been indexed.\n", 211 | "Finished indexing: \n", 212 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 213 | "\n", 214 | "\u001b[32m***** Response from calling function \"search_and_index_wikipedia\" *****\u001b[0m\n", 215 | "None\n", 216 | "\u001b[32m***********************************************************************\u001b[0m\n", 217 | "\n", 218 | "--------------------------------------------------------------------------------\n", 219 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 220 | "\n", 221 | "\u001b[32m***** Suggested function Call: query_wiki_index *****\u001b[0m\n", 222 | "Arguments: \n", 223 | "{\n", 224 | " \"search_string\": \"Croatia adoption of euro\"\n", 225 | "}\n", 226 | "\u001b[32m*****************************************************\u001b[0m\n", 227 | "\n", 228 | "--------------------------------------------------------------------------------\n", 229 | "\u001b[31m\n", 230 | ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", 231 | "\u001b[35m\n", 232 | ">>>>>>>> EXECUTING FUNCTION query_wiki_index...\u001b[0m\n", 233 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 234 | "\n", 235 | "\u001b[32m***** Response from calling function \"query_wiki_index\" *****\u001b[0m\n", 236 | "{'text': ['The Croatian National Bank had anticipated euro adoption within two or three years of EU entry. However, the EU\\'s response to the financial crises in eurozone delayed Croatia\\'s adoption of the euro. The country\\'s own contracting economy also posed a challenge to its meeting of the convergence criteria. While keen on euro adoption, one month before Croatia\\'s EU entry, governor Vujčić stated \"...we have no date (to join the single currency) in mind at the moment\".', 'On 7 December, Croatia and the European Commission signed a Partnership Agreement for the organisation of information and communication campaigns concerning the changeover from the kuna to the euro in Croatia.In November 2021, the Croatian right-wing and eurosceptic party Hrvatski Suverenisti was unable to obtain the required number of signatures to force a referendum to block the planned adoption of the euro.On 10 December 2021, Finance Minister Marić announced that the bill on introducing the euro currency in Croatia was being drafted and could be outlined in mid-January, with its final adoption expected in April 2022.', \"Croatia adopted the euro as its currency on 1 January 2023, becoming the 20th member state of the eurozone. A fixed conversion rate was set at 1 € = 7.5345 kn.Croatia's previous currency, the kuna, used the euro (and prior to that one of the euro's major predecessors, the German mark or Deutsche Mark) as its main reference since its creation in 1994, and a long-held policy of the Croatian National Bank was to keep the kuna's exchange rate with the euro within a relatively stable range.Croatia's European Union (EU) membership obliged it to introduce the euro once it had fulfilled the euro convergence criteria.\", 'Parliament supported the report of Siegfried Mureșan that Croatia has fulfilled all the criteria for adopting euro on 1 January 2023.On 12 July 2022, the Council of EU adopted the final three legal acts that were required for Croatia to adopt the euro as legal tender. A fixed exchange rate was set at 1 € = 7.53450 kn.\\nOn 18 July 2022, the Croatian Mint began producing euro coins with Croatian national motifs.From 5 September 2022 until 31 December 2023, display of all prices in dual currency is mandatory to prevent unjustified price increases. The public can buy euro starter kits to familiarise themselves with the new currency starting 1 December 2022.', 'This had to be at least two years after Croatia joined the European Exchange Rate Mechanism (ERM II), in addition to it meeting other criteria. Croatia joined ERM II on 10 July 2020. Prime Minister Andrej Plenković stated in November 2020 that Croatia intended to adopt the euro on 1 January 2023, and in December 2020 the Croatian government adopted an action plan for euro adoption.Many small businesses in Croatia had debts denominated in euros before EU accession. Croatians already used the euro for most savings and many informal transactions. Real estate, motor vehicle and accommodation prices were mostly quoted in euros.', \"The official decision for euro adoption is made by the EU's ECOFIN council and could not occur prior to 10 July 2022, two years after Croatia joined the ERM II.On 1 June 2022, the Commission assessed in its 2022 convergence report that Croatia fulfilled all the criteria for joining the euro area and proposed to the Council that Croatia adopt the euro on 1 January 2023.On 16 June 2022, the euro area member states recommended that Croatia become the 20th member. Paschal Donohoe, President of the Eurogroup said:\\n\\nI am very pleased to announce that the Eurogroup agreed today that Croatia fulfils all the necessary conditions to adopt the euro.\", 'While keen on euro adoption, one month before Croatia\\'s EU entry, governor Vujčić stated \"...we have no date (to join the single currency) in mind at the moment\". The European Central Bank (ECB) was expecting Croatia to be approved for ERM II membership in 2016 at the earliest, with euro adoption in 2019.In April 2015, President Kolinda Grabar-Kitarović stated in a Bloomberg interview that she was \"confident that Croatia would introduce the euro by 2020\", although the then-Prime Minister Zoran Milanović subsequently refused to commit to such timeline for the euro adoption.In November 2017, Prime Minister Andrej Plenković said that Croatia aimed to join ERM II by 2020 and to introduce the euro initially by 2025.', \"== Background ==\\nCroatia's EU membership obliged it to join the eurozone once it fulfilled the euro convergence criteria. Prior to Croatian entry to the EU on 1 July 2013, Boris Vujčić, governor of the Croatian National Bank, stated that he would like the kuna to be replaced by the euro as soon as possible after accession. This had to be at least two years after Croatia joined the ERM II (in addition to it meeting other criteria).\\nThe Croatian National Bank had anticipated euro adoption within two or three years of EU entry. However, the EU's response to the financial crises in eurozone delayed Croatia's adoption of the euro.\", 'Paschal Donohoe, President of the Eurogroup said:\\n\\nI am very pleased to announce that the Eurogroup agreed today that Croatia fulfils all the necessary conditions to adopt the euro.\\nOn 24 June 2022, the European Council supported the Commission\\'s proposal for Croatia to adopt the euro. \"It endorses the Commission\\'s proposal that Croatia adopt the euro on January 1, 2023 and invites the EU\\'s ECOFIN council to adopt swiftly the relevant Commission proposals,\" the Council added.On 5 July 2022, the European Parliament approved Croatia\\'s entry in eurozone with 539 votes in favour, 45 against and 48 abstentions.', 'Croatians already used the euro for most savings and many informal transactions. Real estate, motor vehicle and accommodation prices were mostly quoted in euros.\\nOn 18 July 2022, the Croatian Mint began producing euro coins with Croatian national motifs.\\n\\n\\n== Public opinion ==\\nPublic support for the euro in Croatia', \"The central rate of the kuna was set at 1 euro = 7.53450 kuna. The earliest allowed date for euro adoption, which requires two years of ERM participation, was then 10 July 2022.\\n\\n\\n=== Target date: 1 January 2023 ===\\nOn 11 November 2020, Prime Minister Andrej Plenković stated that Croatia intended to adopt the euro on 1 January 2023.In June 2021, on the occasion of 30 years of independence, Prime Minister Plenković said the government's ambition was to join the eurozone on the target date.\", \"In September, speaking at the 11th meeting of the National Council for the Introduction of the Euro as Croatia's official currency, Plenković said Croatia had the full support of the European Commission and the European Central Bank to join the euro area. He restated his confidence Croatia would be ready to enter the euro area from the start of 2023. In September 2021, following the meeting of the Eurogroup in Slovenia, Croatia signed an official agreement (a Memorandum of Understanding) with the European Commission and eurozone member states on practical steps for the actual minting of Croatian euro coins.\", \"In 2023, everyone would be able to exchange kunas for euros free of charge in banks, in the Croatian Post offices, and in financial services and payment systems branches.On 13 May 2022, the Croatian Parliament voted in favour of the proposal to introduce the euro as legal tender.In May 2022, the European Commission completed an assessment of Croatia's progress.\", 'The letter marked the first formal step towards the adoption of the euro. Croatia committed to joining the Banking union of the European Union as part of its efforts to join ERM II. On 23 November 2019, European Commissioner Valdis Dombrovskis said that Croatia could join ERM II in the second half of 2020.Croatia joined ERM II on 10 July 2020. The central rate of the kuna was set at 1 euro = 7.53450 kuna. The earliest allowed date for euro adoption, which requires two years of ERM participation, was then 10 July 2022.', 'Prior to Croatian entry to the EU on 1 July 2013, Boris Vujčić, governor of the Croatian National Bank, stated that he would like the kuna to be replaced by the euro as soon as possible after accession. This had to be at least two years after Croatia joined the European Exchange Rate Mechanism (ERM II), in addition to it meeting other criteria. Croatia joined ERM II on 10 July 2020.', 'Croatia, which acceded to the EU in 2013, adopted the euro in 2023.\\nAll new EU members joining the bloc after the signing of the Maastricht Treaty in 1992 are obliged to adopt the euro under the terms of their accession treaties. However, the last of the five economic convergence criteria which need first to be complied with in order to qualify for euro adoption, is the exchange rate stability criterion, which requires having been an ERM-member for a minimum of two years without the presence of \"severe tensions\" for the currency exchange rate.', 'The government agreed that if it was re-elected in 2017 then it would agree a roadmap for adoption by 2020, however the election was lost to Andrej Babiš who had been against euro adoption in the near-term. Babiš\\'s successor Petr Fiala and his cabinet, formed after the 2021 legislative election, maintained the predecessor cabinets\\' intention not to adopt the euro, calling the adoption \"disadvantageous\" for the Czechs.\\n\\n\\n=== Denmark ===\\n\\nDenmark has pegged its krone to the euro at €1 = DKK 7.46038 ± 2.25% through the ERM II since it replaced the original ERM on 1 January 1999.', 'He further stated, \"As of 1 January 2023, we will change over to the euro overnight and then have another two weeks for both currencies in circulation and citizens will be able to continue to pay in kuna but after that payments will be in euro. The dual prices will remain for at least one year\".On 14 December 2021, Prime Minister Andrej Plenković stated that he expected to have a final decision from the EU on Croatia\\'s accession to the Schengen and euro areas in 2022.In January 2022, Croatian Prime Minister Andrej Plenković announced that from 5 September, prices would be displayed in both kunas and euros in the country, and through the whole of 2023.', \"On 18 July 2022, the Croatian Mint began producing euro coins with Croatian national motifs.\\n\\n\\n== Public opinion ==\\nPublic support for the euro in Croatia\\n\\n\\n== Convergence status ==\\nIn its first assessment under the convergence criteria in May 2014, the country satisfied the inflation and interest rate criteria, but did not satisfy the public finances, ERM membership, and legislation compatibility criteria. Subsequent convergence reports published in June 2016, May 2018 and June 2020 came to the same conclusions.\\nThe report published in June 2022 concluded Croatia fulfilled all the criteria for adopting the euro.\\n\\nNotes\\n\\n\\n== Background ==\\nCroatia's EU membership obliged it to join the eurozone once it fulfilled the euro convergence criteria.\", \"Since 2007, the Danish government has discussed holding another referendum on euro adoption. However the political and financial uncertainty due to the European government-debt crisis led this to be postponed. Opinion polls, which had generally favoured euro adoption from 2002 to 2010, showed a rapid decline in support during the height of the EU debt crisis, reaching a low in May 2012 with 26% in favour towards 67% against while 7% were in doubt.\\n\\n\\n=== Hungary ===\\n\\nWith their accession to the EU in 2004, Hungary began planning to adopt the euro in place of the forint. However, the country's high deficit delayed this.\"]}\n", 237 | "\u001b[32m*************************************************************\u001b[0m\n", 238 | "\n", 239 | "--------------------------------------------------------------------------------\n", 240 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 241 | "\n", 242 | "Croatia adopted the euro as its currency on 1 January 2023. This made Croatia the 20th member state of the eurozone. The exchange rate was fixed at 1 € = 7.5345 kn (Croatian kuna). The adoption of the euro was delayed due to the financial crises in the eurozone and Croatia's own contracting economy. The decision to adopt the euro was made by the EU's ECOFIN council, and Croatia joined the European Exchange Rate Mechanism (ERM II) on 10 July 2020, which was a prerequisite for euro adoption.\n", 243 | "\n", 244 | "--------------------------------------------------------------------------------\n", 245 | "\u001b[31m\n", 246 | ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", 247 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 248 | "\n", 249 | "\n", 250 | "\n", 251 | "--------------------------------------------------------------------------------\n", 252 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 253 | "\n", 254 | "Croatia adopted the euro on 1 January 2023.\n", 255 | "\n", 256 | "--------------------------------------------------------------------------------\n", 257 | "\u001b[31m\n", 258 | ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", 259 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 260 | "\n", 261 | "\n", 262 | "\n", 263 | "--------------------------------------------------------------------------------\n", 264 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 265 | "\n", 266 | "Croatia adopted the euro as its currency on 1 January 2023.\n", 267 | "\n", 268 | "--------------------------------------------------------------------------------\n", 269 | "\u001b[31m\n", 270 | ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", 271 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 272 | "\n", 273 | "\n", 274 | "\n", 275 | "--------------------------------------------------------------------------------\n", 276 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 277 | "\n", 278 | "Yes, Croatia adopted the euro as its currency on 1 January 2023.\n", 279 | "\n", 280 | "--------------------------------------------------------------------------------\n", 281 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 282 | "\n", 283 | "Thanks, why did this happen?\n", 284 | "\n", 285 | "--------------------------------------------------------------------------------\n", 286 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 287 | "\n", 288 | "The decision for Croatia to adopt the euro was based on several factors. As a member of the European Union (EU), Croatia was obligated to join the eurozone once it fulfilled the euro convergence criteria. The Croatian National Bank had anticipated euro adoption within two or three years of EU entry.\n", 289 | "\n", 290 | "However, the adoption of the euro was delayed due to the financial crises in the eurozone and Croatia's own contracting economy, which posed challenges in meeting the convergence criteria. The European Central Bank (ECB) and the EU closely monitored Croatia's progress towards meeting the necessary conditions for adopting the euro.\n", 291 | "\n", 292 | "Croatia officially joined the European Exchange Rate Mechanism (ERM II) on 10 July 2020, which was a prerequisite for euro adoption. The country worked to stabilize its currency, the Croatian kuna, and meet the other convergence criteria, such as inflation, interest rates, public finances, and compatibility of legislation.\n", 293 | "\n", 294 | "After fulfilling the necessary conditions, the EU's ECOFIN council made the official decision for Croatia to adopt the euro. On 1 June 2022, the European Commission assessed that Croatia had fulfilled all the criteria for joining the euro area and proposed that Croatia adopt the euro on 1 January 2023. This proposal was supported by the euro area member states and the European Council.\n", 295 | "\n", 296 | "Ultimately, Croatia's adoption of the euro was a significant step in its integration with the EU and the eurozone, providing benefits such as easier trade and financial integration with other member states and greater monetary stability.\n", 297 | "\n", 298 | "--------------------------------------------------------------------------------\n", 299 | "\u001b[31m\n", 300 | ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", 301 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 302 | "\n", 303 | "\n", 304 | "\n", 305 | "--------------------------------------------------------------------------------\n", 306 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 307 | "\n", 308 | "Croatia adopted the euro as its currency on 1 January 2023 due to its EU membership obligations. As a member of the European Union, Croatia was required to adopt the euro once it fulfilled the euro convergence criteria. The decision was made by the EU's ECOFIN council.\n", 309 | "\n", 310 | "Croatia had expressed its intention to adopt the euro soon after its accession to the EU in 2013. However, the adoption process was delayed due to various factors. The financial crises in the eurozone and Croatia's own economic challenges posed obstacles to meeting the convergence criteria.\n", 311 | "\n", 312 | "In order to adopt the euro, Croatia needed to join the European Exchange Rate Mechanism (ERM II) and demonstrate stability in areas such as inflation, interest rates, public finances, and legislation compatibility. Croatia successfully joined ERM II on 10 July 2020, paving the way for euro adoption.\n", 313 | "\n", 314 | "After fulfilling the necessary requirements, the European Commission proposed that Croatia adopt the euro on 1 January 2023. This proposal was supported by the euro area member states and the European Council. Croatia went through the necessary processes and preparations, including setting a fixed conversion rate, and officially adopted the euro as its currency on the specified date.\n", 315 | "\n", 316 | "--------------------------------------------------------------------------------\n", 317 | "\u001b[31m\n", 318 | ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", 319 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 320 | "\n", 321 | "\n", 322 | "\n", 323 | "--------------------------------------------------------------------------------\n", 324 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 325 | "\n", 326 | "Croatia adopted the euro as its currency on 1 January 2023 because it fulfilled the necessary criteria for euro adoption. As a member of the European Union, Croatia had an obligation to join the eurozone once it met the criteria for adopting the euro.\n", 327 | "\n", 328 | "The process of adopting the euro involved several steps. Croatia joined the European Exchange Rate Mechanism (ERM II) on 10 July 2020, which was a prerequisite for euro adoption. The country had to demonstrate stability in areas such as inflation, interest rates, public finances, and legislation compatibility.\n", 329 | "\n", 330 | "After fulfilling these criteria, the European Commission proposed that Croatia adopt the euro on 1 January 2023. This proposal was supported by the euro area member states and the European Council. The decision was then made by the EU's ECOFIN council.\n", 331 | "\n", 332 | "The adoption of the euro brings several benefits to Croatia, including increased economic integration with other eurozone countries, easier trade, and greater financial stability. It also aligns Croatia with the common currency used by a majority of EU member states.\n", 333 | "\n", 334 | "--------------------------------------------------------------------------------\n", 335 | "\u001b[31m\n", 336 | ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", 337 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 338 | "\n", 339 | "\n", 340 | "\n", 341 | "--------------------------------------------------------------------------------\n", 342 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 343 | "\n", 344 | "\u001b[32m***** Suggested function Call: query_wiki_index *****\u001b[0m\n", 345 | "Arguments: \n", 346 | "{\n", 347 | " \"search_string\": \"Reasons for Croatia adoption of the euro\"\n", 348 | "}\n", 349 | "\u001b[32m*****************************************************\u001b[0m\n", 350 | "\n", 351 | "--------------------------------------------------------------------------------\n", 352 | "\u001b[31m\n", 353 | ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", 354 | "\u001b[35m\n", 355 | ">>>>>>>> EXECUTING FUNCTION query_wiki_index...\u001b[0m\n", 356 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 357 | "\n", 358 | "\u001b[32m***** Response from calling function \"query_wiki_index\" *****\u001b[0m\n", 359 | "{'text': ['The Croatian National Bank had anticipated euro adoption within two or three years of EU entry. However, the EU\\'s response to the financial crises in eurozone delayed Croatia\\'s adoption of the euro. The country\\'s own contracting economy also posed a challenge to its meeting of the convergence criteria. While keen on euro adoption, one month before Croatia\\'s EU entry, governor Vujčić stated \"...we have no date (to join the single currency) in mind at the moment\".', \"== Background ==\\nCroatia's EU membership obliged it to join the eurozone once it fulfilled the euro convergence criteria. Prior to Croatian entry to the EU on 1 July 2013, Boris Vujčić, governor of the Croatian National Bank, stated that he would like the kuna to be replaced by the euro as soon as possible after accession. This had to be at least two years after Croatia joined the ERM II (in addition to it meeting other criteria).\\nThe Croatian National Bank had anticipated euro adoption within two or three years of EU entry. However, the EU's response to the financial crises in eurozone delayed Croatia's adoption of the euro.\", 'This had to be at least two years after Croatia joined the European Exchange Rate Mechanism (ERM II), in addition to it meeting other criteria. Croatia joined ERM II on 10 July 2020. Prime Minister Andrej Plenković stated in November 2020 that Croatia intended to adopt the euro on 1 January 2023, and in December 2020 the Croatian government adopted an action plan for euro adoption.Many small businesses in Croatia had debts denominated in euros before EU accession. Croatians already used the euro for most savings and many informal transactions. Real estate, motor vehicle and accommodation prices were mostly quoted in euros.', 'On 7 December, Croatia and the European Commission signed a Partnership Agreement for the organisation of information and communication campaigns concerning the changeover from the kuna to the euro in Croatia.In November 2021, the Croatian right-wing and eurosceptic party Hrvatski Suverenisti was unable to obtain the required number of signatures to force a referendum to block the planned adoption of the euro.On 10 December 2021, Finance Minister Marić announced that the bill on introducing the euro currency in Croatia was being drafted and could be outlined in mid-January, with its final adoption expected in April 2022.', 'Parliament supported the report of Siegfried Mureșan that Croatia has fulfilled all the criteria for adopting euro on 1 January 2023.On 12 July 2022, the Council of EU adopted the final three legal acts that were required for Croatia to adopt the euro as legal tender. A fixed exchange rate was set at 1 € = 7.53450 kn.\\nOn 18 July 2022, the Croatian Mint began producing euro coins with Croatian national motifs.From 5 September 2022 until 31 December 2023, display of all prices in dual currency is mandatory to prevent unjustified price increases. The public can buy euro starter kits to familiarise themselves with the new currency starting 1 December 2022.', 'While keen on euro adoption, one month before Croatia\\'s EU entry, governor Vujčić stated \"...we have no date (to join the single currency) in mind at the moment\". The European Central Bank (ECB) was expecting Croatia to be approved for ERM II membership in 2016 at the earliest, with euro adoption in 2019.In April 2015, President Kolinda Grabar-Kitarović stated in a Bloomberg interview that she was \"confident that Croatia would introduce the euro by 2020\", although the then-Prime Minister Zoran Milanović subsequently refused to commit to such timeline for the euro adoption.In November 2017, Prime Minister Andrej Plenković said that Croatia aimed to join ERM II by 2020 and to introduce the euro initially by 2025.', 'Croatians already used the euro for most savings and many informal transactions. Real estate, motor vehicle and accommodation prices were mostly quoted in euros.\\nOn 18 July 2022, the Croatian Mint began producing euro coins with Croatian national motifs.\\n\\n\\n== Public opinion ==\\nPublic support for the euro in Croatia', \"Croatia adopted the euro as its currency on 1 January 2023, becoming the 20th member state of the eurozone. A fixed conversion rate was set at 1 € = 7.5345 kn.Croatia's previous currency, the kuna, used the euro (and prior to that one of the euro's major predecessors, the German mark or Deutsche Mark) as its main reference since its creation in 1994, and a long-held policy of the Croatian National Bank was to keep the kuna's exchange rate with the euro within a relatively stable range.Croatia's European Union (EU) membership obliged it to introduce the euro once it had fulfilled the euro convergence criteria.\", \"The official decision for euro adoption is made by the EU's ECOFIN council and could not occur prior to 10 July 2022, two years after Croatia joined the ERM II.On 1 June 2022, the Commission assessed in its 2022 convergence report that Croatia fulfilled all the criteria for joining the euro area and proposed to the Council that Croatia adopt the euro on 1 January 2023.On 16 June 2022, the euro area member states recommended that Croatia become the 20th member. Paschal Donohoe, President of the Eurogroup said:\\n\\nI am very pleased to announce that the Eurogroup agreed today that Croatia fulfils all the necessary conditions to adopt the euro.\", \"In September, speaking at the 11th meeting of the National Council for the Introduction of the Euro as Croatia's official currency, Plenković said Croatia had the full support of the European Commission and the European Central Bank to join the euro area. He restated his confidence Croatia would be ready to enter the euro area from the start of 2023. In September 2021, following the meeting of the Eurogroup in Slovenia, Croatia signed an official agreement (a Memorandum of Understanding) with the European Commission and eurozone member states on practical steps for the actual minting of Croatian euro coins.\", 'Paschal Donohoe, President of the Eurogroup said:\\n\\nI am very pleased to announce that the Eurogroup agreed today that Croatia fulfils all the necessary conditions to adopt the euro.\\nOn 24 June 2022, the European Council supported the Commission\\'s proposal for Croatia to adopt the euro. \"It endorses the Commission\\'s proposal that Croatia adopt the euro on January 1, 2023 and invites the EU\\'s ECOFIN council to adopt swiftly the relevant Commission proposals,\" the Council added.On 5 July 2022, the European Parliament approved Croatia\\'s entry in eurozone with 539 votes in favour, 45 against and 48 abstentions.', 'Prior to Croatian entry to the EU on 1 July 2013, Boris Vujčić, governor of the Croatian National Bank, stated that he would like the kuna to be replaced by the euro as soon as possible after accession. This had to be at least two years after Croatia joined the European Exchange Rate Mechanism (ERM II), in addition to it meeting other criteria. Croatia joined ERM II on 10 July 2020.', 'Croatia, which acceded to the EU in 2013, adopted the euro in 2023.\\nAll new EU members joining the bloc after the signing of the Maastricht Treaty in 1992 are obliged to adopt the euro under the terms of their accession treaties. However, the last of the five economic convergence criteria which need first to be complied with in order to qualify for euro adoption, is the exchange rate stability criterion, which requires having been an ERM-member for a minimum of two years without the presence of \"severe tensions\" for the currency exchange rate.', \"The central rate of the kuna was set at 1 euro = 7.53450 kuna. The earliest allowed date for euro adoption, which requires two years of ERM participation, was then 10 July 2022.\\n\\n\\n=== Target date: 1 January 2023 ===\\nOn 11 November 2020, Prime Minister Andrej Plenković stated that Croatia intended to adopt the euro on 1 January 2023.In June 2021, on the occasion of 30 years of independence, Prime Minister Plenković said the government's ambition was to join the eurozone on the target date.\", 'The letter marked the first formal step towards the adoption of the euro. Croatia committed to joining the Banking union of the European Union as part of its efforts to join ERM II. On 23 November 2019, European Commissioner Valdis Dombrovskis said that Croatia could join ERM II in the second half of 2020.Croatia joined ERM II on 10 July 2020. The central rate of the kuna was set at 1 euro = 7.53450 kuna. The earliest allowed date for euro adoption, which requires two years of ERM participation, was then 10 July 2022.', \"In 2023, everyone would be able to exchange kunas for euros free of charge in banks, in the Croatian Post offices, and in financial services and payment systems branches.On 13 May 2022, the Croatian Parliament voted in favour of the proposal to introduce the euro as legal tender.In May 2022, the European Commission completed an assessment of Croatia's progress.\", 'The government agreed that if it was re-elected in 2017 then it would agree a roadmap for adoption by 2020, however the election was lost to Andrej Babiš who had been against euro adoption in the near-term. Babiš\\'s successor Petr Fiala and his cabinet, formed after the 2021 legislative election, maintained the predecessor cabinets\\' intention not to adopt the euro, calling the adoption \"disadvantageous\" for the Czechs.\\n\\n\\n=== Denmark ===\\n\\nDenmark has pegged its krone to the euro at €1 = DKK 7.46038 ± 2.25% through the ERM II since it replaced the original ERM on 1 January 1999.', \"On 18 July 2022, the Croatian Mint began producing euro coins with Croatian national motifs.\\n\\n\\n== Public opinion ==\\nPublic support for the euro in Croatia\\n\\n\\n== Convergence status ==\\nIn its first assessment under the convergence criteria in May 2014, the country satisfied the inflation and interest rate criteria, but did not satisfy the public finances, ERM membership, and legislation compatibility criteria. Subsequent convergence reports published in June 2016, May 2018 and June 2020 came to the same conclusions.\\nThe report published in June 2022 concluded Croatia fulfilled all the criteria for adopting the euro.\\n\\nNotes\\n\\n\\n== Background ==\\nCroatia's EU membership obliged it to join the eurozone once it fulfilled the euro convergence criteria.\", 'The former chief inspector of the Bulgarian National Bank, Kolyo Paramov, in office when the currency board of the state was established, believes that adoption of the euro soon would \"trigger a number of positive economic effects\": Sufficient money supply (leading to increased lending which is needed to improve economic growth), getting rid of the currency board which prevents the national bank functioning as a lender of last resort to rescue banks in financial troubles, and finally private and public lending would benefit from lower interest rates (at least half as high).Before 2015 it had been government policy to hold-off application until the European sovereign-debt crisis had resolved but with the election of Boyko Borisov, Bulgaria began pursuing membership.', \"The European sovereign-debt crisis further decreased the Czech Republic's interest in joining the eurozone. There were calls for a referendum before adopting the euro, with former Prime Minister Petr Nečas saying that the conditions had significantly changed since their accession treaty was ratified. President Miloš Zeman also supported a referendum, but did still advocate adoption of the euro.Adoption was supported under Prime Minister Bohuslav Sobotka but supported a recommendation from the Czech National Bank to refrain from setting a target date.\"]}\n", 360 | "\u001b[32m*************************************************************\u001b[0m\n", 361 | "\n", 362 | "--------------------------------------------------------------------------------\n", 363 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 364 | "\n", 365 | "The adoption of the euro by Croatia was driven by several factors. \n", 366 | "\n", 367 | "Firstly, as a member of the European Union (EU), Croatia had an obligation to join the eurozone once it fulfilled the euro convergence criteria. This requirement was part of the EU accession treaty signed by Croatia when it joined the EU in 2013.\n", 368 | "\n", 369 | "Secondly, the Croatian National Bank had anticipated the adoption of the euro within two or three years of EU entry. The decision to adopt the euro was a long-term goal for Croatia, and preparations for euro adoption have been ongoing since its EU membership.\n", 370 | "\n", 371 | "However, the adoption process was delayed due to various factors. The financial crises in the eurozone and Croatia's own contracting economy posed challenges to meeting the convergence criteria. These challenges required Croatia to stabilize its economy and demonstrate stability in areas such as inflation, interest rates, public finances, and legislation compatibility.\n", 372 | "\n", 373 | "Despite the delays, Croatia successfully joined the European Exchange Rate Mechanism (ERM II) on 10 July 2020, which was a crucial step towards euro adoption. This paved the way for Croatia to meet the necessary requirements and obtain approval from the EU's ECOFIN council for euro adoption.\n", 374 | "\n", 375 | "The adoption of the euro brings several benefits to Croatia, including increased economic integration with other eurozone countries, easier trade, and greater financial stability. It also aligns Croatia with the common currency used by a majority of EU member states.\n", 376 | "\n", 377 | "Overall, the adoption of the euro by Croatia was a significant milestone in its integration with the EU and the eurozone, and it reflects Croatia's commitment to further European integration and economic stability.\n", 378 | "\n", 379 | "--------------------------------------------------------------------------------\n", 380 | "\u001b[31m\n", 381 | ">>>>>>>> USING AUTO REPLY...\u001b[0m\n", 382 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 383 | "\n", 384 | "\n", 385 | "\n", 386 | "--------------------------------------------------------------------------------\n", 387 | "\u001b[33massistant\u001b[0m (to user_proxy):\n", 388 | "\n", 389 | "The adoption of the euro by Croatia was driven by several factors. \n", 390 | "\n", 391 | "First, it was a requirement of Croatia's membership in the European Union (EU). As part of the EU accession process, countries are obliged to eventually adopt the euro once they meet certain criteria. Croatia joined the EU on 1 July 2013 and therefore had the obligation to adopt the euro.\n", 392 | "\n", 393 | "Second, the adoption of the euro aims to enhance economic integration and stability. By adopting the common currency, Croatia eliminates currency exchange costs and risks associated with fluctuating exchange rates. It also facilitates trade and economic cooperation with other eurozone countries.\n", 394 | "\n", 395 | "Third, the euro adoption represents a further step in Croatia's European integration. It aligns Croatia's monetary policy with the eurozone and reinforces its position as a member of the EU. It also promotes financial and economic stability by being part of a larger economic system.\n", 396 | "\n", 397 | "Lastly, the decision to adopt the euro was based on fulfilling the necessary convergence criteria. These criteria include price stability, sound public finances, exchange rate stability, and long-term interest rate convergence. Croatia had to demonstrate that it met these criteria to ensure a stable and sustainable transition to the euro.\n", 398 | "\n", 399 | "Overall, the adoption of the euro by Croatia is a significant milestone in its integration with the EU and a step towards deeper economic and monetary integration with other eurozone countries.\n", 400 | "\n", 401 | "--------------------------------------------------------------------------------\n", 402 | "\u001b[33muser_proxy\u001b[0m (to assistant):\n", 403 | "\n", 404 | "TERMINATE\n", 405 | "\n", 406 | "--------------------------------------------------------------------------------\n" 407 | ] 408 | } 409 | ], 410 | "source": [ 411 | "import autogen \n", 412 | "user_proxy = autogen.UserProxyAgent(\n", 413 | " name=\"user_proxy\",\n", 414 | " is_termination_msg=lambda x: x.get(\"content\", \"\") and x.get(\"content\", \"\").rstrip().endswith(\"TERMINATE\"),\n", 415 | " human_input_mode=\"TERMINATE\",\n", 416 | " max_consecutive_auto_reply=5,\n", 417 | " # system_message= '''Use the tools available to respond to queries.''',\n", 418 | " # llm_config=llm_config,\n", 419 | " \n", 420 | ")\n", 421 | "\n", 422 | "assistant = autogen.AssistantAgent(\n", 423 | " name=\"assistant\",\n", 424 | " system_message='''Complete the task. Begin by utilising the `search_and_index_wikipedia` function to \n", 425 | " index the relevant Wikipedia Knowledge Base, followed by using the `query_wiki_index` \n", 426 | " function to retrieve pertinent information to aid in task completion. \n", 427 | " Conclude with TERMINATE once the answer has been delivered.\n", 428 | " ''',\n", 429 | " llm_config=llm_config,\n", 430 | " # human_input_mode=\"NEVER\"\n", 431 | ")\n", 432 | "\n", 433 | "\n", 434 | "user_proxy.register_function(\n", 435 | " function_map={\n", 436 | " \"search_and_index_wikipedia\": search_and_index_wikipedia,\n", 437 | " \"query_wiki_index\":query_wiki_index,\n", 438 | " # \"generate_response\":generate_response\n", 439 | " }\n", 440 | ")\n", 441 | "\n", 442 | "user_proxy.initiate_chat(\n", 443 | " assistant,\n", 444 | " message=\"\"\"When did croatia adopt the euro?\"\"\",\n", 445 | ")\n", 446 | "\n", 447 | "# groupchat = autogen.GroupChat(agents=[user_proxy, assistant, sense_checker], messages=[], max_round=20)\n", 448 | "# manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)\n", 449 | "# user_proxy.initiate_chat(manager, message=\"Give me a summary of important events in 2023\")\n" 450 | ] 451 | }, 452 | { 453 | "cell_type": "code", 454 | "execution_count": null, 455 | "metadata": {}, 456 | "outputs": [], 457 | "source": [] 458 | } 459 | ], 460 | "metadata": { 461 | "kernelspec": { 462 | "display_name": "autogen_env", 463 | "language": "python", 464 | "name": "python3" 465 | }, 466 | "language_info": { 467 | "codemirror_mode": { 468 | "name": "ipython", 469 | "version": 3 470 | }, 471 | "file_extension": ".py", 472 | "mimetype": "text/x-python", 473 | "name": "python", 474 | "nbconvert_exporter": "python", 475 | "pygments_lexer": "ipython3", 476 | "version": "3.9.18" 477 | } 478 | }, 479 | "nbformat": 4, 480 | "nbformat_minor": 2 481 | } 482 | -------------------------------------------------------------------------------- /autogen_tutorial_notebook.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Auto Gen Tutorial\n", 8 | "Note book written by John Adeojo\n", 9 | "Founder, and Chief Data Scientist at [Data-centric Solutions](https://www.data-centric-solutions.com/).\n", 10 | "\n", 11 | "---\n", 12 | "# License\n", 13 | "\n", 14 | "This work is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).\n", 15 | "\n", 16 | "## How to Credit\n", 17 | "\n", 18 | "If you use this work or adapt it, please credit the author and the company as follows:\n", 19 | "\n", 20 | "\"Auto Gen Tutorial: Open Domain Question Answering with Wikipedia\" by John Adeojo from Data-Centric Solutions, used under CC BY 4.0 / Desaturated from original\n", 21 | "\n", 22 | "## Example Citation\n", 23 | "\n", 24 | "In academic or professional contexts, you can cite this work as follows:\n", 25 | "\n", 26 | "Adeojo, John. \"Auto Gen Tutorial: Open Domain Question Answering with Wikipedia.\" Data-Centric Solutions. 08/11/202\n" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 1, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "import autogen\n", 36 | "import openai \n", 37 | "\n", 38 | "# Change the directories to pick up the files. Ensure you use your own OpenAI API Keys\n", 39 | "index_path = \"G:/My Drive/Data-Centric Solutions/07. Blog Posts/AutoGen/autogen_tutorial/indexes/\"\n", 40 | "configurations_path = \"G:/My Drive/Data-Centric Solutions/07. Blog Posts/AutoGen/autogen_tutorial/\"\n", 41 | "\n", 42 | "config_list = autogen.config_list_from_json(\n", 43 | " env_or_file=\"configurations.json\",\n", 44 | " file_location=configurations_path,\n", 45 | " filter_dict={\n", 46 | " \"model\": [\"gpt-4-1106-preview\"],\n", 47 | " },\n", 48 | ")\n", 49 | "\n", 50 | "api_key = config_list[0]['api_key']\n", 51 | "openai.api_key = api_key" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "## 1. Define tools" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 2, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "from typing import Any, List\n", 68 | "\n", 69 | "from llama_index.readers.base import BaseReader\n", 70 | "from llama_index.readers.schema.base import Document\n", 71 | "import wikipedia\n", 72 | "\n", 73 | "class WikipediaReader(BaseReader):\n", 74 | " def load_data(self, pages: List[str], lang: str = \"en\", **load_kwargs: Any) -> List[Document]:\n", 75 | " results = []\n", 76 | " for page in pages:\n", 77 | " wikipedia.set_lang(lang)\n", 78 | " wiki_page = wikipedia.page(page, **load_kwargs)\n", 79 | " page_content = wiki_page.content\n", 80 | " page_url = wiki_page.url\n", 81 | " # Create a Document with URL included in the metadata\n", 82 | " document = Document(text=page_content, metadata={'source_url': page_url})\n", 83 | " results.append(document)\n", 84 | " return results\n" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 3, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "# Tool 1: Does a query based search for Wikipages\n", 94 | "import wikipedia\n", 95 | "from llama_index import download_loader, VectorStoreIndex, ServiceContext\n", 96 | "from llama_index.node_parser import SimpleNodeParser\n", 97 | "from llama_index.text_splitter import get_default_text_splitter\n", 98 | "from llama_index import StorageContext\n", 99 | "from llama_index import load_index_from_storage\n", 100 | "import json\n", 101 | "\n", 102 | "def load_index(filepath: str):\n", 103 | " # rebuild storage context\n", 104 | " storage_context = StorageContext.from_defaults(persist_dir=index_path)\n", 105 | " # load index\n", 106 | " return load_index_from_storage(storage_context)\n", 107 | "\n", 108 | "def read_json_file(file_path: str) -> dict:\n", 109 | " with open(file_path, 'r') as f:\n", 110 | " data = json.load(f)\n", 111 | " return data\n", 112 | "\n", 113 | "\n", 114 | "def create_wikidocs(wikipage_requests):\n", 115 | " print(f\"Preparing to Download:{wikipage_requests}\")\n", 116 | " documents = []\n", 117 | " for page_title in wikipage_requests:\n", 118 | " try:\n", 119 | " # Attempt to load the Wikipedia page\n", 120 | " wiki_page = wikipedia.page(page_title)\n", 121 | " page_content = wiki_page.content\n", 122 | " page_url = wiki_page.url\n", 123 | " document = Document(text=page_content, metadata={'source_url': page_url})\n", 124 | " documents.append(document)\n", 125 | " except wikipedia.exceptions.PageError:\n", 126 | " # Handle the case where the page does not exist\n", 127 | " print(f\"PageError: The page titled '{page_title}' does not exist on Wikipedia.\")\n", 128 | " except wikipedia.exceptions.DisambiguationError as e:\n", 129 | " # Handle the case where the page title is ambiguous\n", 130 | " print(f\"DisambiguationError: The page titled '{page_title}' is ambiguous. Possible options: {e.options}\")\n", 131 | " print(\"Finished downloading pages\")\n", 132 | " return documents\n", 133 | "\n", 134 | "\n", 135 | "def index_wikipedia_pages(wikipage_requests):\n", 136 | " print(f\"Preparing to index Wikipages: {wikipage_requests}\")\n", 137 | " documents = create_wikidocs(wikipage_requests)\n", 138 | " text_splits = get_default_text_splitter(chunk_size=150, chunk_overlap=45)\n", 139 | " parser = SimpleNodeParser.from_defaults(text_splitter=text_splits)\n", 140 | " service_context = ServiceContext.from_defaults(node_parser=parser)\n", 141 | " index = VectorStoreIndex.from_documents(documents, service_context=service_context, show_progress=False)\n", 142 | " index.storage_context.persist(index_path)\n", 143 | " print(f\"{wikipage_requests} have been indexed.\")\n", 144 | " return \"indexed\"\n", 145 | "\n", 146 | "def search_and_index_wikipedia(\n", 147 | " hops: list, lang: str = \"en\", results_limit: int = 2\n", 148 | " ):\n", 149 | "\n", 150 | " # Set the language for Wikipedia\n", 151 | " wikipedia.set_lang(lang)\n", 152 | "\n", 153 | " # Initialize an empty list to hold all indexed page titles\n", 154 | " wikipage_requests = []\n", 155 | "\n", 156 | " # Loop through the identified hops and search for each\n", 157 | " for hop in hops:\n", 158 | " hop_pages = wikipedia.search(hop, results=results_limit)\n", 159 | " print(f\"Searching Wikipedia for: {hop} - Found: {hop_pages}\")\n", 160 | " wikipage_requests.extend(hop_pages)\n", 161 | "\n", 162 | " # Index the gathered pages (assuming 'index_wikipedia_pages' is a defined function that you implement)\n", 163 | " index_wikipedia_pages(wikipage_requests)\n", 164 | "\n", 165 | " return wikipage_requests\n", 166 | "\n", 167 | "\n", 168 | "def query_wiki_index(hops: List[str], index_path: str = index_path, n_results: int = 5): \n", 169 | " index = load_index(filepath=index_path)\n", 170 | " query_engine = index.as_query_engine(\n", 171 | " response_mode=\"compact\", verbose=True, similarity_top_k=n_results\n", 172 | " )\n", 173 | " \n", 174 | " retrieved_context = {}\n", 175 | " \n", 176 | " # Iterate over each hop in the multihop query\n", 177 | " for hop in hops:\n", 178 | " nodes = query_engine.query(hop).source_nodes\n", 179 | " \n", 180 | " # Process each node found for the current hop\n", 181 | " for node in nodes:\n", 182 | " doc_id = node.node.id_\n", 183 | " doc_text = node.node.text\n", 184 | " doc_source = node.node.metadata.get('source_url', 'No source URL') # Default value if source_url is not present.\n", 185 | " \n", 186 | " # Append to the list of texts and sources for each doc_id\n", 187 | " if doc_id not in retrieved_context:\n", 188 | " retrieved_context[doc_id] = {'texts': [doc_text], 'sources': [doc_source]}\n", 189 | " else:\n", 190 | " retrieved_context[doc_id]['texts'].append(doc_text)\n", 191 | " retrieved_context[doc_id]['sources'].append(doc_source)\n", 192 | "\n", 193 | " # Serialise the context for all hops into a JSON file\n", 194 | " file_path = index_path + \"retrieved_context.json\"\n", 195 | " with open(file_path, 'w') as f:\n", 196 | " json.dump(retrieved_context, f)\n", 197 | " \n", 198 | " return retrieved_context\n" 199 | ] 200 | }, 201 | { 202 | "cell_type": "markdown", 203 | "metadata": {}, 204 | "source": [ 205 | "## 2. Define Function Calling" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 4, 211 | "metadata": {}, 212 | "outputs": [], 213 | "source": [ 214 | "\n", 215 | "llm_config = {\n", 216 | " \"functions\": [\n", 217 | " {\n", 218 | " \"name\": \"search_and_index_wikipedia\",\n", 219 | " \"description\": \"Indexes Wikipedia pages based on specified queries for each hop to build a knowledge base for future reference. Use before query_wiki_index.\",\n", 220 | " \"parameters\": {\n", 221 | " \"type\": \"object\",\n", 222 | " \"properties\": {\n", 223 | " \"hops\": {\n", 224 | " \"type\": \"array\",\n", 225 | " \"items\": {\n", 226 | " \"type\": \"string\"\n", 227 | " },\n", 228 | " \"description\": \"The search queries for identifying relevant Wikipedia pages to index, each corresponding to a hop in the multihop question.\",\n", 229 | " }\n", 230 | " },\n", 231 | " \"required\": [\"hops\"],\n", 232 | " },\n", 233 | " },\n", 234 | " {\n", 235 | " \"name\": \"query_wiki_index\",\n", 236 | " \"description\": \"Queries the indexed Wikipedia knowledge base to retrieve pertinent information across multiple hops\",\n", 237 | " \"parameters\": {\n", 238 | " \"type\": \"object\",\n", 239 | " \"properties\": {\n", 240 | " \"hops\": {\n", 241 | " \"type\": \"array\",\n", 242 | " \"items\": {\n", 243 | " \"type\": \"string\"\n", 244 | " },\n", 245 | " \"description\": \"The search queries to search the indexed Wikipedia knowledge base for relevant information, each corresponding to a hop in the multihop question.\",\n", 246 | " },\n", 247 | " },\n", 248 | " \"required\": [\"hops\"],\n", 249 | " },\n", 250 | " },\n", 251 | " ],\n", 252 | " \"config_list\": config_list,\n", 253 | " \"request_timeout\": 120,\n", 254 | " \"seed\": 100,\n", 255 | " \"temperature\":0.7\n", 256 | "}\n", 257 | "\n", 258 | "# The llm_config_no_tools remains the same, excluding the 'functions' key.\n", 259 | "llm_config_no_tools = {k: v for k, v in llm_config.items() if k != 'functions'}\n", 260 | "\n" 261 | ] 262 | }, 263 | { 264 | "cell_type": "markdown", 265 | "metadata": {}, 266 | "source": [ 267 | "## 3. Define Agent Worflow" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": 5, 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "name": "stdout", 277 | "output_type": "stream", 278 | "text": [ 279 | "\u001b[33mchat_manager\u001b[0m (to chat_manager):\n", 280 | "\n", 281 | "How many Germans live in the colonial\n", 282 | "holding in Aruba’s continent that was governed by Prazeres’s country? \n", 283 | "\n", 284 | "--------------------------------------------------------------------------------\n", 285 | "\u001b[33manalyst\u001b[0m (to chat_manager):\n", 286 | "\n", 287 | "\u001b[32m***** Suggested function Call: search_and_index_wikipedia *****\u001b[0m\n", 288 | "Arguments: \n", 289 | "{\"hops\":[\"Germans\",\"colonial holding in Aruba\",\"Aruba's continent\",\"Prazeres's country\"]}\n", 290 | "\u001b[32m***************************************************************\u001b[0m\n", 291 | "\n", 292 | "--------------------------------------------------------------------------------\n", 293 | "\u001b[35m\n", 294 | ">>>>>>>> EXECUTING FUNCTION search_and_index_wikipedia...\u001b[0m\n", 295 | "Searching Wikipedia for: Germans - Found: ['Germans', 'Germany']\n", 296 | "Searching Wikipedia for: colonial holding in Aruba - Found: ['Aruba', 'Aruba Phosphate Company']\n", 297 | "Searching Wikipedia for: Aruba's continent - Found: ['Aruba', 'Americas']\n", 298 | "Searching Wikipedia for: Prazeres's country - Found: ['Prazeres, Madeira', 'Michel Prazeres']\n", 299 | "Preparing to index Wikipages: ['Germans', 'Germany', 'Aruba', 'Aruba Phosphate Company', 'Aruba', 'Americas', 'Prazeres, Madeira', 'Michel Prazeres']\n", 300 | "Preparing to Download:['Germans', 'Germany', 'Aruba', 'Aruba Phosphate Company', 'Aruba', 'Americas', 'Prazeres, Madeira', 'Michel Prazeres']\n", 301 | "Finished downloading pages\n", 302 | "['Germans', 'Germany', 'Aruba', 'Aruba Phosphate Company', 'Aruba', 'Americas', 'Prazeres, Madeira', 'Michel Prazeres'] have been indexed.\n", 303 | "\u001b[33muser_proxy\u001b[0m (to chat_manager):\n", 304 | "\n", 305 | "\u001b[32m***** Response from calling function \"search_and_index_wikipedia\" *****\u001b[0m\n", 306 | "['Germans', 'Germany', 'Aruba', 'Aruba Phosphate Company', 'Aruba', 'Americas', 'Prazeres, Madeira', 'Michel Prazeres']\n", 307 | "\u001b[32m***********************************************************************\u001b[0m\n", 308 | "\n", 309 | "--------------------------------------------------------------------------------\n", 310 | "\u001b[33manalyst\u001b[0m (to chat_manager):\n", 311 | "\n", 312 | "\u001b[32m***** Suggested function Call: query_wiki_index *****\u001b[0m\n", 313 | "Arguments: \n", 314 | "{\"hops\":[\"Germans in Aruba\",\"colonial power of Aruba\",\"continent of Aruba\",\"country of Prazeres\"]}\n", 315 | "\u001b[32m*****************************************************\u001b[0m\n", 316 | "\n", 317 | "--------------------------------------------------------------------------------\n", 318 | "\u001b[35m\n", 319 | ">>>>>>>> EXECUTING FUNCTION query_wiki_index...\u001b[0m\n", 320 | "\u001b[33muser_proxy\u001b[0m (to chat_manager):\n", 321 | "\n", 322 | "\u001b[32m***** Response from calling function \"query_wiki_index\" *****\u001b[0m\n", 323 | "{'09d24039-7094-4c5d-80a5-7427241a0f27': {'texts': ['Zwan, J. van der; Merryweather, S. (1948). \"Aruba Gedurende Vijftig Jaar\" [Aruba During Fifty Years]. Oranje en de zes Caraibische parelen : officieel gedenkboek ter gelegenheid van het gouden regeringsjubileum van hare majesteit Koningin Wilhelmina Helena [Orange and the Six Caribbean Pearls: Official Commemorative Book on the Occasion of the Golden Reign Jubilee of Her Majesty Queen Wilhelmina Helena.]', 'Zwan, J. van der; Merryweather, S. (1948). \"Aruba Gedurende Vijftig Jaar\" [Aruba During Fifty Years]. Oranje en de zes Caraibische parelen : officieel gedenkboek ter gelegenheid van het gouden regeringsjubileum van hare majesteit Koningin Wilhelmina Helena [Orange and the Six Caribbean Pearls: Official Commemorative Book on the Occasion of the Golden Reign Jubilee of Her Majesty Queen Wilhelmina Helena.]', 'Zwan, J. van der; Merryweather, S. (1948). \"Aruba Gedurende Vijftig Jaar\" [Aruba During Fifty Years]. Oranje en de zes Caraibische parelen : officieel gedenkboek ter gelegenheid van het gouden regeringsjubileum van hare majesteit Koningin Wilhelmina Helena [Orange and the Six Caribbean Pearls: Official Commemorative Book on the Occasion of the Golden Reign Jubilee of Her Majesty Queen Wilhelmina Helena.]'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company', 'https://en.wikipedia.org/wiki/Aruba_Phosphate_Company', 'https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, '83652e08-2ba8-4d1a-9a5c-fd11d0142d50': {'texts': [\"A substantial workforce, often exceeding 250 individuals, had stable employment, receiving their wages in cash each week. These workers earned a weekly wage of five to six guilders. Dutch guilders per week benefited the poor population of the island. Notably, the Aruba Phosphate Company did not engage in trading provisions and groceries; instead, these essential items were provided as part of the workers' wage compensation.\\nThe funds introduced into circulation on a weekly basis yielded benefits for the entire island population. Local shopkeepers made sales, while schooner and small ship owners maintained ongoing vessel operations.\"], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, 'a19cec72-7d02-431f-ba30-5e1059822e74': {'texts': ['The number of Muslims is growing. There is also a notable Jewish community, which was decimated in the Holocaust. Remembering the Holocaust is an important part of German culture.\\n\\n\\n== Geographic distribution ==\\n\\nIt is estimated that there are between 100 and 150 million Germans today, most of whom live in Germany, where they constitute the majority of the population. There are also sizable populations of Germans in Austria, Switzerland, the United States, Brazil, France, Kazakhstan, Russia, Argentina, Canada, Poland, Italy, Hungary, Australia, South Africa, Chile, Paraguay, and Namibia. German-speaking peoples such as the Austrians and the German-speaking Swiss are sometimes referred to by scholars as Germans, although most of them do not identify as such nowadays.'], 'sources': ['https://en.wikipedia.org/wiki/Germans']}, 'b6977a72-6d38-43e4-8686-51f0ddb96e5f': {'texts': ['Germans consume a high amount of alcohol, particularly beer, compared to other European peoples. Obesity is relatively widespread among Germans.Carnival is an important part of German culture, particularly in Southern Germany. An important German festival is the Oktoberfest.A steadily shrinking majority of Germans are Christians. About a third are Roman Catholics, while one third adheres to Protestantism. Another third does not profess any religion. Christian holidays such as Christmas and Easter are celebrated by many Germans. The number of Muslims is growing. There is also a notable Jewish community, which was decimated in the Holocaust.'], 'sources': ['https://en.wikipedia.org/wiki/Germans']}, 'c3a2ed50-6c52-4937-93f2-7580772ca30e': {'texts': ['Paul van Dyk, Felix Jaehn, Paul Kalkbrenner, Robin Schulz and Scooter).\\n\\n\\n=== Art, design and architecture ===\\n\\nGerman painters have influenced Western art. Albrecht Dürer, Hans Holbein the Younger, Matthias Grünewald and Lucas Cranach the Elder were important German artists of the Renaissance, Johann Baptist Zimmermann of the Baroque, Caspar David Friedrich and Carl Spitzweg of Romanticism, Max Liebermann of Impressionism and Max Ernst of Surrealism.'], 'sources': ['https://en.wikipedia.org/wiki/Germany']}, 'fb4501e1-debf-4cfc-855a-d251ef423a1a': {'texts': ['van (1904). \"Aruba\". Naar de Antillen en Venezuela [To the Antilles and Venezuela]. Leiden: A.W. Sijthoff. Retrieved 2023-09-04.\\nKol, H.H. van (1901). Een Noodlijdende Kolonie [A Suffering Colony]. Amst.-Rott.: Masereeuw & Bouten. Retrieved 2023-09-04.\\nLago Oil and Transport Co. Ltd. (1940).', 'van (1904). \"Aruba\". Naar de Antillen en Venezuela [To the Antilles and Venezuela]. Leiden: A.W. Sijthoff. Retrieved 2023-09-04.\\nKol, H.H. van (1901). Een Noodlijdende Kolonie [A Suffering Colony]. Amst.-Rott.: Masereeuw & Bouten. Retrieved 2023-09-04.\\nLago Oil and Transport Co. Ltd. (1940).'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company', 'https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, 'a4cb631c-7252-490d-acd3-0fd9f8c290c8': {'texts': ['Consequently, no concession had been granted for the phosphate at Seroe Colorado.\\nThis verdict granted complete control over the phosphate deposits to the colonial administration. The concession was put up for auction, and on January 7, 1879, it was awarded to a British resident named Charles Brodie Sewell, who, however, acted in consultation with the Aruba Island Gold Mining Company. This concession permitted C.B. Sewell to exploit and export Aruba phosphates.'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, '27d9212a-92d4-487c-a91e-ff556da20cc8': {'texts': ['Derix, Ruud (2019). The history of resource exploitation in Aruba: Landscape series 2 (Report) (published 2016).\\nHartog, J. (1961). Aruba : Past and Present : From the Time of the Indians until Today. Translated by J.A. Verleun. Oranjestad: D.J. de Wit.\\nJesurun, A. (1882).'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, '6d747179-c696-45ba-b760-57a82cef6a17': {'texts': [\"The funds introduced into circulation on a weekly basis yielded benefits for the entire island population. Local shopkeepers made sales, while schooner and small ship owners maintained ongoing vessel operations. This facilitated the consistent transport of vital supplies from Curaçao and nearby cities in Venezuela and Colombia to the island.\\n\\n\\n==== Welfare ====\\nA worker lost his hand in a dynamite explosion while working for the company but was unable to receive any pension.\\n\\n\\n=== Decline ===\\nIn 1900–1901, the company's profit amounted to only 17,055 guilders.\"], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, 'e3c48e71-0653-47fa-9e82-8b7e96546577': {'texts': ['Amst.-Rott.: Masereeuw & Bouten. Retrieved 2023-09-04.\\nLago Oil and Transport Co. Ltd. (1940). A History of Aruba (14th ed.). Pan-Aruban. Retrieved 2023-08-28.\\nZwan, J. van der; Merryweather, S. (1948). \"Aruba Gedurende Vijftig Jaar\" [Aruba During Fifty Years].'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, 'ed0f1c2b-a649-40e1-a466-5c0ac28af4cd': {'texts': ['Retrieved 2023-09-06.\\nJesurun, A. (1883). Aruba Phosphaat Maatschappij (1882-1883) Beredeneerd Verslag [Aruba Phosphate Company (1882-1883) Motivated Report] (Report). Retrieved 2023-09-06.\\nKol, H.H. van (1904). \"Aruba\". Naar de Antillen en Venezuela [To the Antilles and Venezuela]. Leiden: A.W. Sijthoff.'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, '5ef4b5b8-755d-4f54-b19c-314a12a704b6': {'texts': ['Translated by J.A. Verleun. Oranjestad: D.J. de Wit.\\nJesurun, A. (1882). Aruba Phosphaat Maatschappij (1881-1882) Beredeneerd Verslag [Aruba Phosphate Company (1881-1882) Motivated Report] (Report). Retrieved 2023-09-06.\\nJesurun, A. (1883).'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, '14d90e99-201a-45cd-b339-2a590172b5c9': {'texts': ['Prazeres (English: pleasures) is a civil parish in the municipality of Calheta in the Portuguese archipelago of Madeira. The population in 2011 was 704, in an area of 10.03 km2.\\nPrazeres is located along the main Regional 222 Roadway, linking it to Fajã da Ovelha and Estreito da Calheta. Agriculture continues to be the driving activity in the region, although commercial establishments are scattered within the community.'], 'sources': ['https://en.wikipedia.org/wiki/Prazeres,_Madeira']}, '90e3ea13-518f-415c-b30a-40d847772f46': {'texts': ['== Geography ==\\nPrazeres is central parish within the municipality of Calheta, juxtopositioned between Estreito da Calheta and Fajã da Ovelha. Physically, it extends from the edge of the escarpment overlooking the Atlantic Ocean into the interior to the Serra do Paul. In addition, upon reaching its pinnacle in the interior (1276 metres) the border continues down the river-valley of the Ribeira da Janela.'], 'sources': ['https://en.wikipedia.org/wiki/Prazeres,_Madeira']}, '61db4ced-448f-4ee7-b6f7-f0d2580c17aa': {'texts': ['Similarly, this area is the primary agricultural lands accessed by ancillary roads that extend almost to the edge of the cliffs. Starting in the area of the Regional Roadway 222 the terrain is more inclined, and forested until reaching the Serra do Paul.\\n\\n\\n== Culture ==\\nThe Clube Desportivo e Recreativo dos Prazeres (English: Sports and Recreational Club of Prazeres) is the local sports association, supporting athletes in many different areas (such as Futsal, badminton, gymnastics and/or athletics).'], 'sources': ['https://en.wikipedia.org/wiki/Prazeres,_Madeira']}, 'd6891fe9-e69a-403d-a716-715fc9c0e90b': {'texts': ['== History ==\\nThe name for the parish developed due to the existence of a small chapel in the area before the creation of the parish, dedicated to Nossa Senhora dos Prazeres (English: Our Lady of Pleasures). The reference to pleasure came from local references to an area that captivated the senses and the areas symbiosis with earthly pleasures.\\nHistorically a part of Estreito da Calheta, this region became independent, along with some homes in Fajã da Ovelha on 18 December 1676.'], 'sources': ['https://en.wikipedia.org/wiki/Prazeres,_Madeira']}, 'bae4d801-1bc1-4c0d-af52-36fc28ae1bc9': {'texts': ['The Sports Club is located in the eastern part of the parish, along with the main athletic field and air conditioned sports pavilion.\\nThe Caminho Real, one of the official Madeira Islands Footpaths (PR19) starts in Prazeres and leads to Paul do Mar.\\nThe parish has seven restaurants, serving typical traditional delicacies (such as cod) or other customary foods, such as Italian pizzas, lasagnas or pasta dishes. A popular drink, Poncha da Madeira, is a traditional liqueur drink made from lemon or orange brandy, and common in many of these restaurants.'], 'sources': ['https://en.wikipedia.org/wiki/Prazeres,_Madeira']}}\n", 324 | "\u001b[32m*************************************************************\u001b[0m\n", 325 | "\n", 326 | "--------------------------------------------------------------------------------\n", 327 | "\u001b[33mreporter\u001b[0m (to chat_manager):\n", 328 | "\n", 329 | "The information provided does not directly answer the question regarding the number of Germans living in the colonial holding in Aruba's continent that was governed by Prazeres's country. While there is a mention of the Aruba Phosphate Company and its workforce, it does not specify the nationality of these workers, nor does it mention German inhabitants specifically[1][2]. Additionally, the indexed information about Germans shows a broad overview of their global distribution but does not include specific numbers for Aruba or any connection to Prazeres's country, which is Madeira, a region of Portugal[3][14].\n", 330 | "\n", 331 | "Therefore, based on the available data, I cannot provide a precise number or even confirm the presence of Germans in the colonial holding in Aruba's continent governed by Prazeres's country (Madeira, Portugal). Further research beyond the indexed content would be necessary to determine such specifics.\n", 332 | "\n", 333 | "PLEASE REVIEW\n", 334 | "\n", 335 | "References:\n", 336 | "1. Wikipedia. Aruba Phosphate Company - https://en.wikipedia.org/wiki/Aruba_Phosphate_Company\n", 337 | "2. Wikipedia. Aruba Phosphate Company - https://en.wikipedia.org/wiki/Aruba_Phosphate_Company\n", 338 | "3. Wikipedia. Germans - https://en.wikipedia.org/wiki/Germans\n", 339 | "14. Wikipedia. Prazeres, Madeira - https://en.wikipedia.org/wiki/Prazeres,_Madeira\n", 340 | "\n", 341 | "--------------------------------------------------------------------------------\n", 342 | "\u001b[33mmoderator\u001b[0m (to chat_manager):\n", 343 | "\n", 344 | "The answer is approved.\n", 345 | "\n", 346 | "--------------------------------------------------------------------------------\n", 347 | "\u001b[33mreporter\u001b[0m (to chat_manager):\n", 348 | "\n", 349 | "TERMINATE\n", 350 | "\n", 351 | "--------------------------------------------------------------------------------\n" 352 | ] 353 | } 354 | ], 355 | "source": [ 356 | "import autogen \n", 357 | "\n", 358 | "user_proxy = autogen.UserProxyAgent(\n", 359 | " name=\"user_proxy\",\n", 360 | " is_termination_msg=lambda x: x.get(\"content\", \"\") and x.get(\"content\", \"\").rstrip().endswith(\"TERMINATE\"),\n", 361 | " human_input_mode=\"NEVER\",\n", 362 | " max_consecutive_auto_reply=5,\n", 363 | " # system_message='''You should start the workflow by consulting the analyst, then the reporter and finally the moderator. \n", 364 | " # If the analyst does not use both the `search_and_index_wikipedia` and the `query_wiki_index`, you must request that it does.'''\n", 365 | " \n", 366 | ")\n", 367 | "\n", 368 | "analyst = autogen.AssistantAgent(\n", 369 | " name=\"analyst\",\n", 370 | " system_message='''\n", 371 | " As the Information Gatherer, you must start by using the `search_and_index_wikipedia` function to gather relevant data about the user's query. Follow these steps:\n", 372 | "\n", 373 | " 1. Upon receiving a query, immediately invoke the `search_and_index_wikipedia` function to find and index Wikipedia pages related to the query. Do not proceed without completing this step.\n", 374 | " 2. After successfully indexing, utilize the `query_wiki_index` to extract detailed information from the indexed content.\n", 375 | " 3. Present the indexed information and detailed findings to the Reporter, ensuring they have a comprehensive dataset to draft a response.\n", 376 | " 4. Conclude your part with \"INFORMATION GATHERING COMPLETE\" to signal that you have finished collecting data and it is now ready for the Reporter to use in formulating the answer.\n", 377 | "\n", 378 | " Remember, you are responsible for information collection and indexing only. The Reporter will rely on the accuracy and completeness of your findings to generate the final answer.\n", 379 | "\n", 380 | " ''',\n", 381 | " llm_config=llm_config,\n", 382 | " # human_input_mode=\"NEVER\"\n", 383 | ")\n", 384 | "\n", 385 | "reporter = autogen.AssistantAgent(\n", 386 | " name=\"reporter\",\n", 387 | " system_message='''\n", 388 | " As the Reporter, you are responsible for formulating an answer to the user's query using the information provided by the Information Gatherer.\n", 389 | "\n", 390 | " 1. Wait for the Information Gatherer to complete their task and present you with the indexed information.\n", 391 | " 2. Using the gathered data, create a comprehensive and precise response that adheres to the criteria of precision, depth, clarity, and proper citation.\n", 392 | " 3. Present your draft answer followed by \"PLEASE REVIEW\" for the Moderator to assess.\n", 393 | "\n", 394 | " If the Moderator approves your answer, respond with \"TERMINATE\" to signal the end of the interaction.\n", 395 | "\n", 396 | " If the Moderator rejects your answer:\n", 397 | " - Review their feedback.\n", 398 | " - Make necessary amendments.\n", 399 | " - Resubmit the revised answer with \"PLEASE REVIEW.\"\n", 400 | "\n", 401 | " Ensure that your response is fully informed by the data provided and meets the established criteria.\n", 402 | "\n", 403 | " criteria are as follows:\n", 404 | " A. Precision: Directly address the user's question.\n", 405 | " B. Depth: Provide comprehensive information using indexed content.\n", 406 | " C. Citing: Incorporate citations within your response using the Vancouver citation style. \n", 407 | " For each reference, a superscript number shoud be insered in the text at the point of citation, corresponding to the number of the reference. \n", 408 | " At the end of the document, references must be listed numerically with links to the source provided. \n", 409 | " For instance, if you are citing a Wikipedia article, it would look like this in the text:\n", 410 | "\n", 411 | " \"The collapse of Silicon Valley Bank was primarily due to...[1].\"\n", 412 | "\n", 413 | " And then at the end of the document:\n", 414 | "\n", 415 | " References\n", 416 | " 1. Wikipedia Available from: https://en.wikipedia.org/wiki/Collapse_of_Silicon_Valley_Bank.\n", 417 | "\n", 418 | " Ensure that each citation number corresponds to a unique reference which is listed at the end of your report in the order they appear in the text.\n", 419 | " D. Clarity: Present information logically and coherently.\n", 420 | "\n", 421 | " ''',\n", 422 | " llm_config=llm_config_no_tools,\n", 423 | " \n", 424 | ")\n", 425 | "\n", 426 | "moderator = autogen.AssistantAgent(\n", 427 | " name=\"moderator\",\n", 428 | " system_message='''\n", 429 | "\n", 430 | " As the Moderator, your task is to review the Reporter's answers to ensure they meet the required criteria:\n", 431 | "\n", 432 | " - Assess the Reporter's answers after the \"PLEASE REVIEW\" prompt for alignment with the following criteria:\n", 433 | " A. Precision: Directly addressed the user's question.\n", 434 | " B. Depth: Provided comprehensive information using indexed content.\n", 435 | " C. Citing: Citations should be encorporated using the Vancouver citation style. \n", 436 | " For each reference, a superscript number shoud be insered in the text at the point of citation, corresponding to the number of the reference. \n", 437 | " At the end of the document, references must be listed numerically with links to the source provided. \n", 438 | " For instance, if you are citing a Wikipedia article, it would look like this in the text:\n", 439 | "\n", 440 | " \"The collapse of Silicon Valley Bank was primarily due to...[1].\"\n", 441 | "\n", 442 | " And then at the end of the document:\n", 443 | "\n", 444 | " References\n", 445 | " 1. Wikipedia Available from: https://en.wikipedia.org/wiki/Collapse_of_Silicon_Valley_Bank.\n", 446 | "\n", 447 | " Ensure that each citation number corresponds to a unique reference which is listed at the end of your report in the order they appear in the text.\n", 448 | " \n", 449 | " D. Clarity: information presented logically and coherently.\n", 450 | " - Approve the answer by stating \"The answer is approved\" if it meets the criteria.\n", 451 | " - If the answer falls short, specify which criteria were not met and instruct the Reporter to revise the answer accordingly. Do not generate new content or answers yourself.\n", 452 | "\n", 453 | " Your role is crucial in ensuring that the final answer provided to the user is factually correct and meets all specified quality standards.\n", 454 | "\n", 455 | " ''',\n", 456 | " llm_config=llm_config_no_tools,\n", 457 | ")\n", 458 | "\n", 459 | "user_proxy.register_function(\n", 460 | " function_map={\n", 461 | " \"search_and_index_wikipedia\": search_and_index_wikipedia,\n", 462 | " \"query_wiki_index\":query_wiki_index,\n", 463 | " }\n", 464 | ")\n", 465 | "\n", 466 | "groupchat = autogen.GroupChat(\n", 467 | " agents=[user_proxy, analyst, reporter, moderator], \n", 468 | " messages=[], \n", 469 | " max_round=20\n", 470 | " )\n", 471 | "manager = autogen.GroupChatManager(\n", 472 | " groupchat=groupchat, \n", 473 | " llm_config=llm_config, \n", 474 | " system_message='''You should start the workflow by consulting the analyst, \n", 475 | " then the reporter and finally the moderator. \n", 476 | " If the analyst does not use both the `search_and_index_wikipedia` \n", 477 | " and the `query_wiki_index`, you must request that it does.'''\n", 478 | " )\n", 479 | "\n", 480 | "manager.initiate_chat(\n", 481 | " manager, \n", 482 | " message='''How many Germans live in the colonial\n", 483 | "holding in Aruba’s continent that was governed by Prazeres’s country? '''\n", 484 | " )" 485 | ] 486 | }, 487 | { 488 | "cell_type": "code", 489 | "execution_count": null, 490 | "metadata": {}, 491 | "outputs": [], 492 | "source": [] 493 | } 494 | ], 495 | "metadata": { 496 | "kernelspec": { 497 | "display_name": "autogen_env", 498 | "language": "python", 499 | "name": "python3" 500 | }, 501 | "language_info": { 502 | "codemirror_mode": { 503 | "name": "ipython", 504 | "version": 3 505 | }, 506 | "file_extension": ".py", 507 | "mimetype": "text/x-python", 508 | "name": "python", 509 | "nbconvert_exporter": "python", 510 | "pygments_lexer": "ipython3", 511 | "version": "3.9.18" 512 | } 513 | }, 514 | "nbformat": 4, 515 | "nbformat_minor": 2 516 | } 517 | -------------------------------------------------------------------------------- /configurations.json: -------------------------------------------------------------------------------- 1 | 2 | [ 3 | { 4 | "model": "gpt-3.5-turbo-16k", 5 | "api_key": "" 6 | } , 7 | { 8 | "model": "gpt-4-1106-preview", 9 | "api_key": "" 10 | } 11 | ] 12 | -------------------------------------------------------------------------------- /indexes/Docs from Wikipedia: -------------------------------------------------------------------------------- 1 | [ -------------------------------------------------------------------------------- /indexes/graph_store.json: -------------------------------------------------------------------------------- 1 | {"graph_dict": {}} -------------------------------------------------------------------------------- /indexes/retrieved_context.json: -------------------------------------------------------------------------------- 1 | {"09d24039-7094-4c5d-80a5-7427241a0f27": {"texts": ["Zwan, J. van der; Merryweather, S. (1948). \"Aruba Gedurende Vijftig Jaar\" [Aruba During Fifty Years]. Oranje en de zes Caraibische parelen : officieel gedenkboek ter gelegenheid van het gouden regeringsjubileum van hare majesteit Koningin Wilhelmina Helena [Orange and the Six Caribbean Pearls: Official Commemorative Book on the Occasion of the Golden Reign Jubilee of Her Majesty Queen Wilhelmina Helena.]", "Zwan, J. van der; Merryweather, S. (1948). \"Aruba Gedurende Vijftig Jaar\" [Aruba During Fifty Years]. Oranje en de zes Caraibische parelen : officieel gedenkboek ter gelegenheid van het gouden regeringsjubileum van hare majesteit Koningin Wilhelmina Helena [Orange and the Six Caribbean Pearls: Official Commemorative Book on the Occasion of the Golden Reign Jubilee of Her Majesty Queen Wilhelmina Helena.]", "Zwan, J. van der; Merryweather, S. (1948). \"Aruba Gedurende Vijftig Jaar\" [Aruba During Fifty Years]. Oranje en de zes Caraibische parelen : officieel gedenkboek ter gelegenheid van het gouden regeringsjubileum van hare majesteit Koningin Wilhelmina Helena [Orange and the Six Caribbean Pearls: Official Commemorative Book on the Occasion of the Golden Reign Jubilee of Her Majesty Queen Wilhelmina Helena.]"], "sources": ["https://en.wikipedia.org/wiki/Aruba_Phosphate_Company", "https://en.wikipedia.org/wiki/Aruba_Phosphate_Company", "https://en.wikipedia.org/wiki/Aruba_Phosphate_Company"]}, "83652e08-2ba8-4d1a-9a5c-fd11d0142d50": {"texts": ["A substantial workforce, often exceeding 250 individuals, had stable employment, receiving their wages in cash each week. These workers earned a weekly wage of five to six guilders. Dutch guilders per week benefited the poor population of the island. Notably, the Aruba Phosphate Company did not engage in trading provisions and groceries; instead, these essential items were provided as part of the workers' wage compensation.\nThe funds introduced into circulation on a weekly basis yielded benefits for the entire island population. Local shopkeepers made sales, while schooner and small ship owners maintained ongoing vessel operations."], "sources": ["https://en.wikipedia.org/wiki/Aruba_Phosphate_Company"]}, "a19cec72-7d02-431f-ba30-5e1059822e74": {"texts": ["The number of Muslims is growing. There is also a notable Jewish community, which was decimated in the Holocaust. Remembering the Holocaust is an important part of German culture.\n\n\n== Geographic distribution ==\n\nIt is estimated that there are between 100 and 150 million Germans today, most of whom live in Germany, where they constitute the majority of the population. There are also sizable populations of Germans in Austria, Switzerland, the United States, Brazil, France, Kazakhstan, Russia, Argentina, Canada, Poland, Italy, Hungary, Australia, South Africa, Chile, Paraguay, and Namibia. German-speaking peoples such as the Austrians and the German-speaking Swiss are sometimes referred to by scholars as Germans, although most of them do not identify as such nowadays."], "sources": ["https://en.wikipedia.org/wiki/Germans"]}, "b6977a72-6d38-43e4-8686-51f0ddb96e5f": {"texts": ["Germans consume a high amount of alcohol, particularly beer, compared to other European peoples. Obesity is relatively widespread among Germans.Carnival is an important part of German culture, particularly in Southern Germany. An important German festival is the Oktoberfest.A steadily shrinking majority of Germans are Christians. About a third are Roman Catholics, while one third adheres to Protestantism. Another third does not profess any religion. Christian holidays such as Christmas and Easter are celebrated by many Germans. The number of Muslims is growing. There is also a notable Jewish community, which was decimated in the Holocaust."], "sources": ["https://en.wikipedia.org/wiki/Germans"]}, "c3a2ed50-6c52-4937-93f2-7580772ca30e": {"texts": ["Paul van Dyk, Felix Jaehn, Paul Kalkbrenner, Robin Schulz and Scooter).\n\n\n=== Art, design and architecture ===\n\nGerman painters have influenced Western art. Albrecht D\u00fcrer, Hans Holbein the Younger, Matthias Gr\u00fcnewald and Lucas Cranach the Elder were important German artists of the Renaissance, Johann Baptist Zimmermann of the Baroque, Caspar David Friedrich and Carl Spitzweg of Romanticism, Max Liebermann of Impressionism and Max Ernst of Surrealism."], "sources": ["https://en.wikipedia.org/wiki/Germany"]}, "fb4501e1-debf-4cfc-855a-d251ef423a1a": {"texts": ["van (1904). \"Aruba\". Naar de Antillen en Venezuela [To the Antilles and Venezuela]. Leiden: A.W. Sijthoff. Retrieved 2023-09-04.\nKol, H.H. van (1901). Een Noodlijdende Kolonie [A Suffering Colony]. Amst.-Rott.: Masereeuw & Bouten. Retrieved 2023-09-04.\nLago Oil and Transport Co. Ltd. (1940).", "van (1904). \"Aruba\". Naar de Antillen en Venezuela [To the Antilles and Venezuela]. Leiden: A.W. Sijthoff. Retrieved 2023-09-04.\nKol, H.H. van (1901). Een Noodlijdende Kolonie [A Suffering Colony]. Amst.-Rott.: Masereeuw & Bouten. Retrieved 2023-09-04.\nLago Oil and Transport Co. Ltd. (1940)."], "sources": ["https://en.wikipedia.org/wiki/Aruba_Phosphate_Company", "https://en.wikipedia.org/wiki/Aruba_Phosphate_Company"]}, "a4cb631c-7252-490d-acd3-0fd9f8c290c8": {"texts": ["Consequently, no concession had been granted for the phosphate at Seroe Colorado.\nThis verdict granted complete control over the phosphate deposits to the colonial administration. The concession was put up for auction, and on January 7, 1879, it was awarded to a British resident named Charles Brodie Sewell, who, however, acted in consultation with the Aruba Island Gold Mining Company. This concession permitted C.B. Sewell to exploit and export Aruba phosphates."], "sources": ["https://en.wikipedia.org/wiki/Aruba_Phosphate_Company"]}, "27d9212a-92d4-487c-a91e-ff556da20cc8": {"texts": ["Derix, Ruud (2019). The history of resource exploitation in Aruba: Landscape series 2 (Report) (published 2016).\nHartog, J. (1961). Aruba : Past and Present : From the Time of the Indians until Today. Translated by J.A. Verleun. Oranjestad: D.J. de Wit.\nJesurun, A. (1882)."], "sources": ["https://en.wikipedia.org/wiki/Aruba_Phosphate_Company"]}, "6d747179-c696-45ba-b760-57a82cef6a17": {"texts": ["The funds introduced into circulation on a weekly basis yielded benefits for the entire island population. Local shopkeepers made sales, while schooner and small ship owners maintained ongoing vessel operations. This facilitated the consistent transport of vital supplies from Cura\u00e7ao and nearby cities in Venezuela and Colombia to the island.\n\n\n==== Welfare ====\nA worker lost his hand in a dynamite explosion while working for the company but was unable to receive any pension.\n\n\n=== Decline ===\nIn 1900\u20131901, the company's profit amounted to only 17,055 guilders."], "sources": ["https://en.wikipedia.org/wiki/Aruba_Phosphate_Company"]}, "e3c48e71-0653-47fa-9e82-8b7e96546577": {"texts": ["Amst.-Rott.: Masereeuw & Bouten. Retrieved 2023-09-04.\nLago Oil and Transport Co. Ltd. (1940). A History of Aruba (14th ed.). Pan-Aruban. Retrieved 2023-08-28.\nZwan, J. van der; Merryweather, S. (1948). \"Aruba Gedurende Vijftig Jaar\" [Aruba During Fifty Years]."], "sources": ["https://en.wikipedia.org/wiki/Aruba_Phosphate_Company"]}, "ed0f1c2b-a649-40e1-a466-5c0ac28af4cd": {"texts": ["Retrieved 2023-09-06.\nJesurun, A. (1883). Aruba Phosphaat Maatschappij (1882-1883) Beredeneerd Verslag [Aruba Phosphate Company (1882-1883) Motivated Report] (Report). Retrieved 2023-09-06.\nKol, H.H. van (1904). \"Aruba\". Naar de Antillen en Venezuela [To the Antilles and Venezuela]. Leiden: A.W. Sijthoff."], "sources": ["https://en.wikipedia.org/wiki/Aruba_Phosphate_Company"]}, "5ef4b5b8-755d-4f54-b19c-314a12a704b6": {"texts": ["Translated by J.A. Verleun. Oranjestad: D.J. de Wit.\nJesurun, A. (1882). Aruba Phosphaat Maatschappij (1881-1882) Beredeneerd Verslag [Aruba Phosphate Company (1881-1882) Motivated Report] (Report). Retrieved 2023-09-06.\nJesurun, A. (1883)."], "sources": ["https://en.wikipedia.org/wiki/Aruba_Phosphate_Company"]}, "14d90e99-201a-45cd-b339-2a590172b5c9": {"texts": ["Prazeres (English: pleasures) is a civil parish in the municipality of Calheta in the Portuguese archipelago of Madeira. The population in 2011 was 704, in an area of 10.03 km2.\nPrazeres is located along the main Regional 222 Roadway, linking it to Faj\u00e3 da Ovelha and Estreito da Calheta. Agriculture continues to be the driving activity in the region, although commercial establishments are scattered within the community."], "sources": ["https://en.wikipedia.org/wiki/Prazeres,_Madeira"]}, "90e3ea13-518f-415c-b30a-40d847772f46": {"texts": ["== Geography ==\nPrazeres is central parish within the municipality of Calheta, juxtopositioned between Estreito da Calheta and Faj\u00e3 da Ovelha. Physically, it extends from the edge of the escarpment overlooking the Atlantic Ocean into the interior to the Serra do Paul. In addition, upon reaching its pinnacle in the interior (1276 metres) the border continues down the river-valley of the Ribeira da Janela."], "sources": ["https://en.wikipedia.org/wiki/Prazeres,_Madeira"]}, "61db4ced-448f-4ee7-b6f7-f0d2580c17aa": {"texts": ["Similarly, this area is the primary agricultural lands accessed by ancillary roads that extend almost to the edge of the cliffs. Starting in the area of the Regional Roadway 222 the terrain is more inclined, and forested until reaching the Serra do Paul.\n\n\n== Culture ==\nThe Clube Desportivo e Recreativo dos Prazeres (English: Sports and Recreational Club of Prazeres) is the local sports association, supporting athletes in many different areas (such as Futsal, badminton, gymnastics and/or athletics)."], "sources": ["https://en.wikipedia.org/wiki/Prazeres,_Madeira"]}, "d6891fe9-e69a-403d-a716-715fc9c0e90b": {"texts": ["== History ==\nThe name for the parish developed due to the existence of a small chapel in the area before the creation of the parish, dedicated to Nossa Senhora dos Prazeres (English: Our Lady of Pleasures). The reference to pleasure came from local references to an area that captivated the senses and the areas symbiosis with earthly pleasures.\nHistorically a part of Estreito da Calheta, this region became independent, along with some homes in Faj\u00e3 da Ovelha on 18 December 1676."], "sources": ["https://en.wikipedia.org/wiki/Prazeres,_Madeira"]}, "bae4d801-1bc1-4c0d-af52-36fc28ae1bc9": {"texts": ["The Sports Club is located in the eastern part of the parish, along with the main athletic field and air conditioned sports pavilion.\nThe Caminho Real, one of the official Madeira Islands Footpaths (PR19) starts in Prazeres and leads to Paul do Mar.\nThe parish has seven restaurants, serving typical traditional delicacies (such as cod) or other customary foods, such as Italian pizzas, lasagnas or pasta dishes. A popular drink, Poncha da Madeira, is a traditional liqueur drink made from lemon or orange brandy, and common in many of these restaurants."], "sources": ["https://en.wikipedia.org/wiki/Prazeres,_Madeira"]}} -------------------------------------------------------------------------------- /q2 How many Germans live in the colonial agent trace.txt: -------------------------------------------------------------------------------- 1 | How many Germans live in the colonial 2 | holding in Aruba’s continent that was governed by Prazeres’s country? 3 | 4 | -------------------------------------------------------------------------------- 5 | analyst (to chat_manager): 6 | 7 | ***** Suggested function Call: search_and_index_wikipedia ***** 8 | Arguments: 9 | {"hops":["Germans","colonial holding in Aruba","Aruba's continent","Prazeres's country"]} 10 | *************************************************************** 11 | 12 | -------------------------------------------------------------------------------- 13 | 14 | >>>>>>>> EXECUTING FUNCTION search_and_index_wikipedia... 15 | Searching Wikipedia for: Germans - Found: ['Germans', 'Germany'] 16 | Searching Wikipedia for: colonial holding in Aruba - Found: ['Aruba', 'Aruba Phosphate Company'] 17 | Searching Wikipedia for: Aruba's continent - Found: ['Aruba', 'Americas'] 18 | Searching Wikipedia for: Prazeres's country - Found: ['Prazeres, Madeira', 'Michel Prazeres'] 19 | Preparing to index Wikipages: ['Germans', 'Germany', 'Aruba', 'Aruba Phosphate Company', 'Aruba', 'Americas', 'Prazeres, Madeira', 'Michel Prazeres'] 20 | Preparing to Download:['Germans', 'Germany', 'Aruba', 'Aruba Phosphate Company', 'Aruba', 'Americas', 'Prazeres, Madeira', 'Michel Prazeres'] 21 | Finished downloading pages 22 | ['Germans', 'Germany', 'Aruba', 'Aruba Phosphate Company', 'Aruba', 'Americas', 'Prazeres, Madeira', 'Michel Prazeres'] have been indexed. 23 | user_proxy (to chat_manager): 24 | 25 | ***** Response from calling function "search_and_index_wikipedia" ***** 26 | ['Germans', 'Germany', 'Aruba', 'Aruba Phosphate Company', 'Aruba', 'Americas', 'Prazeres, Madeira', 'Michel Prazeres'] 27 | *********************************************************************** 28 | 29 | -------------------------------------------------------------------------------- 30 | analyst (to chat_manager): 31 | 32 | ***** Suggested function Call: query_wiki_index ***** 33 | Arguments: 34 | {"hops":["Germans in Aruba","colonial power of Aruba","continent of Aruba","country of Prazeres"]} 35 | ***************************************************** 36 | 37 | -------------------------------------------------------------------------------- 38 | 39 | >>>>>>>> EXECUTING FUNCTION query_wiki_index... 40 | user_proxy (to chat_manager): 41 | 42 | ***** Response from calling function "query_wiki_index" ***** 43 | {'09d24039-7094-4c5d-80a5-7427241a0f27': {'texts': ['Zwan, J. van der; Merryweather, S. (1948). "Aruba Gedurende Vijftig Jaar" [Aruba During Fifty Years]. Oranje en de zes Caraibische parelen : officieel gedenkboek ter gelegenheid van het gouden regeringsjubileum van hare majesteit Koningin Wilhelmina Helena [Orange and the Six Caribbean Pearls: Official Commemorative Book on the Occasion of the Golden Reign Jubilee of Her Majesty Queen Wilhelmina Helena.]', 'Zwan, J. van der; Merryweather, S. (1948). "Aruba Gedurende Vijftig Jaar" [Aruba During Fifty Years]. Oranje en de zes Caraibische parelen : officieel gedenkboek ter gelegenheid van het gouden regeringsjubileum van hare majesteit Koningin Wilhelmina Helena [Orange and the Six Caribbean Pearls: Official Commemorative Book on the Occasion of the Golden Reign Jubilee of Her Majesty Queen Wilhelmina Helena.]', 'Zwan, J. van der; Merryweather, S. (1948). "Aruba Gedurende Vijftig Jaar" [Aruba During Fifty Years]. Oranje en de zes Caraibische parelen : officieel gedenkboek ter gelegenheid van het gouden regeringsjubileum van hare majesteit Koningin Wilhelmina Helena [Orange and the Six Caribbean Pearls: Official Commemorative Book on the Occasion of the Golden Reign Jubilee of Her Majesty Queen Wilhelmina Helena.]'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company', 'https://en.wikipedia.org/wiki/Aruba_Phosphate_Company', 'https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, '83652e08-2ba8-4d1a-9a5c-fd11d0142d50': {'texts': ["A substantial workforce, often exceeding 250 individuals, had stable employment, receiving their wages in cash each week. These workers earned a weekly wage of five to six guilders. Dutch guilders per week benefited the poor population of the island. Notably, the Aruba Phosphate Company did not engage in trading provisions and groceries; instead, these essential items were provided as part of the workers' wage compensation.\nThe funds introduced into circulation on a weekly basis yielded benefits for the entire island population. Local shopkeepers made sales, while schooner and small ship owners maintained ongoing vessel operations."], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, 'a19cec72-7d02-431f-ba30-5e1059822e74': {'texts': ['The number of Muslims is growing. There is also a notable Jewish community, which was decimated in the Holocaust. Remembering the Holocaust is an important part of German culture.\n\n\n== Geographic distribution ==\n\nIt is estimated that there are between 100 and 150 million Germans today, most of whom live in Germany, where they constitute the majority of the population. There are also sizable populations of Germans in Austria, Switzerland, the United States, Brazil, France, Kazakhstan, Russia, Argentina, Canada, Poland, Italy, Hungary, Australia, South Africa, Chile, Paraguay, and Namibia. German-speaking peoples such as the Austrians and the German-speaking Swiss are sometimes referred to by scholars as Germans, although most of them do not identify as such nowadays.'], 'sources': ['https://en.wikipedia.org/wiki/Germans']}, 'b6977a72-6d38-43e4-8686-51f0ddb96e5f': {'texts': ['Germans consume a high amount of alcohol, particularly beer, compared to other European peoples. Obesity is relatively widespread among Germans.Carnival is an important part of German culture, particularly in Southern Germany. An important German festival is the Oktoberfest.A steadily shrinking majority of Germans are Christians. About a third are Roman Catholics, while one third adheres to Protestantism. Another third does not profess any religion. Christian holidays such as Christmas and Easter are celebrated by many Germans. The number of Muslims is growing. There is also a notable Jewish community, which was decimated in the Holocaust.'], 'sources': ['https://en.wikipedia.org/wiki/Germans']}, 'c3a2ed50-6c52-4937-93f2-7580772ca30e': {'texts': ['Paul van Dyk, Felix Jaehn, Paul Kalkbrenner, Robin Schulz and Scooter).\n\n\n=== Art, design and architecture ===\n\nGerman painters have influenced Western art. Albrecht Dürer, Hans Holbein the Younger, Matthias Grünewald and Lucas Cranach the Elder were important German artists of the Renaissance, Johann Baptist Zimmermann of the Baroque, Caspar David Friedrich and Carl Spitzweg of Romanticism, Max Liebermann of Impressionism and Max Ernst of Surrealism.'], 'sources': ['https://en.wikipedia.org/wiki/Germany']}, 'fb4501e1-debf-4cfc-855a-d251ef423a1a': {'texts': ['van (1904). "Aruba". Naar de Antillen en Venezuela [To the Antilles and Venezuela]. Leiden: A.W. Sijthoff. Retrieved 2023-09-04.\nKol, H.H. van (1901). Een Noodlijdende Kolonie [A Suffering Colony]. Amst.-Rott.: Masereeuw & Bouten. Retrieved 2023-09-04.\nLago Oil and Transport Co. Ltd. (1940).', 'van (1904). "Aruba". Naar de Antillen en Venezuela [To the Antilles and Venezuela]. Leiden: A.W. Sijthoff. Retrieved 2023-09-04.\nKol, H.H. van (1901). Een Noodlijdende Kolonie [A Suffering Colony]. Amst.-Rott.: Masereeuw & Bouten. Retrieved 2023-09-04.\nLago Oil and Transport Co. Ltd. (1940).'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company', 'https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, 'a4cb631c-7252-490d-acd3-0fd9f8c290c8': {'texts': ['Consequently, no concession had been granted for the phosphate at Seroe Colorado.\nThis verdict granted complete control over the phosphate deposits to the colonial administration. The concession was put up for auction, and on January 7, 1879, it was awarded to a British resident named Charles Brodie Sewell, who, however, acted in consultation with the Aruba Island Gold Mining Company. This concession permitted C.B. Sewell to exploit and export Aruba phosphates.'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, '27d9212a-92d4-487c-a91e-ff556da20cc8': {'texts': ['Derix, Ruud (2019). The history of resource exploitation in Aruba: Landscape series 2 (Report) (published 2016).\nHartog, J. (1961). Aruba : Past and Present : From the Time of the Indians until Today. Translated by J.A. Verleun. Oranjestad: D.J. de Wit.\nJesurun, A. (1882).'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, '6d747179-c696-45ba-b760-57a82cef6a17': {'texts': ["The funds introduced into circulation on a weekly basis yielded benefits for the entire island population. Local shopkeepers made sales, while schooner and small ship owners maintained ongoing vessel operations. This facilitated the consistent transport of vital supplies from Curaçao and nearby cities in Venezuela and Colombia to the island.\n\n\n==== Welfare ====\nA worker lost his hand in a dynamite explosion while working for the company but was unable to receive any pension.\n\n\n=== Decline ===\nIn 1900–1901, the company's profit amounted to only 17,055 guilders."], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, 'e3c48e71-0653-47fa-9e82-8b7e96546577': {'texts': ['Amst.-Rott.: Masereeuw & Bouten. Retrieved 2023-09-04.\nLago Oil and Transport Co. Ltd. (1940). A History of Aruba (14th ed.). Pan-Aruban. Retrieved 2023-08-28.\nZwan, J. van der; Merryweather, S. (1948). "Aruba Gedurende Vijftig Jaar" [Aruba During Fifty Years].'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, 'ed0f1c2b-a649-40e1-a466-5c0ac28af4cd': {'texts': ['Retrieved 2023-09-06.\nJesurun, A. (1883). Aruba Phosphaat Maatschappij (1882-1883) Beredeneerd Verslag [Aruba Phosphate Company (1882-1883) Motivated Report] (Report). Retrieved 2023-09-06.\nKol, H.H. van (1904). "Aruba". Naar de Antillen en Venezuela [To the Antilles and Venezuela]. Leiden: A.W. Sijthoff.'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, '5ef4b5b8-755d-4f54-b19c-314a12a704b6': {'texts': ['Translated by J.A. Verleun. Oranjestad: D.J. de Wit.\nJesurun, A. (1882). Aruba Phosphaat Maatschappij (1881-1882) Beredeneerd Verslag [Aruba Phosphate Company (1881-1882) Motivated Report] (Report). Retrieved 2023-09-06.\nJesurun, A. (1883).'], 'sources': ['https://en.wikipedia.org/wiki/Aruba_Phosphate_Company']}, '14d90e99-201a-45cd-b339-2a590172b5c9': {'texts': ['Prazeres (English: pleasures) is a civil parish in the municipality of Calheta in the Portuguese archipelago of Madeira. The population in 2011 was 704, in an area of 10.03 km2.\nPrazeres is located along the main Regional 222 Roadway, linking it to Fajã da Ovelha and Estreito da Calheta. Agriculture continues to be the driving activity in the region, although commercial establishments are scattered within the community.'], 'sources': ['https://en.wikipedia.org/wiki/Prazeres,_Madeira']}, '90e3ea13-518f-415c-b30a-40d847772f46': {'texts': ['== Geography ==\nPrazeres is central parish within the municipality of Calheta, juxtopositioned between Estreito da Calheta and Fajã da Ovelha. Physically, it extends from the edge of the escarpment overlooking the Atlantic Ocean into the interior to the Serra do Paul. In addition, upon reaching its pinnacle in the interior (1276 metres) the border continues down the river-valley of the Ribeira da Janela.'], 'sources': ['https://en.wikipedia.org/wiki/Prazeres,_Madeira']}, '61db4ced-448f-4ee7-b6f7-f0d2580c17aa': {'texts': ['Similarly, this area is the primary agricultural lands accessed by ancillary roads that extend almost to the edge of the cliffs. Starting in the area of the Regional Roadway 222 the terrain is more inclined, and forested until reaching the Serra do Paul.\n\n\n== Culture ==\nThe Clube Desportivo e Recreativo dos Prazeres (English: Sports and Recreational Club of Prazeres) is the local sports association, supporting athletes in many different areas (such as Futsal, badminton, gymnastics and/or athletics).'], 'sources': ['https://en.wikipedia.org/wiki/Prazeres,_Madeira']}, 'd6891fe9-e69a-403d-a716-715fc9c0e90b': {'texts': ['== History ==\nThe name for the parish developed due to the existence of a small chapel in the area before the creation of the parish, dedicated to Nossa Senhora dos Prazeres (English: Our Lady of Pleasures). The reference to pleasure came from local references to an area that captivated the senses and the areas symbiosis with earthly pleasures.\nHistorically a part of Estreito da Calheta, this region became independent, along with some homes in Fajã da Ovelha on 18 December 1676.'], 'sources': ['https://en.wikipedia.org/wiki/Prazeres,_Madeira']}, 'bae4d801-1bc1-4c0d-af52-36fc28ae1bc9': {'texts': ['The Sports Club is located in the eastern part of the parish, along with the main athletic field and air conditioned sports pavilion.\nThe Caminho Real, one of the official Madeira Islands Footpaths (PR19) starts in Prazeres and leads to Paul do Mar.\nThe parish has seven restaurants, serving typical traditional delicacies (such as cod) or other customary foods, such as Italian pizzas, lasagnas or pasta dishes. A popular drink, Poncha da Madeira, is a traditional liqueur drink made from lemon or orange brandy, and common in many of these restaurants.'], 'sources': ['https://en.wikipedia.org/wiki/Prazeres,_Madeira']}} 44 | ************************************************************* 45 | 46 | -------------------------------------------------------------------------------- 47 | reporter (to chat_manager): 48 | 49 | The information provided does not directly answer the question regarding the number of Germans living in the colonial holding in Aruba's continent that was governed by Prazeres's country. While there is a mention of the Aruba Phosphate Company and its workforce, it does not specify the nationality of these workers, nor does it mention German inhabitants specifically[1][2]. Additionally, the indexed information about Germans shows a broad overview of their global distribution but does not include specific numbers for Aruba or any connection to Prazeres's country, which is Madeira, a region of Portugal[3][14]. 50 | 51 | Therefore, based on the available data, I cannot provide a precise number or even confirm the presence of Germans in the colonial holding in Aruba's continent governed by Prazeres's country (Madeira, Portugal). Further research beyond the indexed content would be necessary to determine such specifics. 52 | 53 | PLEASE REVIEW 54 | 55 | References: 56 | 1. Wikipedia. Aruba Phosphate Company - https://en.wikipedia.org/wiki/Aruba_Phosphate_Company 57 | 2. Wikipedia. Aruba Phosphate Company - https://en.wikipedia.org/wiki/Aruba_Phosphate_Company 58 | 3. Wikipedia. Germans - https://en.wikipedia.org/wiki/Germans 59 | 14. Wikipedia. Prazeres, Madeira - https://en.wikipedia.org/wiki/Prazeres,_Madeira 60 | 61 | -------------------------------------------------------------------------------- 62 | moderator (to chat_manager): 63 | 64 | The answer is approved. 65 | 66 | -------------------------------------------------------------------------------- 67 | reporter (to chat_manager): 68 | 69 | TERMINATE 70 | 71 | -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | llama-index==0.8.52 2 | openai==0.28.1 3 | pyautogen==0.1.14 4 | docker==6.1.3 5 | pyautogen[retrievechat]==0.1.14 6 | llama-hub==0.0.43 7 | wikipedia==1.4.0 8 | --------------------------------------------------------------------------------