diff --git a/.gitignore b/.gitignore index 771e58d7..dd4927f7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,8 @@ .DS_Store dist/ README_hidden.md -**/__pycache__/ \ No newline at end of file +**/__pycache__/ +build/ +*.egg-info +storage_graph/* +chapter/* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..c5317889 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,111 @@ +--- +default_language_version: + python: python3 + +exclude: "llama-index-integrations/vector_stores/llama-index-vector-stores-wordlift/manager_client/.*" + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-byte-order-marker + - id: check-merge-conflict + - id: check-symlinks + - id: check-toml + exclude: llama-index-core/llama_index/core/_static + - id: check-yaml + exclude: llama-index-core/llama_index/core/_static + - id: detect-private-key + - id: end-of-file-fixer + exclude: llama-index-core/llama_index/core/_static + - id: mixed-line-ending + exclude: llama-index-core/llama_index/core/_static + - id: trailing-whitespace + exclude: llama-index-core/llama_index/core/_static + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.1.5 + + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + exclude: ".*poetry.lock|.*_static" + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 23.10.1 + hooks: + - id: black-jupyter + name: black-src + alias: black + exclude: "^docs|.*poetry.lock|.*_static" + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.0.1 + hooks: + - id: mypy + additional_dependencies: + [ + "types-requests", + "types-Deprecated", + "types-redis", + "types-setuptools", + "types-PyYAML", + "types-protobuf==4.24.0.4", + ] + exclude: ^(docs/|llama-index-core/llama_index/core/_static) + args: + [ + --namespace-packages, + --explicit-package-bases, + --disallow-untyped-defs, + --ignore-missing-imports, + --python-version=3.8, + ] + entry: bash -c "export MYPYPATH=llama_index" + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 23.10.1 + hooks: + - id: black-jupyter + name: black-docs-py + alias: black + files: ^(docs/|examples/) + # Using PEP 8's line length in docs prevents excess left/right scrolling + args: [--line-length=79] + - repo: https://github.com/adamchainz/blacken-docs + rev: 1.16.0 + hooks: + - id: blacken-docs + name: black-docs-text + alias: black + types_or: [rst, markdown, tex] + additional_dependencies: [black==23.10.1] + # Using PEP 8's line length in docs prevents excess left/right scrolling + args: [--line-length=79] + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.0.3 + hooks: + - id: prettier + exclude: llama-index-core/llama_index/core/_static|poetry.lock|llama-index-legacy/llama_index/legacy/_static|docs/docs + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + additional_dependencies: [tomli] + exclude: | + poetry.lock| + (\/.*?\.[\w:]+)/pyproject.toml| + llama-index-core/llama_index/core/_static| + llama-index-legacy/llama_index/legacy/_static| + (\/.*?\.[\w:]+)/poetry.lock + args: + [ + "--ignore-words-list", + "astroid,gallary,momento,narl,ot,rouge,nin,gere,asend", + ] + - repo: https://github.com/srstevenson/nb-clean + rev: 3.1.0 + hooks: + - id: nb-clean + args: [--preserve-cell-outputs, --remove-empty-cells] + - repo: https://github.com/pappasam/toml-sort + rev: v0.23.1 + hooks: + - id: toml-sort-fix + exclude: ".*poetry.lock|.*_static" diff --git a/README.md b/README.md index afa4e642..a7f94605 100644 --- a/README.md +++ b/README.md @@ -25,27 +25,34 @@ The above process includes the routing agent, knoweldge graph and memory module Raw source code for these components can also be found in their respective directories including benchmarks, notebooks, and updates. ## Installation + 1. With pip: + ``` pip install memary ``` 2. Locally: - 1. Create your [virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments) and activate it. Note that Python versions 3.12 or greater are not supported by a key dependancy, llama-index and reccomended to run of python versions <= 3.11.9. + + 1. Create your [virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments) and activate it. Note that Python versions 3.12 or greater are not supported by a key dependency, llama-index and recommended to run of python versions <= 3.11.9. 2. Install Python dependencies: + ``` pip install -r requirements.txt ``` ## Demo + **Notes:** memary currently assumes the local installation method and currently supports any models available through Ollama: + - LLM running locally using Ollama (Llama 3 8B/40B as suggested defaults) **OR** `gpt-3.5-turbo` - Vision model running locally using Ollama (LLaVA as suggested default) **OR** `gpt-4-vision-preview` memary will default to the locally run models unless explicitly specified. **To run the Streamlit app:** + 1. [Optional] If running models locally using Ollama, follow this the instructions in this [repo](https://github.com/ollama/ollama). 2. Ensure that a `.env` exists with any necessary API keys and Neo4j credentials. @@ -76,13 +83,13 @@ Google Maps: Alpha Vantage: (this key is for getting real time stock data) https://www.alphavantage.co/support/#api-key - Reccomend use https://10minutemail.com/ to generate a temporary email to use + Recommend use https://10minutemail.com/ to generate a temporary email to use ``` -4. Update user persona which can be found in `streamlit_app/data/user_persona.txt` using the user persona template which can be found in `streamlit_app/data/user_persona_template.txt`. Instructions have been provided - replace the curly brackets with relevant information. +4. Update user persona which can be found in `streamlit_app/data/user_persona.txt` using the user persona template which can be found in `streamlit_app/data/user_persona_template.txt`. Instructions have been provided - replace the curly brackets with relevant information. -5. . [Optional] Update system persona, if needed, which can be found in `streamlit_app/data/system_persona.txt`. -6. Run: +5. . [Optional] Update system persona, if needed, which can be found in `streamlit_app/data/system_persona.txt`. +6. Run: ``` cd streamlit_app @@ -90,6 +97,7 @@ streamlit run app.py ``` ## Usage + ```python from memary.agent.chat_agent import ChatAgent @@ -107,18 +115,24 @@ chat_agent = ChatAgent( past_chat_json, ) ``` + Pass in subset of `['search', 'vision', 'locate', 'stocks']` as `include_from_defaults` for different set of default tools upon initialization. + ### Adding Custom Tools + ```python def multiply(a: int, b: int) -> int: """Multiply two integers and returns the result integer""" return a * b + chat_agent.add_tool({"multiply": multiply}) ``` -More information about creating custom tools for the LlamaIndex ReAct Agent can be found [here](https://docs.llamaindex.ai/en/stable/examples/agent/react_agent/). + +More information about creating custom tools for the LlamaIndex ReAct Agent can be found [here](https://docs.llamaindex.ai/en/stable/examples/agent/react_agent/). ### Removing Tools + ```python chat_agent.remove_tool("multiply") ``` @@ -191,7 +205,7 @@ The memory module comprises the Memory Stream and Entity Knowledge Store. The me - Personalize Responses: Use the key categorized entities and themes associated with the user to tailor agent responses more closely to the user's current interests and knowledge level/expertise. - Anticipate Needs: Leverage trends and shifts identified in the summaries to anticipate users' future questions or needs. - Future contributions - - We currently extract the top N entities from the entitiy knowledge store and pass these entities into the context window for inference. memary can future benefit from more advanced memory compression techniques such as passing only entities that are in the agent's response to the context window. We look forward to related community contributions. + - We currently extract the top N entities from the entity knowledge store and pass these entities into the context window for inference. memary can future benefit from more advanced memory compression techniques such as passing only entities that are in the agent's response to the context window. We look forward to related community contributions. ![Memory Compression](diagrams/memory_compression.png) @@ -231,7 +245,7 @@ Currently memary is structured so that the ReAct agent can only process one quer - In a parallel system, the agent will be able to parse multiple queries at once. The query decomposer (QD) will pass all subqueries (or original query if no subqueries exist) to the agent at once. - Simultaneously, QD will pass the original query to the reranking module to rerank the agent responses based on their relevance to the pre-decomposed query. - Future contributions - - Once agent multiprocessing is integrated, QD will be valuable to leverage. All user queries will be passed to QD, and the (sub)queries wil be passed to the routing agent for parallel processing. + - Once agent multiprocessing is integrated, QD will be valuable to leverage. All user queries will be passed to QD, and the (sub)queries will be passed to the routing agent for parallel processing. - Self-Learning: Whenever queries are decomposed, those examples will be appended to the engine’s example store as a feedback loop for improved future performance. ### Reranking diff --git a/dev/KG_memory_stream/data/system_persona.txt b/dev/KG_memory_stream/data/system_persona.txt index df6fea71..d6592a0b 100644 --- a/dev/KG_memory_stream/data/system_persona.txt +++ b/dev/KG_memory_stream/data/system_persona.txt @@ -7,4 +7,4 @@ Contexts: A history of interactions categorized by role, content, and date. Memory Stream: A list detailing entities and their interaction dates. Knowledge Entity Store: A record of entities, including their mention count and the date of the last mention. Interaction Keys: 'user' for user questions, 'rag' for responses from our knowledge graph, and 'system' for system-generated answers. -Your responses should be informed, nuanced, and tailored, demonstrating a thorough understanding of the user's questions and the overarching conversation context. When addressing the user's latest inquiry, your answer must integrate the current conversation's context, historical interactions, and pertinent knowledge graph insights. \ No newline at end of file +Your responses should be informed, nuanced, and tailored, demonstrating a thorough understanding of the user's questions and the overarching conversation context. When addressing the user's latest inquiry, your answer must integrate the current conversation's context, historical interactions, and pertinent knowledge graph insights. diff --git a/dev/KG_memory_stream/data/user_persona.txt b/dev/KG_memory_stream/data/user_persona.txt index d4c9b144..605306b6 100644 --- a/dev/KG_memory_stream/data/user_persona.txt +++ b/dev/KG_memory_stream/data/user_persona.txt @@ -6,4 +6,4 @@ I really love sports such as badminton, tennis and workout and spend 4 or 5 day [Answer Instructions] I hope you can remember my questions and their answers so that I can leverage my personal past knowledge from you to be helpful in my life. -I always prefer short and concise answers, not over two sentences. \ No newline at end of file +I always prefer short and concise answers, not over two sentences. diff --git a/dev/KG_memory_stream/docs/update_021924.md b/dev/KG_memory_stream/docs/update_021924.md index 36a83d22..00c009aa 100644 --- a/dev/KG_memory_stream/docs/update_021924.md +++ b/dev/KG_memory_stream/docs/update_021924.md @@ -1,4 +1,5 @@ ## Update + - Implemented first version of Knowledge Graph RAG - LlamaIndex for graph framework - Nebula Graph for graph store @@ -26,9 +27,8 @@ - Extract chatper 1, 2 and 3 => N=11, E=9 ![pic1](src/chapter1_2_3.png) - - ## Todo + - [x] Modify [Nebula_graph_store_tutorial.ipynb](../Nebula_graph_store_tutorial.ipynb) to be easily produce Knowledge graphs - [ ] Implement the memory stream structures on ChatMemoryBuffer -- [x] Test Neo4j of compatible with Knowledge Graph Retriever \ No newline at end of file +- [x] Test Neo4j of compatible with Knowledge Graph Retriever diff --git a/dev/KG_memory_stream/docs/update_022024.md b/dev/KG_memory_stream/docs/update_022024.md index b4cc6068..7ce1abba 100644 --- a/dev/KG_memory_stream/docs/update_022024.md +++ b/dev/KG_memory_stream/docs/update_022024.md @@ -1,4 +1,5 @@ ## Update + - Fix the stable version of llama-index - Specified all the requirements in [requirements.txt](../requirements.txt) - Test the memory feature of llama knowledge graph @@ -6,8 +7,9 @@ But sadly, we can't see the sub-graph after finishing asking questions. This sub-graph is what we wanted. I am finding the reason. ## Todo + - [x] Modify [Nebula_graph_store_tutorial.ipynb](../Nebula_graph_store_tutorial.ipynb) to be easily produce Knowledge graphs - We can use [graph_rag_chat.py](../graph_rag_chatbot.py) for production. - [ ] Implement the memory stream structures on ChatMemoryBuffer - [x] Test Neo4j of compatible with Knowledge Graph Retriever -- [ ] Visualize sub-graph to utilize for memory stream (**new**) \ No newline at end of file +- [ ] Visualize sub-graph to utilize for memory stream (**new**) diff --git a/dev/KG_memory_stream/docs/update_022524.md b/dev/KG_memory_stream/docs/update_022524.md index 70410aa5..412db266 100644 --- a/dev/KG_memory_stream/docs/update_022524.md +++ b/dev/KG_memory_stream/docs/update_022524.md @@ -15,7 +15,8 @@ index = KnowledgeGraphIndex.from_documents( max_triplets_per_chunk=2, ) ``` -I found there is a `insert_nodes` method to inject the processed graph to pre-existed one. + +I found there is a `insert_nodes` method to inject the processed graph to pre-existed one. We can create our own Knowledge managing class to inject knowledge graph or remove or update it. @@ -26,6 +27,7 @@ We can create our own Knowledge managing class to inject knowledge graph or remo ## Memory Stream Class [memory_stream.py](../src/memory/memory_stream.py) + ``` # Example usage # Create a MemoryStream object @@ -57,5 +59,6 @@ python -m pytest tests/ ``` # TODO + - [ ] Create MemoryEntityStorage class -- [ ] Preprocessing of sub-graph's output to store them in MemoryStream \ No newline at end of file +- [ ] Preprocessing of sub-graph's output to store them in MemoryStream diff --git a/dev/KG_memory_stream/docs/update_022924.md b/dev/KG_memory_stream/docs/update_022924.md index 7b797ae5..fc1bd8d7 100644 --- a/dev/KG_memory_stream/docs/update_022924.md +++ b/dev/KG_memory_stream/docs/update_022924.md @@ -1,6 +1,6 @@ ## Combined MemoryStream with RAG -I made a half version of MemoryStream with RAG. +I made a half version of MemoryStream with RAG. We should save the entities of 'response,' but I couldn't figure out how I can get those entities from Llamaindex. We are retrieving answers through these processes. @@ -14,7 +14,7 @@ We are retrieving answers through these processes. Between 4 and 5, we should get the entities of response, but there is no function in llamaindex. Steps 4 and 5 are in one function, `query` of `RetrieverQueryEngine`. -But we can get the entities of query results of our Knowledge Graph easily. For the agile method, I just implement the memory stream using Knowledge Graph's entities. +But we can get the entities of query results of our Knowledge Graph easily. For the agile method, I just implement the memory stream using Knowledge Graph's entities. For example, if we ask, "Tell me about Harry", then we do a query to neo4j and can get all the relationships from our Knowledge Graph. And I am using this. ## Demo Result diff --git a/dev/KG_memory_stream/openrc b/dev/KG_memory_stream/openrc index 704db407..a34245c4 100644 --- a/dev/KG_memory_stream/openrc +++ b/dev/KG_memory_stream/openrc @@ -4,4 +4,4 @@ export GRAPHD_HOST="127.0.0.1" export GRAPHD_PORT="9669" export NEBULA_USER="root" export NEBULA_PASSWORD="nebula" -export NEBULA_ADDRESS=$GRAPHD_HOST:$GRAPHD_PORT \ No newline at end of file +export NEBULA_ADDRESS=$GRAPHD_HOST:$GRAPHD_PORT diff --git a/dev/KG_memory_stream/tests/memory/test_entity_knowledge_store.py b/dev/KG_memory_stream/tests/memory/test_entity_knowledge_store.py index c8bce3d8..9deb7954 100644 --- a/dev/KG_memory_stream/tests/memory/test_entity_knowledge_store.py +++ b/dev/KG_memory_stream/tests/memory/test_entity_knowledge_store.py @@ -6,11 +6,9 @@ class TestEntityKnowledgeStore(unittest.TestCase): - def setUp(self): self.file_name = "tests/memory/test_knowledge_memory.json" - self.entity_knowledge_store = EntityKnowledgeStore( - file_name=self.file_name) + self.entity_knowledge_store = EntityKnowledgeStore(file_name=self.file_name) def tearDown(self): # Clean up test file after each test @@ -20,29 +18,26 @@ def tearDown(self): pass def test_add_memory(self): - data = [ - MemoryItem("test_entity", - datetime.now().replace(microsecond=0)) - ] + data = [MemoryItem("test_entity", datetime.now().replace(microsecond=0))] self.entity_knowledge_store.add_memory(data) assert len(self.entity_knowledge_store.knowledge_memory) == 1 - assert isinstance(self.entity_knowledge_store.knowledge_memory[0], - KnowledgeMemoryItem) + assert isinstance( + self.entity_knowledge_store.knowledge_memory[0], KnowledgeMemoryItem + ) def test_convert_memory_to_knowledge_memory(self): - data = [ - MemoryItem("test_entity", - datetime.now().replace(microsecond=0)) - ] - converted_data = self.entity_knowledge_store._convert_memory_to_knowledge_memory( - data) + data = [MemoryItem("test_entity", datetime.now().replace(microsecond=0))] + converted_data = ( + self.entity_knowledge_store._convert_memory_to_knowledge_memory(data) + ) assert len(converted_data) == 1 assert isinstance(converted_data[0], KnowledgeMemoryItem) def test_update_knowledge_memory(self): data = [ - KnowledgeMemoryItem("knowledge_entity", 1, - datetime.now().replace(microsecond=0)) + KnowledgeMemoryItem( + "knowledge_entity", 1, datetime.now().replace(microsecond=0) + ) ] self.entity_knowledge_store._update_knowledge_memory(data) assert len(self.entity_knowledge_store.knowledge_memory) == 1 diff --git a/dev/KG_memory_stream/tests/memory/test_memory.json b/dev/KG_memory_stream/tests/memory/test_memory.json index b111c4cf..08816ff0 100644 --- a/dev/KG_memory_stream/tests/memory/test_memory.json +++ b/dev/KG_memory_stream/tests/memory/test_memory.json @@ -1,6 +1,6 @@ [ - { - "entity": "test_entity", - "date": "2024-02-26T12:22:14" - } -] \ No newline at end of file + { + "entity": "test_entity", + "date": "2024-02-26T12:22:14" + } +] diff --git a/dev/KG_memory_stream/tests/memory/test_memory_stream.py b/dev/KG_memory_stream/tests/memory/test_memory_stream.py index 495c6421..0fc837d6 100644 --- a/dev/KG_memory_stream/tests/memory/test_memory_stream.py +++ b/dev/KG_memory_stream/tests/memory/test_memory_stream.py @@ -4,6 +4,7 @@ from src.memory import MemoryStream from src.memory.types import MemoryItem + class TestMemoryStream(unittest.TestCase): def setUp(self): self.file_name = "tests/memory/test_memory.json" @@ -34,19 +35,28 @@ def test_save_and_load_memory(self): self.memory_stream.save_memory() new_memory_stream = MemoryStream(file_name=self.file_name) self.assertEqual(len(new_memory_stream), len(self.memory_stream)) - self.assertEqual(new_memory_stream.get_memory(), self.memory_stream.get_memory()) + self.assertEqual( + new_memory_stream.get_memory(), self.memory_stream.get_memory() + ) def test_get_memory_by_index(self): - data = [MemoryItem("entity1", datetime.now().replace(microsecond=0)), MemoryItem("entity2", datetime.now().replace(microsecond=0))] + data = [ + MemoryItem("entity1", datetime.now().replace(microsecond=0)), + MemoryItem("entity2", datetime.now().replace(microsecond=0)), + ] self.memory_stream.add_memory(data) self.assertEqual(self.memory_stream.get_memory_by_index(1), data[1]) def test_remove_memory_by_index(self): - data = [MemoryItem("entity1", datetime.now().replace(microsecond=0)), MemoryItem("entity2", datetime.now().replace(microsecond=0))] + data = [ + MemoryItem("entity1", datetime.now().replace(microsecond=0)), + MemoryItem("entity2", datetime.now().replace(microsecond=0)), + ] self.memory_stream.add_memory(data) self.memory_stream.remove_memory_by_index(0) self.assertEqual(len(self.memory_stream), 1) self.assertEqual(self.memory_stream.get_memory()[0], data[1]) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() diff --git a/dev/legacy_routing_agent/get_location.ipynb b/dev/legacy_routing_agent/get_location.ipynb index aaf9952b..9dca0adc 100644 --- a/dev/legacy_routing_agent/get_location.ipynb +++ b/dev/legacy_routing_agent/get_location.ipynb @@ -18,17 +18,18 @@ "import requests\n", "from geopy.geocoders import Nominatim\n", "\n", + "\n", "def get_location():\n", " try:\n", " # Fetch location data from ip-api\n", - " ip_url = 'http://ip-api.com/json/'\n", + " ip_url = \"http://ip-api.com/json/\"\n", " response = requests.get(ip_url)\n", " data = response.json()\n", "\n", " # Check if the response is successful\n", - " if data['status'] == 'success':\n", - " latitude = data['lat']\n", - " longitude = data['lon']\n", + " if data[\"status\"] == \"success\":\n", + " latitude = data[\"lat\"]\n", + " longitude = data[\"lon\"]\n", "\n", " # Use geopy to get more detailed location data\n", " geolocator = Nominatim(user_agent=\"geoapiExercises\")\n", @@ -43,20 +44,16 @@ " except Exception as e:\n", " return f\"An error occurred: {e}\", \"\"\n", "\n", + "\n", "latitude, longitude = get_location()\n", "if latitude and longitude:\n", " print(f\"Current Latitude: {latitude}\")\n", " print(f\"Current Longitude: {longitude}\")\n", "else:\n", - " print(latitude) # This would print the error message if location could not be determined\n" + " print(\n", + " latitude\n", + " ) # This would print the error message if location could not be determined" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -74,8 +71,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/legacy_routing_agent/main.py b/dev/legacy_routing_agent/main.py index 494365b0..d543d0a7 100644 --- a/dev/legacy_routing_agent/main.py +++ b/dev/legacy_routing_agent/main.py @@ -1,107 +1,117 @@ -import ml, utils -from flask import Flask, request, jsonify, send_file, render_template, make_response +import ml +from flask import Flask, request, jsonify, render_template, make_response from flask.helpers import send_from_directory from werkzeug.utils import secure_filename from dotenv import load_dotenv -import json, os, uuid +import os +import uuid import googlemaps load_dotenv() app = Flask(__name__) -app.config['UPLOAD_FOLDER'] = './uploads' +app.config["UPLOAD_FOLDER"] = "./uploads" google_maps_key = os.getenv("google_maps_key") gmaps = googlemaps.Client(key=google_maps_key) - -@app.route('/audio/', methods=['GET']) + + +@app.route("/audio/", methods=["GET"]) def serve_audio(filename): - return send_from_directory(os.path.join('./audio_files'), filename, mimetype='audio/wav') - -@app.route('/process', methods=['POST']) -def process(): - try: - question = request.form['question'] - - if "vision" in question: - return handle_vision_question(request) - elif "location" in question: - return handle_location_question(request) - else: - return jsonify({"message": "Question type not recognized."}), 400 - - except Exception as e: - print(f"Caught exception: {e}") - return make_response(jsonify({"error": str(e)}), 400) - -def handle_vision_question(request): - print("Handling vision request ...") - try: - if 'file' not in request.files: + return send_from_directory( + os.path.join("./audio_files"), filename, mimetype="audio/wav" + ) + + +@app.route("/process", methods=["POST"]) +def process(): + try: + question = request.form["question"] + + if "vision" in question: + return handle_vision_question(request) + elif "location" in question: + return handle_location_question(request) + else: + return jsonify({"message": "Question type not recognized."}), 400 + + except Exception as e: + print(f"Caught exception: {e}") + return make_response(jsonify({"error": str(e)}), 400) + + +def handle_vision_question(request): + print("Handling vision request ...") + try: + if "file" not in request.files: return jsonify({"error": "No file part in the request"}), 400 - - file = request.files['file'] - question = request.form['question'] - - if file.filename == '': - print("No file selected") - return jsonify({"error": "No file selected"}), 400 - - if file: - filename = secure_filename(file.filename) - filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename) - file.save(filepath) - print(f"Saved file to {filepath}") - - base64_image = ml.encode_image(filepath) - - gpt_response = ml.call_gpt_vision(base64_image, question) - print("GPT-4 vision response recieved.") - - return handle_audio_response(gpt_response) - - except Exception as e: - print(f"Caught exception in handle_vision_question: {e}") - return jsonify({"error": str(e)}), 500 - -def handle_location_question(request): - print("Handling location request ...") - - try: - latitude = request.form.get('latitude') - longitude = request.form.get('longitude') - print(f"Location recieved: ({latitude}, {longitude})") - - if not latitude or not longitude: - text = "Location could not be determined." - else: - reverse_geocode_result = gmaps.reverse_geocode((latitude, longitude)) - readable_address = reverse_geocode_result[0]['formatted_address'] - - text = "Your readable address is" + readable_address - - return handle_audio_response(text) - - except Exception as e: - print(f"Caught exception in handle_location_question: {e}") - return jsonify({"error": str(e)}), 500 - -def handle_audio_response(text): - audio_directory = './audio_files' - if not os.path.exists(audio_directory): - os.makedirs(audio_directory) - - audio_filename = f"audio_{uuid.uuid4()}.mp3" - audio_path = os.path.join(audio_directory, audio_filename) - ml.text_to_speech(text, audio_path) - print(f"Audio file saved at {audio_path}") - - audio_url = request.url_root + "audio/" + audio_filename - return jsonify({"audio_url": audio_url}) - -@app.route('/') + + file = request.files["file"] + question = request.form["question"] + + if file.filename == "": + print("No file selected") + return jsonify({"error": "No file selected"}), 400 + + if file: + filename = secure_filename(file.filename) + filepath = os.path.join(app.config["UPLOAD_FOLDER"], filename) + file.save(filepath) + print(f"Saved file to {filepath}") + + base64_image = ml.encode_image(filepath) + + gpt_response = ml.call_gpt_vision(base64_image, question) + print("GPT-4 vision response received.") + + return handle_audio_response(gpt_response) + + except Exception as e: + print(f"Caught exception in handle_vision_question: {e}") + return jsonify({"error": str(e)}), 500 + + +def handle_location_question(request): + print("Handling location request ...") + + try: + latitude = request.form.get("latitude") + longitude = request.form.get("longitude") + print(f"Location received: ({latitude}, {longitude})") + + if not latitude or not longitude: + text = "Location could not be determined." + else: + reverse_geocode_result = gmaps.reverse_geocode((latitude, longitude)) + readable_address = reverse_geocode_result[0]["formatted_address"] + + text = "Your readable address is" + readable_address + + return handle_audio_response(text) + + except Exception as e: + print(f"Caught exception in handle_location_question: {e}") + return jsonify({"error": str(e)}), 500 + + +def handle_audio_response(text): + audio_directory = "./audio_files" + if not os.path.exists(audio_directory): + os.makedirs(audio_directory) + + audio_filename = f"audio_{uuid.uuid4()}.mp3" + audio_path = os.path.join(audio_directory, audio_filename) + ml.text_to_speech(text, audio_path) + print(f"Audio file saved at {audio_path}") + + audio_url = request.url_root + "audio/" + audio_filename + return jsonify({"audio_url": audio_url}) + + +@app.route("/") def home(): - return render_template('index.html') + return render_template("index.html") + -if __name__ == "__main__": - app.run(debug=True) - # app.run(host='0.0.0.0', port=5000) +if __name__ == "__main__": + app.run(debug=True) + # app.run(host='0.0.0.0', port=5000) diff --git a/dev/legacy_routing_agent/ml.py b/dev/legacy_routing_agent/ml.py index cdfa4807..056ef831 100644 --- a/dev/legacy_routing_agent/ml.py +++ b/dev/legacy_routing_agent/ml.py @@ -8,90 +8,88 @@ OPENAI_API_KEY = os.getenv("openai_api_key") client = OpenAI() - + + def call_gpt_model(prompt, data, model, temperature=None): - messages = [ - {"role": "system", "content": prompt}, - {"role": "user", "content": data} - ] - - api_params = { - "model": model, - "messages": messages - } - - if temperature is not None: - api_params["temperature"] = temperature - - try: - response = client.chat.completions.create(**api_params) - response_content = response.choices[0].message.content.strip() - - return response_content - - except Exception as e: - raise RuntimeError(f"An error occurred while making an API call: {e}") - -def call_gpt_vision(base64_image, user): - headers = { - "Content-Type": "application/json", - "Authorization": f"Bearer {OPENAI_API_KEY}" - } - - payload = { - "model": "gpt-4-vision-preview", - "messages": [ - { - "role": "system", - "content": "You are tasked with answering a blind individual's question about their current environment. Aim for brevity without sacrificing the immersive experience." - }, - { - "role": "user", - "content": [ - { - "type": "text", - "text": user - }, - { - "type": "image_url", - "image_url": { - "url": f"data:image/jpeg;base64,{base64_image}" - } - } - ] - } - ], - "max_tokens": 300 - } - - response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload) - - return response.json()['choices'][0]['message']['content'] + messages = [ + {"role": "system", "content": prompt}, + {"role": "user", "content": data}, + ] + + api_params = {"model": model, "messages": messages} + + if temperature is not None: + api_params["temperature"] = temperature + + try: + response = client.chat.completions.create(**api_params) + response_content = response.choices[0].message.content.strip() + + return response_content + + except Exception as e: + raise RuntimeError(f"An error occurred while making an API call: {e}") + + +def call_gpt_vision(base64_image, user): + headers = { + "Content-Type": "application/json", + "Authorization": f"Bearer {OPENAI_API_KEY}", + } + + payload = { + "model": "gpt-4-vision-preview", + "messages": [ + { + "role": "system", + "content": "You are tasked with answering a blind individual's question about their current environment. Aim for brevity without sacrificing the immersive experience.", + }, + { + "role": "user", + "content": [ + {"type": "text", "text": user}, + { + "type": "image_url", + "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}, + }, + ], + }, + ], + "max_tokens": 300, + } + + response = requests.post( + "https://api.openai.com/v1/chat/completions", headers=headers, json=payload + ) + + return response.json()["choices"][0]["message"]["content"] + def encode_image(image_path): with open(image_path, "rb") as image_file: - return base64.b64encode(image_file.read()).decode('utf-8') - -def text_to_speech(text, filepath): - try: - response = client.audio.speech.create( - model="tts-1", - voice="shimmer", - input=text - ) - response.stream_to_file(filepath) - - except Exception as e: - raise RuntimeError(f"An unexpected error occurred: {str(e)}") - + return base64.b64encode(image_file.read()).decode("utf-8") + + +def text_to_speech(text, filepath): + try: + response = client.audio.speech.create( + model="tts-1", voice="shimmer", input=text + ) + response.stream_to_file(filepath) + + except Exception as e: + raise RuntimeError(f"An unexpected error occurred: {str(e)}") + + def speech_to_text(filepath): - try: - audio_file = open(filepath, "rb") - transcript = client.audio.transcriptions.create( - model="whisper-1", - file=audio_file, - prompt="The transcript is about a blind person asking about their environment", - response_format="text" - ) - except Exception as e: - return f"An unexpected error occurred: {str(e)}" \ No newline at end of file + try: + audio_file = open(filepath, "rb") + transcript = client.audio.transcriptions.create( + model="whisper-1", + file=audio_file, + prompt="The transcript is about a blind person asking about their environment", + response_format="text", + ) + return transcript + except Exception as e: + return f"An unexpected error occurred: {str(e)}" diff --git a/dev/legacy_routing_agent/readme.md b/dev/legacy_routing_agent/readme.md index 17f4f9a5..f0be194a 100644 --- a/dev/legacy_routing_agent/readme.md +++ b/dev/legacy_routing_agent/readme.md @@ -1,4 +1,4 @@ -# *This is the old routing agent implementation.* Current implementation of the routing agent can be found in src/agent/base_agent.py +# _This is the old routing agent implementation._ Current implementation of the routing agent can be found in src/agent/base_agent.py Llama Index Tool Specification Example Usage This document provides an overview of how to utilize custom tool specifications with the Llama Index framework to handle specialized tasks like vision and location-based queries. @@ -18,8 +18,11 @@ The following classes are defined but commented out for clarity. You should unco python Copy code + # from main import handle_location_question, handle_vision_question, app + # from llama_index.agent.openai import OpenAIAgent + These lines would typically import custom functions and classes necessary for handling specific types of questions within an application framework like Flask. Tool Specifications @@ -30,7 +33,7 @@ Copy code from llama_index.core.tools.tool_spec.base import BaseToolSpec class CVToolSpec(BaseToolSpec): - spec_functions = ['handle_vision_question'] +spec_functions = ['handle_vision_question'] def __init__(self): # , form): # self.form = form @@ -40,7 +43,7 @@ class CVToolSpec(BaseToolSpec): return handle_vision_question(request) class LocationToolSpec(BaseToolSpec): - spec_functions = ['handle_location_question'] +spec_functions = ['handle_location_question'] def __init__(self): # , form): # self.form = form @@ -48,6 +51,7 @@ class LocationToolSpec(BaseToolSpec): def handle_location_question(request): return handle_location_question(request) + The CVToolSpec and LocationToolSpec classes inherit from BaseToolSpec and specify functions that handle vision and location questions, respectively. Integration with Llama Index @@ -71,19 +75,16 @@ The agent can now handle complex queries that require integration of different f python Copy code + # This is a hypothetical example and would need a real request object to work: + # response = agent.handle(request) + # print(response) + Replace agent.handle(request) with an appropriate method call to handle real requests. Ensure the request object is constructed properly according to the needs of the handle_vision_question and handle_location_question functions. Extending Functionality The framework allows for easy extension by adding new tool specifications or modifying existing ones to handle different types of data or queries. Remember to handle API keys and sensitive data securely, especially when dealing with location data or integrating third-party services like Google Maps. - - - - - - - diff --git a/dev/legacy_routing_agent/tool_spec.ipynb b/dev/legacy_routing_agent/tool_spec.ipynb index 4ae92d22..5ee35bfb 100644 --- a/dev/legacy_routing_agent/tool_spec.ipynb +++ b/dev/legacy_routing_agent/tool_spec.ipynb @@ -45,11 +45,11 @@ "outputs": [], "source": [ "class CVToolSpec(BaseToolSpec):\n", - " spec_functions = ['handle_vision_question']\n", + " spec_functions = [\"handle_vision_question\"]\n", "\n", - " def __init__(self): #, form):\n", + " def __init__(self): # , form):\n", " # self.form = form\n", - " ''''''\n", + " \"\"\"\"\"\"\n", "\n", " def handle_vision_question(request):\n", " return handle_vision_question(request)" @@ -72,15 +72,14 @@ "outputs": [], "source": [ "class LocationToolSpec(BaseToolSpec):\n", - " spec_functions = ['handle_location_question']\n", + " spec_functions = [\"handle_location_question\"]\n", "\n", - " def __init__(self): #, form):\n", + " def __init__(self): # , form):\n", " # self.form = form\n", - " ''''''\n", + " \"\"\"\"\"\"\n", "\n", - " def handle_location_question(request): \n", - " return handle_location_question(request)\n", - " " + " def handle_location_question(request):\n", + " return handle_location_question(request)" ] }, { @@ -89,12 +88,12 @@ "metadata": {}, "outputs": [], "source": [ - "from flask import request \n", + "from flask import request\n", "\n", "# form_data = request.form\n", "\n", "loc_tool = LocationToolSpec()\n", - "loc_tool_list = loc_tool.to_tool_list(['handle_location_question'])" + "loc_tool_list = loc_tool.to_tool_list([\"handle_location_question\"])" ] }, { @@ -113,10 +112,10 @@ "outputs": [], "source": [ "class SearchToolSpec(BaseToolSpec):\n", - " spec_functions = ['']\n", + " spec_functions = [\"\"]\n", "\n", " def __init__(self):\n", - " ''''''\n", + " \"\"\"\"\"\"\n", "\n", " def handle_search_request(request):\n", " return handle_search_request(request)" @@ -159,8 +158,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/legacy_routing_agent/utils.py b/dev/legacy_routing_agent/utils.py index 58d0b744..29716c75 100644 --- a/dev/legacy_routing_agent/utils.py +++ b/dev/legacy_routing_agent/utils.py @@ -1,12 +1,9 @@ import os import googlemaps -import json -from langchain.chat_models import ChatOpenAI from langchain.tools import StructuredTool -from langchain.agents import initialize_agent, AgentType from pydantic import BaseModel, Field from datetime import datetime -from typing import Optional, Union, List, Tuple, Any +from typing import Optional, Union, List, Tuple from dotenv import load_dotenv load_dotenv() @@ -14,158 +11,244 @@ google_maps_key = os.getenv("google_maps_key") gmaps = googlemaps.Client(key=google_maps_key) -def retrieve_location(): - "Returns latitude and longitude of current location" - latitude = 37.423304896346345 - longitude = -122.16023584591919 - - return latitude, longitude - -def reverse_geocode(latitude: float, longitude: float): - "Converts latitude and longitude into a readable address" - result = gmaps.reverse_geocode((latitude, longitude)) - if result: - address = result[0].get('formatted_address', 'No address found') - else: - address = 'No address found' - - return address - -def find_places(query: None, location = None, radius = None, language = None, min_price = None, max_price = None, open_now = False, place_type = None, region = None): - params = { - 'query': query, - 'location': location, - 'radius': radius, - 'language': language, - 'min_price': min_price, - 'max_price': max_price, - 'open_now': open_now, - 'type': place_type, - 'region': region - } - - params = {k: v for k, v in params.items() if v is not None} - response = gmaps.places(**params) - - results = response['results'][:5] # limit to top 5 results - - simplified_results = [] - for place in results: - place_info = { - 'place_id': place.get('place_id'), - 'name': place.get('name'), - 'location': (place['geometry']['location']['lat'], place['geometry']['location']['lng']), - 'formatted_address': place.get('formatted_address'), - 'rating': place.get('rating') + +def retrieve_location(): + "Returns latitude and longitude of current location" + latitude = 37.423304896346345 + longitude = -122.16023584591919 + + return latitude, longitude + + +def reverse_geocode(latitude: float, longitude: float): + "Converts latitude and longitude into a readable address" + result = gmaps.reverse_geocode((latitude, longitude)) + if result: + address = result[0].get("formatted_address", "No address found") + else: + address = "No address found" + + return address + + +def find_places( + query: None, + location=None, + radius=None, + language=None, + min_price=None, + max_price=None, + open_now=False, + place_type=None, + region=None, +): + params = { + "query": query, + "location": location, + "radius": radius, + "language": language, + "min_price": min_price, + "max_price": max_price, + "open_now": open_now, + "type": place_type, + "region": region, } - simplified_results.append(place_info) - - return simplified_results - -class FindPlacesArgs(BaseModel): - query: Optional[str] = Field(None, description = "Text string to search for, e.g., 'restaurant'") - location: Optional[Union[tuple, list, str]] = Field(None, description = "Latitude and longitude as a tuple or string") - radius: Optional[int] = Field(None, description = "Search radius in meters") - language: Optional[str] = Field(None, description = "The language in which to return results") - min_price: Optional[int] = Field(None, description = "Minimum price level of places to include, from 0 (most affordable) to 4 (most expensive)") - max_price: Optional[int] = Field(None, description = "Maximum price level of places to include, from 0 (most affordable) to 4 (most expensive)") - open_now: Optional[bool] = Field(False, description = "Return only those places that are open for business at the time the query is sent") - place_type: Optional[str] = Field(None, description = "Type of place to restrict results to") - region: Optional[str] = Field(None, description = "Region code to bias results towards") - + + params = {k: v for k, v in params.items() if v is not None} + response = gmaps.places(**params) + + results = response["results"][:5] # limit to top 5 results + + simplified_results = [] + for place in results: + place_info = { + "place_id": place.get("place_id"), + "name": place.get("name"), + "location": ( + place["geometry"]["location"]["lat"], + place["geometry"]["location"]["lng"], + ), + "formatted_address": place.get("formatted_address"), + "rating": place.get("rating"), + } + simplified_results.append(place_info) + + return simplified_results + + +class FindPlacesArgs(BaseModel): + query: Optional[str] = Field( + None, description="Text string to search for, e.g., 'restaurant'" + ) + location: Optional[Union[tuple, list, str]] = Field( + None, description="Latitude and longitude as a tuple or string" + ) + radius: Optional[int] = Field(None, description="Search radius in meters") + language: Optional[str] = Field( + None, description="The language in which to return results" + ) + min_price: Optional[int] = Field( + None, + description="Minimum price level of places to include, from 0 (most affordable) to 4 (most expensive)", + ) + max_price: Optional[int] = Field( + None, + description="Maximum price level of places to include, from 0 (most affordable) to 4 (most expensive)", + ) + open_now: Optional[bool] = Field( + False, + description="Return only those places that are open for business at the time the query is sent", + ) + place_type: Optional[str] = Field( + None, description="Type of place to restrict results to" + ) + region: Optional[str] = Field( + None, description="Region code to bias results towards" + ) + + find_places_tool = StructuredTool( - func = find_places, - name = "Find Places", - description = "Finds places based on location and other optional parameters. For each place, returns place ID, name, coordinates as a tuple, formatted address, and rating.", - args_schema = FindPlacesArgs + func=find_places, + name="Find Places", + description="Finds places based on location and other optional parameters. For each place, returns place ID, name, coordinates as a tuple, formatted address, and rating.", + args_schema=FindPlacesArgs, ) -def get_directions(origin, destination, mode="walking", waypoints=None, alternatives=False, avoid=None, language=None, units=None, region=None, departure_time=None, arrival_time=None, optimize_waypoints=False, transit_mode=None, transit_routing_preference=None, traffic_model=None): - params = { - 'origin': origin, - 'destination': destination, - 'mode': mode, - 'waypoints': waypoints, - 'alternatives': alternatives, - 'avoid': avoid, - 'language': language, - 'units': units, - 'region': region, - 'departure_time': departure_time, - 'arrival_time': arrival_time, - 'optimize_waypoints': optimize_waypoints, - 'transit_mode': transit_mode, - 'transit_routing_preference': transit_routing_preference, - 'traffic_model': traffic_model + +def get_directions( + origin, + destination, + mode="walking", + waypoints=None, + alternatives=False, + avoid=None, + language=None, + units=None, + region=None, + departure_time=None, + arrival_time=None, + optimize_waypoints=False, + transit_mode=None, + transit_routing_preference=None, + traffic_model=None, +): + params = { + "origin": origin, + "destination": destination, + "mode": mode, + "waypoints": waypoints, + "alternatives": alternatives, + "avoid": avoid, + "language": language, + "units": units, + "region": region, + "departure_time": departure_time, + "arrival_time": arrival_time, + "optimize_waypoints": optimize_waypoints, + "transit_mode": transit_mode, + "transit_routing_preference": transit_routing_preference, + "traffic_model": traffic_model, } - - # Remove None values - params = {k: v for k, v in params.items() if v is not None} - - # Make the API call - response = gmaps.directions(**params) - - return response + + # Remove None values + params = {k: v for k, v in params.items() if v is not None} + + # Make the API call + response = gmaps.directions(**params) + + return response + class DirectionsArgs(BaseModel): - origin: Union[str, Tuple[float, float]] = Field(..., description="The starting address or latitude/longitude value.") - destination: Union[str, Tuple[float, float]] = Field(..., description="The ending address or latitude/longitude value.") - mode: Optional[str] = Field("walking", description="Mode of transport (driving, walking, bicycling, or transit).") - waypoints: Optional[Union[List[Union[str, Tuple[float, float]]], str]] = Field(None, description="Array of waypoints to alter the route. To route through a location without stopping, prefix it with 'via:', e.g., ['via:San Francisco', 'via:Mountain View'].") - alternatives: bool = Field(False, description="If True, more than one route may be returned in the response.") - avoid: Optional[Union[str, List[str]]] = Field(None, description="Features to avoid (tolls, highways, ferries, etc.).") + origin: Union[str, Tuple[float, float]] = Field( + ..., description="The starting address or latitude/longitude value." + ) + destination: Union[str, Tuple[float, float]] = Field( + ..., description="The ending address or latitude/longitude value." + ) + mode: Optional[str] = Field( + "walking", + description="Mode of transport (driving, walking, bicycling, or transit).", + ) + waypoints: Optional[Union[List[Union[str, Tuple[float, float]]], str]] = Field( + None, + description="Array of waypoints to alter the route. To route through a location without stopping, prefix it with 'via:', e.g., ['via:San Francisco', 'via:Mountain View'].", + ) + alternatives: bool = Field( + False, + description="If True, more than one route may be returned in the response.", + ) + avoid: Optional[Union[str, List[str]]] = Field( + None, description="Features to avoid (tolls, highways, ferries, etc.)." + ) language: Optional[str] = Field(None, description="Language for the results.") - units: Optional[str] = Field(None, description="Unit system for the results (metric or imperial).") - region: Optional[str] = Field(None, description="Region code, specified as a ccTLD two-character value.") - departure_time: Optional[Union[int, datetime]] = Field(None, description="Desired time of departure as a timestamp or datetime.") - arrival_time: Optional[Union[int, datetime]] = Field(None, description="Desired time of arrival as a timestamp or datetime.") - optimize_waypoints: bool = Field(False, description="Whether to optimize the order of waypoints.") - transit_mode: Optional[Union[str, List[str]]] = Field(None, description="Preferred modes of transit (bus, subway, train, etc.).") - transit_routing_preference: Optional[str] = Field(None, description="Preferences for transit routing (less_walking or fewer_transfers).") - traffic_model: Optional[str] = Field(None, description="Predictive travel time model (best_guess, optimistic, pessimistic).") - -def main(): - tools = [] - tools.append(StructuredTool.from_function(retrieve_location)) - tools.append(StructuredTool.from_function(reverse_geocode)) - tools.append(find_places_tool) - - # TODO: - # Missing: place (implement?) - # Missing: find_place (implement?) - # Missing: directions - # Missing: distance_matrix - # Missing: vision - # Missing: audio - - # llm = ChatOpenAI(model="gpt-4") - # agent_chain = initialize_agent(tools, llm, agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True) - # agent_chain.invoke( - # { - # "input": "Is there a cafe near me?" - # } - # ) - - latitude = 37.423304896346345 - longitude = -122.16023584591919 - - response = get_directions(origin=(latitude, longitude), destination="Coupa Cafe Green Library Stanford") - # print(response[0]['legs'][0]) # 'legs' because walking was specified? - # print(response[0]['legs'][0].keys()) # keys = distance, duration, end_address, end_location, start_address, start_location, steps, traffic_speed_entry, via_waypoint - # print(response[0]['legs'][0]['steps'][0].keys()) # keys = distance, duration, end_location, html_instructions, polyline, start_location, travel_mode - - # TODO: - # places() - # Only certain 'type' can be accepted. Prompt agent. - # Only certain 'regions' can be accepted. - - - -if __name__ == "__main__": - main() - # Important GMaps documentation: https://googlemaps.github.io/google-maps-services-python/docs/index.html#googlemaps.Client.places - - - - + units: Optional[str] = Field( + None, description="Unit system for the results (metric or imperial)." + ) + region: Optional[str] = Field( + None, description="Region code, specified as a ccTLD two-character value." + ) + departure_time: Optional[Union[int, datetime]] = Field( + None, description="Desired time of departure as a timestamp or datetime." + ) + arrival_time: Optional[Union[int, datetime]] = Field( + None, description="Desired time of arrival as a timestamp or datetime." + ) + optimize_waypoints: bool = Field( + False, description="Whether to optimize the order of waypoints." + ) + transit_mode: Optional[Union[str, List[str]]] = Field( + None, description="Preferred modes of transit (bus, subway, train, etc.)." + ) + transit_routing_preference: Optional[str] = Field( + None, + description="Preferences for transit routing (less_walking or fewer_transfers).", + ) + traffic_model: Optional[str] = Field( + None, + description="Predictive travel time model (best_guess, optimistic, pessimistic).", + ) + + +def main(): + tools = [] + tools.append(StructuredTool.from_function(retrieve_location)) + tools.append(StructuredTool.from_function(reverse_geocode)) + tools.append(find_places_tool) + + # TODO: + # Missing: place (implement?) + # Missing: find_place (implement?) + # Missing: directions + # Missing: distance_matrix + # Missing: vision + # Missing: audio + + # llm = ChatOpenAI(model="gpt-4") + # agent_chain = initialize_agent(tools, llm, agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True) + # agent_chain.invoke( + # { + # "input": "Is there a cafe near me?" + # } + # ) + + latitude = 37.423304896346345 + longitude = -122.16023584591919 + + response = get_directions( + origin=(latitude, longitude), destination="Coupa Cafe Green Library Stanford" + ) + print("Directions response:", response) + # print(response[0]['legs'][0]) # 'legs' because walking was specified? + # print(response[0]['legs'][0].keys()) # keys = distance, duration, end_address, end_location, start_address, start_location, steps, traffic_speed_entry, via_waypoint + # print(response[0]['legs'][0]['steps'][0].keys()) # keys = distance, duration, end_location, html_instructions, polyline, start_location, travel_mode + + # TODO: + # places() + # Only certain 'type' can be accepted. Prompt agent. + # Only certain 'regions' can be accepted. + +if __name__ == "__main__": + main() + # Important GMaps documentation: https://googlemaps.github.io/google-maps-services-python/docs/index.html#googlemaps.Client.places diff --git a/dev/query_decomposition/MS-SQ.ipynb b/dev/query_decomposition/MS-SQ.ipynb index b6970d8a..44799b89 100644 --- a/dev/query_decomposition/MS-SQ.ipynb +++ b/dev/query_decomposition/MS-SQ.ipynb @@ -128,9 +128,7 @@ "step_decompose_transform = StepDecomposeQueryTransform(llm=gpt4, verbose=True)\n", "\n", "# gpt-3\n", - "step_decompose_transform_gpt3 = StepDecomposeQueryTransform(\n", - " llm=gpt35, verbose=True\n", - ")" + "step_decompose_transform_gpt3 = StepDecomposeQueryTransform(llm=gpt35, verbose=True)" ] }, { @@ -160,7 +158,7 @@ " index_summary=index_summary,\n", ")\n", "response_gpt4 = query_engine.query(\n", - " \"What is the article about?\", \n", + " \"What is the article about?\",\n", ")" ] }, @@ -220,8 +218,8 @@ "outputs": [], "source": [ "response = query_engine.query(\n", - " # instead of this, use extracted query \n", - " #To Do: reference newest query here \n", + " # instead of this, use extracted query\n", + " # To Do: reference newest query here\n", " \"What is the specific topic of this article by Paul Graham?\"\n", ")" ] @@ -271,8 +269,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.8" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/query_decomposition/MS_finetuning.ipynb b/dev/query_decomposition/MS_finetuning.ipynb index 7cd08df6..e021d7aa 100644 --- a/dev/query_decomposition/MS_finetuning.ipynb +++ b/dev/query_decomposition/MS_finetuning.ipynb @@ -37,9 +37,7 @@ "step_decompose_transform = StepDecomposeQueryTransform(llm=llm_4, verbose=True)\n", "\n", "# gpt-3\n", - "step_decompose_transform_gpt3 = StepDecomposeQueryTransform(\n", - " llm=llm_35, verbose=True\n", - ")" + "step_decompose_transform_gpt3 = StepDecomposeQueryTransform(llm=llm_35, verbose=True)" ] }, { @@ -58,7 +56,9 @@ "metadata": {}, "outputs": [], "source": [ - "index_summary = \"Used to answer questions about the teacher, the students, and the classroom\"" + "index_summary = (\n", + " \"Used to answer questions about the teacher, the students, and the classroom\"\n", + ")" ] }, { @@ -77,7 +77,7 @@ "\n", "from llama_index.core import Settings\n", "\n", - "# limit the context window artifically to test refine process\n", + "# limit the context window artificially to test refine process\n", "Settings.context_window = 2048" ] }, @@ -110,8 +110,8 @@ "source": [ "import json\n", "\n", - "file_path = './query-decomposition/cv_loc_enhanced_questions.json'\n", - "with open(file_path, 'r') as file_loc:\n", + "file_path = \"./query-decomposition/cv_loc_enhanced_questions.json\"\n", + "with open(file_path, \"r\") as file_loc:\n", " data = json.load(file_loc)\n", "\n", "new_questions = data" @@ -127,7 +127,8 @@ " with open(path, \"w\") as f:\n", " for question in questions:\n", " f.write(question + \"\\n\")\n", - " \n", + "\n", + "\n", "def load_questions(path):\n", " questions = []\n", " with open(path, \"r\") as f:\n", @@ -172,7 +173,6 @@ "metadata": {}, "outputs": [], "source": [ - "\n", "query_engine_tools = [\n", " QueryEngineTool(\n", " query_engine=query_engine,\n", @@ -240,7 +240,7 @@ "metadata": {}, "outputs": [], "source": [ - "for response in responses: \n", + "for response in responses:\n", " sub_qa = response.metadata[\"sub_qa\"]\n", " tuples = [(t[0], t[1]) for t in sub_qa]\n", " if len(tuples) > 0:\n", @@ -269,7 +269,7 @@ "finetune_engine = OpenAIFinetuneEngine(\n", " \"gpt-3.5-turbo\",\n", " \"finetuning_events_10q.jsonl\",\n", - " #start_job_id=\"\" # if you have an existing job, can specify id here\n", + " # start_job_id=\"\" # if you have an existing job, can specify id here\n", ")" ] }, @@ -307,8 +307,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/query_decomposition/SQ-MS.ipynb b/dev/query_decomposition/SQ-MS.ipynb index ccdcaf8d..f962c9ca 100644 --- a/dev/query_decomposition/SQ-MS.ipynb +++ b/dev/query_decomposition/SQ-MS.ipynb @@ -29,6 +29,7 @@ "os.environ[\"OPENAI_API_KEY\"] = \"sk-\"\n", "\n", "import nest_asyncio\n", + "\n", "nest_asyncio.apply()" ] }, @@ -38,14 +39,14 @@ "metadata": {}, "outputs": [], "source": [ - "#copied imports from llama-index example for subquestion\n", + "# copied imports from llama-index example for subquestion\n", "from llama_index.core import VectorStoreIndex, SimpleDirectoryReader\n", "from llama_index.core.tools import QueryEngineTool, ToolMetadata\n", "from llama_index.core.query_engine import SubQuestionQueryEngine\n", "from llama_index.core.callbacks import CallbackManager, LlamaDebugHandler\n", "from llama_index.core import Settings\n", "\n", - "#copied imports from llama-index example for multistep\n", + "# copied imports from llama-index example for multistep\n", "from llama_index.llms.openai import OpenAI\n", "from IPython.display import Markdown, display" ] @@ -73,15 +74,15 @@ "from llama_index.core import SimpleDirectoryReader\n", "import urllib.request\n", "\n", - "os.makedirs('data/paul_graham/', exist_ok=True)\n", + "os.makedirs(\"data/paul_graham/\", exist_ok=True)\n", "\n", "# Download the file\n", - "url = 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt'\n", - "file_path = 'data/paul_graham/paul_graham_essay.txt'\n", + "url = \"https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt\"\n", + "file_path = \"data/paul_graham/paul_graham_essay.txt\"\n", "urllib.request.urlretrieve(url, file_path)\n", "\n", "# load documents\n", - "pg_essay = SimpleDirectoryReader(\"./data/paul_graham/\").load_data()\n" + "pg_essay = SimpleDirectoryReader(\"./data/paul_graham/\").load_data()" ] }, { @@ -149,11 +150,11 @@ "metadata": {}, "outputs": [], "source": [ - "llama_debug.flush_event_logs() #flush for easier retrieval of subquestions\n", + "llama_debug.flush_event_logs() # flush for easier retrieval of subquestions\n", "\n", "response = query_engine.query(\n", " \"Summarize the essay, and discuss the authors life before and after the essay was written.\"\n", - ") #todo: figure out how to stop it from printing responses" + ") # todo: figure out how to stop it from printing responses" ] }, { @@ -175,12 +176,10 @@ " # smth wrong\n", " continue\n", "\n", - " new_q = sub_q_object[start_index+14:end_index-1]\n", + " new_q = sub_q_object[start_index + 14 : end_index - 1]\n", " sub_questions.append(new_q)\n", "\n", - "# probably a better way to do this than to substring\n", - "\n", - " " + "# probably a better way to do this than to substring" ] }, { @@ -223,13 +222,6 @@ " response = multi_query_engine.query(sub_q)\n", " # print(response)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -247,8 +239,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.8" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/query_decomposition/langchain_ms.ipynb b/dev/query_decomposition/langchain_ms.ipynb index 28810298..876b9dc9 100644 --- a/dev/query_decomposition/langchain_ms.ipynb +++ b/dev/query_decomposition/langchain_ms.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -85,7 +85,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -94,7 +94,7 @@ "[SubQuery(sub_query='How to do rag')]" ] }, - "execution_count": 3, + "execution_count": null, "metadata": {}, "output_type": "execute_result" } @@ -105,7 +105,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -115,7 +115,7 @@ " SubQuery(sub_query='How to turn a chain into a REST API')]" ] }, - "execution_count": 4, + "execution_count": null, "metadata": {}, "output_type": "execute_result" } @@ -130,7 +130,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -145,7 +145,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -158,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -173,7 +173,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -188,7 +188,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -210,7 +210,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -256,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -283,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -293,7 +293,7 @@ " SubQuery(sub_query='Do Web Voyager and Reflection Agents use LangGraph?')]" ] }, - "execution_count": 12, + "execution_count": null, "metadata": {}, "output_type": "execute_result" } @@ -305,13 +305,6 @@ " }\n", ")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -329,8 +322,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/query_decomposition/routing_and_multistep.ipynb b/dev/query_decomposition/routing_and_multistep.ipynb index 07c51779..a345b91c 100644 --- a/dev/query_decomposition/routing_and_multistep.ipynb +++ b/dev/query_decomposition/routing_and_multistep.ipynb @@ -1,467 +1,368 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "5e0768d5", - "metadata": { - "id": "5e0768d5" - }, - "source": [ - "\"Open" - ] - }, - { - "cell_type": "markdown", - "id": "9c48213d-6e6a-4c10-838a-2a7c710c3a05", - "metadata": { - "id": "9c48213d-6e6a-4c10-838a-2a7c710c3a05" - }, - "source": [ - "# Multi-Step Query Engine\n", - "\n", - "We have a multi-step query engine that's able to decompose a complex query into sequential subquestions. This\n", - "guide walks you through how to set it up!" - ] - }, - { - "cell_type": "markdown", - "id": "cc77f986", - "metadata": { - "id": "cc77f986" - }, - "source": [ - "If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "20a71098", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "20a71098", - "outputId": "e001a673-d277-4839-bdec-d3433f035956" - }, - "outputs": [], - "source": [ - "%pip install llama-index-llms-openai\n", - "%pip install llama-index-agent-openai\n", - "!pip install llama-index" - ] - }, - { - "cell_type": "markdown", - "id": "c5885d63", - "metadata": { - "id": "c5885d63" - }, - "source": [ - "#### Download Data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ee4ace96", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "ee4ace96", - "outputId": "0963ba23-3afc-419f-f148-f22630d18cbf" - }, - "outputs": [], - "source": [ - "!mkdir -p 'data/paul_graham/'\n", - "!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'" - ] - }, - { - "cell_type": "markdown", - "id": "50d3b817-b70e-4667-be4f-d3a0fe4bd119", - "metadata": { - "id": "50d3b817-b70e-4667-be4f-d3a0fe4bd119" - }, - "source": [ - "#### Load documents, build the VectorStoreIndex" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "65ebfca2", - "metadata": { - "id": "65ebfca2" - }, - "outputs": [], - "source": [ - "import os\n", - "\n", - "os.environ[\"OPENAI_API_KEY\"] = \"sk-...\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "690a6918-7c75-4f95-9ccc-d2c4a1fe00d7", - "metadata": { - "id": "690a6918-7c75-4f95-9ccc-d2c4a1fe00d7" - }, - "outputs": [], - "source": [ - "from llama_index.core import VectorStoreIndex, SimpleDirectoryReader\n", - "from llama_index.llms.openai import OpenAI\n", - "from IPython.display import Markdown, display" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c48da73f-aadb-480c-8db1-99c915b7cc1c", - "metadata": { - "id": "c48da73f-aadb-480c-8db1-99c915b7cc1c" - }, - "outputs": [], - "source": [ - "# LLM (gpt-3.5)\n", - "gpt35 = OpenAI(temperature=0, model=\"gpt-3.5-turbo\")\n", - "\n", - "# LLM (gpt-4)\n", - "gpt4 = OpenAI(temperature=0, model=\"gpt-4\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "03d1691e-544b-454f-825b-5ee12f7faa8a", - "metadata": { - "id": "03d1691e-544b-454f-825b-5ee12f7faa8a" - }, - "outputs": [], - "source": [ - "# load documents\n", - "documents = SimpleDirectoryReader(\"./data/paul_graham/\").load_data()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ad144ee7-96da-4dd6-be00-fd6cf0c78e58", - "metadata": { - "id": "ad144ee7-96da-4dd6-be00-fd6cf0c78e58" - }, - "outputs": [], - "source": [ - "index = VectorStoreIndex.from_documents(documents)" - ] - }, - { - "cell_type": "markdown", - "id": "b6caf93b-6345-4c65-a346-a95b0f1746c4", - "metadata": { - "id": "b6caf93b-6345-4c65-a346-a95b0f1746c4" - }, - "source": [ - "#### Query Index" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "95d989ba-0c1d-43b6-a1d3-0ea7135f43a6", - "metadata": { - "id": "95d989ba-0c1d-43b6-a1d3-0ea7135f43a6" - }, - "outputs": [], - "source": [ - "from llama_index.core.indices.query.query_transform.base import (\n", - " StepDecomposeQueryTransform,\n", - ")\n", - "\n", - "# gpt-4\n", - "step_decompose_transform = StepDecomposeQueryTransform(llm=gpt4, verbose=True)\n", - "\n", - "# gpt-3\n", - "step_decompose_transform_gpt3 = StepDecomposeQueryTransform(\n", - " llm=gpt35, verbose=True\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2a124db0-e2d7-4566-bcec-1d41cf669ff4", - "metadata": { - "id": "2a124db0-e2d7-4566-bcec-1d41cf669ff4" - }, - "outputs": [], - "source": [ - "index_summary = \"Used to answer questions about the author\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "85466fdf-93f3-4cb1-a5f9-0056a8245a6f", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "85466fdf-93f3-4cb1-a5f9-0056a8245a6f", - "outputId": "1745877d-95f3-4266-a8e0-118ae21b09eb" - }, - "outputs": [], - "source": [ - "# set Logging to DEBUG for more detailed outputs\n", - "from llama_index.core.query_engine import MultiStepQueryEngine\n", - "\n", - "query_engine = index.as_query_engine(llm=gpt4)\n", - "query_engine = MultiStepQueryEngine(\n", - " query_engine=query_engine,\n", - " query_transform=step_decompose_transform,\n", - " index_summary=index_summary,\n", - ")\n", - "response_gpt4 = query_engine.query(\n", - " \"Who was in the first batch of the accelerator program the author\"\n", - " \" started?\",\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7MeeUrf1xQcl", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "7MeeUrf1xQcl", - "outputId": "98ba7f16-ddf7-4aa2-d7f1-58f14e3e1783" - }, - "outputs": [], - "source": [ - "sub_qa = response_gpt4.metadata[\"sub_qa\"]\n", - "tuples = [(t[0], t[1].response) for t in sub_qa]\n", - "print(tuples)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "sA96XR4qxtYh", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "sA96XR4qxtYh", - "outputId": "1763d5cf-f53e-4dfc-e761-ac392b7bcb9e" - }, - "outputs": [], - "source": [ - "latest_tuple = tuples[-1]\n", - "latest_query = latest_tuple[0]\n", - "print(latest_query)" - ] - }, - { - "cell_type": "markdown", - "id": "iRiYf_rJy5Vb", - "metadata": { - "id": "iRiYf_rJy5Vb" - }, - "source": [ - "New Technique" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "X2-aHSfByGyw", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "X2-aHSfByGyw", - "outputId": "0b597cfc-7fe3-4270-8f44-1a36bf2fa527" - }, - "outputs": [], - "source": [ - "%load_ext autoreload\n", - "%autoreload 2" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "NCsUXEuqyI2S", - "metadata": { - "id": "NCsUXEuqyI2S" - }, - "outputs": [], - "source": [ - "from llama_index.core import SimpleDirectoryReader, VectorStoreIndex\n", - "from llama_index.core.response.pprint_utils import pprint_response\n", - "from llama_index.llms.openai import OpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "MdBfe2CEyKl-", - "metadata": { - "id": "MdBfe2CEyKl-" - }, - "outputs": [], - "source": [ - "llm = OpenAI(temperature=0, model=\"gpt-4\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ff_byYewyL5K", - "metadata": { - "id": "ff_byYewyL5K" - }, - "outputs": [], - "source": [ - "engine = index.as_query_engine(similarity_top_k=3, llm=llm)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "kwjUemE5yTVB", - "metadata": { - "id": "kwjUemE5yTVB" - }, - "outputs": [], - "source": [ - "from llama_index.core.tools import QueryEngineTool\n", - "\n", - "\n", - "query_tool_pg = QueryEngineTool.from_defaults(\n", - " query_engine=engine,\n", - " name=\"files\",\n", - " description=(\n", - " f\"Paul graham essay\"\n", - " ),\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "EZi7FVbwydNQ", - "metadata": { - "id": "EZi7FVbwydNQ" - }, - "outputs": [], - "source": [ - "# define query plan tool\n", - "from llama_index.core.tools import QueryPlanTool\n", - "from llama_index.core import get_response_synthesizer\n", - "\n", - "response_synthesizer = get_response_synthesizer()\n", - "query_plan_tool = QueryPlanTool.from_defaults(\n", - " query_engine_tools=[query_tool_pg],\n", - " response_synthesizer=response_synthesizer,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "DV9tC4DQyexP", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "DV9tC4DQyexP", - "outputId": "a72383bc-af3d-43da-eed1-9eaf746dd872" - }, - "outputs": [], - "source": [ - "query_plan_tool.metadata.to_openai_tool() # to_openai_function() deprecated" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "MPEwUMaAygE-", - "metadata": { - "id": "MPEwUMaAygE-" - }, - "outputs": [], - "source": [ - "from llama_index.agent.openai import OpenAIAgent\n", - "from llama_index.llms.openai import OpenAI\n", - "\n", - "\n", - "agent = OpenAIAgent.from_tools(\n", - " [query_plan_tool],\n", - " max_function_calls=10,\n", - " llm=OpenAI(temperature=0, model=\"gpt-4-0613\"),\n", - " verbose=True,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "HGEzQEupyh9a", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "HGEzQEupyh9a", - "outputId": "00f83ff8-68b2-4c22-f683-1e2da834c26f" - }, - "outputs": [], - "source": [ - "response = agent.query(latest_query)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "-IOyxIjpymvH", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "-IOyxIjpymvH", - "outputId": "ca25e7a5-8488-4469-c1a0-7f5a32a2ae53" - }, - "outputs": [], - "source": [ - "print(str(response))" - ] - } - ], - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "display_name": "llama", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3" - } + "cells": [ + { + "cell_type": "markdown", + "id": "5e0768d5", + "metadata": {}, + "source": [ + "\"Open" + ] }, - "nbformat": 4, - "nbformat_minor": 5 + { + "cell_type": "markdown", + "id": "9c48213d-6e6a-4c10-838a-2a7c710c3a05", + "metadata": {}, + "source": [ + "# Multi-Step Query Engine\n", + "\n", + "We have a multi-step query engine that's able to decompose a complex query into sequential subquestions. This\n", + "guide walks you through how to set it up!" + ] + }, + { + "cell_type": "markdown", + "id": "cc77f986", + "metadata": {}, + "source": [ + "If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "20a71098", + "metadata": {}, + "outputs": [], + "source": [ + "%pip install llama-index-llms-openai\n", + "%pip install llama-index-agent-openai\n", + "!pip install llama-index" + ] + }, + { + "cell_type": "markdown", + "id": "c5885d63", + "metadata": {}, + "source": [ + "#### Download Data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee4ace96", + "metadata": {}, + "outputs": [], + "source": [ + "!mkdir -p 'data/paul_graham/'\n", + "!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'" + ] + }, + { + "cell_type": "markdown", + "id": "50d3b817-b70e-4667-be4f-d3a0fe4bd119", + "metadata": {}, + "source": [ + "#### Load documents, build the VectorStoreIndex" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "65ebfca2", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "os.environ[\"OPENAI_API_KEY\"] = \"sk-...\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "690a6918-7c75-4f95-9ccc-d2c4a1fe00d7", + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.core import VectorStoreIndex, SimpleDirectoryReader\n", + "from llama_index.llms.openai import OpenAI\n", + "from IPython.display import Markdown, display" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c48da73f-aadb-480c-8db1-99c915b7cc1c", + "metadata": {}, + "outputs": [], + "source": [ + "# LLM (gpt-3.5)\n", + "gpt35 = OpenAI(temperature=0, model=\"gpt-3.5-turbo\")\n", + "\n", + "# LLM (gpt-4)\n", + "gpt4 = OpenAI(temperature=0, model=\"gpt-4\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "03d1691e-544b-454f-825b-5ee12f7faa8a", + "metadata": {}, + "outputs": [], + "source": [ + "# load documents\n", + "documents = SimpleDirectoryReader(\"./data/paul_graham/\").load_data()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ad144ee7-96da-4dd6-be00-fd6cf0c78e58", + "metadata": {}, + "outputs": [], + "source": [ + "index = VectorStoreIndex.from_documents(documents)" + ] + }, + { + "cell_type": "markdown", + "id": "b6caf93b-6345-4c65-a346-a95b0f1746c4", + "metadata": {}, + "source": [ + "#### Query Index" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "95d989ba-0c1d-43b6-a1d3-0ea7135f43a6", + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.core.indices.query.query_transform.base import (\n", + " StepDecomposeQueryTransform,\n", + ")\n", + "\n", + "# gpt-4\n", + "step_decompose_transform = StepDecomposeQueryTransform(llm=gpt4, verbose=True)\n", + "\n", + "# gpt-3\n", + "step_decompose_transform_gpt3 = StepDecomposeQueryTransform(llm=gpt35, verbose=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2a124db0-e2d7-4566-bcec-1d41cf669ff4", + "metadata": {}, + "outputs": [], + "source": [ + "index_summary = \"Used to answer questions about the author\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "85466fdf-93f3-4cb1-a5f9-0056a8245a6f", + "metadata": {}, + "outputs": [], + "source": [ + "# set Logging to DEBUG for more detailed outputs\n", + "from llama_index.core.query_engine import MultiStepQueryEngine\n", + "\n", + "query_engine = index.as_query_engine(llm=gpt4)\n", + "query_engine = MultiStepQueryEngine(\n", + " query_engine=query_engine,\n", + " query_transform=step_decompose_transform,\n", + " index_summary=index_summary,\n", + ")\n", + "response_gpt4 = query_engine.query(\n", + " \"Who was in the first batch of the accelerator program the author\" \" started?\",\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7MeeUrf1xQcl", + "metadata": {}, + "outputs": [], + "source": [ + "sub_qa = response_gpt4.metadata[\"sub_qa\"]\n", + "tuples = [(t[0], t[1].response) for t in sub_qa]\n", + "print(tuples)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "sA96XR4qxtYh", + "metadata": {}, + "outputs": [], + "source": [ + "latest_tuple = tuples[-1]\n", + "latest_query = latest_tuple[0]\n", + "print(latest_query)" + ] + }, + { + "cell_type": "markdown", + "id": "iRiYf_rJy5Vb", + "metadata": {}, + "source": [ + "New Technique" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "X2-aHSfByGyw", + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "NCsUXEuqyI2S", + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.core import SimpleDirectoryReader, VectorStoreIndex\n", + "from llama_index.core.response.pprint_utils import pprint_response\n", + "from llama_index.llms.openai import OpenAI" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "MdBfe2CEyKl-", + "metadata": {}, + "outputs": [], + "source": [ + "llm = OpenAI(temperature=0, model=\"gpt-4\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ff_byYewyL5K", + "metadata": {}, + "outputs": [], + "source": [ + "engine = index.as_query_engine(similarity_top_k=3, llm=llm)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "kwjUemE5yTVB", + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.core.tools import QueryEngineTool\n", + "\n", + "\n", + "query_tool_pg = QueryEngineTool.from_defaults(\n", + " query_engine=engine,\n", + " name=\"files\",\n", + " description=(f\"Paul graham essay\"),\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "EZi7FVbwydNQ", + "metadata": {}, + "outputs": [], + "source": [ + "# define query plan tool\n", + "from llama_index.core.tools import QueryPlanTool\n", + "from llama_index.core import get_response_synthesizer\n", + "\n", + "response_synthesizer = get_response_synthesizer()\n", + "query_plan_tool = QueryPlanTool.from_defaults(\n", + " query_engine_tools=[query_tool_pg],\n", + " response_synthesizer=response_synthesizer,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "DV9tC4DQyexP", + "metadata": {}, + "outputs": [], + "source": [ + "query_plan_tool.metadata.to_openai_tool() # to_openai_function() deprecated" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "MPEwUMaAygE-", + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.agent.openai import OpenAIAgent\n", + "from llama_index.llms.openai import OpenAI\n", + "\n", + "\n", + "agent = OpenAIAgent.from_tools(\n", + " [query_plan_tool],\n", + " max_function_calls=10,\n", + " llm=OpenAI(temperature=0, model=\"gpt-4-0613\"),\n", + " verbose=True,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "HGEzQEupyh9a", + "metadata": {}, + "outputs": [], + "source": [ + "response = agent.query(latest_query)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "-IOyxIjpymvH", + "metadata": {}, + "outputs": [], + "source": [ + "print(str(response))" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "llama", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 } diff --git a/dev/recursive_retrieval/benchmarking/benchmark.py b/dev/recursive_retrieval/benchmarking/benchmark.py index 5d4338d0..4561367f 100644 --- a/dev/recursive_retrieval/benchmarking/benchmark.py +++ b/dev/recursive_retrieval/benchmarking/benchmark.py @@ -1,11 +1,9 @@ import os -from collections import defaultdict from typing import List from dotenv import load_dotenv from llama_index.core.llms import ChatMessage from llama_index.llms.perplexity import Perplexity -from pandas import DataFrame from judge import custom_response_evaluator diff --git a/dev/recursive_retrieval/benchmarking/judge.py b/dev/recursive_retrieval/benchmarking/judge.py index dcda7155..d9c15a01 100644 --- a/dev/recursive_retrieval/benchmarking/judge.py +++ b/dev/recursive_retrieval/benchmarking/judge.py @@ -15,7 +15,7 @@ def custom_response_evaluator(query: str, response: str) -> Dict[str, int]: parser = JsonOutputParser(pydantic_object=Output) template = """ - You are an expert response judger. Score the provided respose a score from 0 to 1000 with 0 being the worst and 1000 being the best. + You are an expert response judger. Score the provided response a score from 0 to 1000 with 0 being the worst and 1000 being the best. Give separate scores for conciseness, informativeness and accuracy. For conciceness, focus on how succinct the response is and how clearly the information is conveyed using minimal words. For informativeness, focus on how comprehensive and relevant the contents of the response is to the given query. @@ -27,9 +27,9 @@ def custom_response_evaluator(query: str, response: str) -> Dict[str, int]: The Harry Potter books have been massively popular, spawning a highly successful film series that ran from 2001 to 2011, as well as a play, video games, theme park attractions, and a vast amount of fan fiction. The series is considered a landmark of 20th and 21st century children's literature. In summary, Harry Potter is a beloved fantasy series that has had a tremendous cultural impact through its books, films, and expanded universe. - + The judge should give a score of 300 for conciseness, 600 to informativeness, 900 for accuracy. - + Format: {format_instructions} Query: {query} diff --git a/dev/recursive_retrieval/benchmarking/ollama_quality.ipynb b/dev/recursive_retrieval/benchmarking/ollama_quality.ipynb index bdfb08f3..6bce4650 100644 --- a/dev/recursive_retrieval/benchmarking/ollama_quality.ipynb +++ b/dev/recursive_retrieval/benchmarking/ollama_quality.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -69,8 +69,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/recursive_retrieval/benchmarking/ollama_test.ipynb b/dev/recursive_retrieval/benchmarking/ollama_test.ipynb index 8cb085b2..73c51eef 100644 --- a/dev/recursive_retrieval/benchmarking/ollama_test.ipynb +++ b/dev/recursive_retrieval/benchmarking/ollama_test.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -47,8 +47,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/recursive_retrieval/benchmarking/perplexity_quality.ipynb b/dev/recursive_retrieval/benchmarking/perplexity_quality.ipynb index 8f8f5de7..5afc91f8 100644 --- a/dev/recursive_retrieval/benchmarking/perplexity_quality.ipynb +++ b/dev/recursive_retrieval/benchmarking/perplexity_quality.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -14,14 +14,12 @@ "\n", "pplx_api_key = os.getenv(\"PERPLEXITY_API_KEY\")\n", "\n", - "llm = Perplexity(\n", - " api_key=pplx_api_key, model=\"mistral-7b-instruct\", temperature=0.5\n", - ")" + "llm = Perplexity(api_key=pplx_api_key, model=\"mistral-7b-instruct\", temperature=0.5)" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -47,7 +45,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -59,9 +57,7 @@ } ], "source": [ - "llm = Perplexity(\n", - " api_key=pplx_api_key, model=\"mixtral-8x7b-instruct\", temperature=0.5\n", - ")\n", + "llm = Perplexity(api_key=pplx_api_key, model=\"mixtral-8x7b-instruct\", temperature=0.5)\n", "messages_dict = [\n", " {\"role\": \"system\", \"content\": \"Be precise and concise.\"},\n", " {\"role\": \"user\", \"content\": \"tell me about harry potter\"},\n", @@ -74,7 +70,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -86,9 +82,7 @@ } ], "source": [ - "llm = Perplexity(\n", - " api_key=pplx_api_key, model=\"sonar-small-chat\", temperature=0.5\n", - ")\n", + "llm = Perplexity(api_key=pplx_api_key, model=\"sonar-small-chat\", temperature=0.5)\n", "messages_dict = [\n", " {\"role\": \"system\", \"content\": \"Be precise and concise.\"},\n", " {\"role\": \"user\", \"content\": \"tell me about harry potter\"},\n", @@ -115,8 +109,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/recursive_retrieval/benchmarking/perplexity_test.ipynb b/dev/recursive_retrieval/benchmarking/perplexity_test.ipynb index b1df100a..5929b01d 100644 --- a/dev/recursive_retrieval/benchmarking/perplexity_test.ipynb +++ b/dev/recursive_retrieval/benchmarking/perplexity_test.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -14,14 +14,12 @@ "\n", "pplx_api_key = os.getenv(\"PERPLEXITY_API_KEY\")\n", "\n", - "llm = Perplexity(\n", - " api_key=pplx_api_key, model=\"mistral-7b-instruct\", temperature=0.5\n", - ")" + "llm = Perplexity(api_key=pplx_api_key, model=\"mistral-7b-instruct\", temperature=0.5)" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -47,18 +45,16 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "llm = Perplexity(\n", - " api_key=pplx_api_key, model=\"mixtral-8x7b-instruct\", temperature=0.5\n", - ")" + "llm = Perplexity(api_key=pplx_api_key, model=\"mixtral-8x7b-instruct\", temperature=0.5)" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -84,18 +80,16 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "llm = Perplexity(\n", - " api_key=pplx_api_key, model=\"sonar-small-chat\", temperature=0.5\n", - ")" + "llm = Perplexity(api_key=pplx_api_key, model=\"sonar-small-chat\", temperature=0.5)" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -135,8 +129,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/recursive_retrieval/data/external_response.txt b/dev/recursive_retrieval/data/external_response.txt index 89575fbb..c48ef2cc 100644 --- a/dev/recursive_retrieval/data/external_response.txt +++ b/dev/recursive_retrieval/data/external_response.txt @@ -520,4 +520,4 @@ bottles, nor that he would spend the next few weeks being prodded and pinched by his cousin Dudley... He couldn't know that at this very moment, people meeting in secret all over the country were holding up their glasses and saying in hushed voices: "To Harry Potter -- the boy -who lived!" \ No newline at end of file +who lived!" diff --git a/dev/recursive_retrieval/docs/cypher.md b/dev/recursive_retrieval/docs/cypher.md index 011b0b38..addb018c 100644 --- a/dev/recursive_retrieval/docs/cypher.md +++ b/dev/recursive_retrieval/docs/cypher.md @@ -1,13 +1,13 @@ # Recursive Retrieval Cyphers ## Getting Subraph Based on Entity ID + MATCH p = (:Entity { id: "Harry" })-[*]->() RETURN p; -- the `*` means traversing all paths -- adding a number, `x`, after `*` means a max hop distance of only that many nodes +- the `*` means traversing all paths +- adding a number, `x`, after `*` means a max hop distance of only that many nodes - can search labels by replacing `Entity` with labels - `->` can be replaced with `<-` for incoming children or `-` for both outgoing and incoming children - drawing diff --git a/dev/recursive_retrieval/docs/implementation.md b/dev/recursive_retrieval/docs/implementation.md index 11b6a456..ae5a4508 100644 --- a/dev/recursive_retrieval/docs/implementation.md +++ b/dev/recursive_retrieval/docs/implementation.md @@ -1,6 +1,8 @@ # Current Implementation of Recursive Retrieval + ## Graph Rag + NL2GraphQuery + - Graph RAG extracts subgraph related to key entities in question - NL2GraphQuery generates graph cypher based on query and schema - Note: Cypher not showing up in metadata right now -- Combination of these two contexts → LLM generates answer with all of this invovled \ No newline at end of file +- Combination of these two contexts → LLM generates answer with all of this involved diff --git a/dev/recursive_retrieval/docs/updates.md b/dev/recursive_retrieval/docs/updates.md index 51408d5c..44881307 100644 --- a/dev/recursive_retrieval/docs/updates.md +++ b/dev/recursive_retrieval/docs/updates.md @@ -1,5 +1,7 @@ # Recursive Retrieval Updates + ## Update 4/6/24 + - LLM "Judge" - analyze quality of perplexity models (sonar-small-online, mistral, mixtral) on conciseness, informativeness, and accuracy - potential improvements should focus on quality of the prompt fed into GPT3.5 (or use GPT4) @@ -7,6 +9,7 @@ - Incorporate Mistral model for external querying in streamlit app ## Update 3/21/24 + - Custom synonym expansion - leveraging llm to produce larger range of synonyms of key entities found in query - custom formatting to fit neo4j @@ -14,6 +17,7 @@ - further testing to fine tune the prompt for increased accuracy ## Update 3/19/24 + - Enhancing retrieval with llm - passing in llm to `KnowledgeGraphRAGRetriever` allows model to make jumps in entity extraction process (ie return entities not specifically mentioned) - ex. `query`: Tell me about Sirius Black. `entities`: ['Harry Potter'] (assuming Sirius Black is not an existing entity) @@ -29,30 +33,33 @@ - need to test effectiveness ## Update 3/14/24 + - Set up querying of web corpus using Gemma, but through locally hosted model using Ollama - no API calls on external server that could be easily integrated with llama index frameworks - initial observation is that it is much slower to slower to locally host - Ollama can be used to host all of the open source models as well - - very easy Ollama integration with llama index + - very easy Ollama integration with llama index - using https://docs.llamaindex.ai/en/latest/examples/llm/ollama.html ## Update 3/13/24 + - Set up queyring of web corpus using Perplexity - really great optionality in specific model to use - mistral-7b-instruct - mixtral-8x7b-instruct - sonar-small-chat (perplexity model) - others found here: https://docs.perplexity.ai/docs/model-cards - - interesting update from perplexity recently: *Deprecation and removal of codellama-34b-instruct and llama-2-70b-chat* + - interesting update from perplexity recently: _Deprecation and removal of codellama-34b-instruct and llama-2-70b-chat_ - test results under /tests - Overall querying external source and adding to KG is successful - When using RAG retrieval, hard to identify key entities at times for newly added nodes - Looking into why the retrieval process is a little buggy ## Update 3/12/24 + - Set up querying of web corpus using Llama 2 - - information is succesfully injected into KG - - when querying afterwards, RAG retreiver and index both have a hard time identifying the new topics being asked as key entities (index has some better luck) + - information is successfully injected into KG + - when querying afterwards, RAG retriever and index both have a hard time identifying the new topics being asked as key entities (index has some better luck) - Looking into LangChain + Diffbot for alternative options - Investigating why key entities are not being identified using llama index -- https://lmy.medium.com/comparing-langchain-and-llamaindex-with-4-tasks-2970140edf33 \ No newline at end of file +- https://lmy.medium.com/comparing-langchain-and-llamaindex-with-4-tasks-2970140edf33 diff --git a/dev/recursive_retrieval/entity_extraction/entity_extraction.py b/dev/recursive_retrieval/entity_extraction/entity_extraction.py index 1b231848..3486a60c 100644 --- a/dev/recursive_retrieval/entity_extraction/entity_extraction.py +++ b/dev/recursive_retrieval/entity_extraction/entity_extraction.py @@ -2,7 +2,6 @@ from typing import List from dotenv import load_dotenv -from langchain.chains import LLMChain from langchain.prompts import PromptTemplate from langchain_core.output_parsers import JsonOutputParser from langchain_openai import OpenAI @@ -17,7 +16,7 @@ def custom_entity_extract_fn(query: str) -> List[str]: template = """ You are an expert entity extraction system. Extract the following entities from the given text: - + Format: {format_instructions} Text: {query} @@ -26,20 +25,18 @@ def custom_entity_extract_fn(query: str) -> List[str]: prompt = PromptTemplate( template=template, input_variables=["query"], - partial_variables={ - "format_instructions": parser.get_format_instructions() - }, + partial_variables={"format_instructions": parser.get_format_instructions()}, ) chain = prompt | llm | parser result = chain.invoke({"query": query}) - l = [] + entity_list = [] for category in result: for entity in result[category]: - l.append(entity) + entity_list.append(entity) - return l + return entity_list # testing diff --git a/dev/recursive_retrieval/external_perplexity.ipynb b/dev/recursive_retrieval/external_perplexity.ipynb index 862933ab..c452ef47 100644 --- a/dev/recursive_retrieval/external_perplexity.ipynb +++ b/dev/recursive_retrieval/external_perplexity.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -14,7 +14,7 @@ "load_dotenv()\n", "\n", "pplx_api_key = os.getenv(\"PERPLEXITY_API_KEY\")\n", - "os.environ[\"OPENAI_API_KEY\"] = os.getenv('OPENAI_KEY')\n", + "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_KEY\")\n", "\n", "query_llm = Perplexity(\n", " api_key=pplx_api_key, model=\"sonar-small-online\", temperature=0.5\n", @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -33,8 +33,8 @@ "from llama_index.core import StorageContext\n", "\n", "username = \"neo4j\"\n", - "password = os.getenv('NEO4J_PW')\n", - "url = os.getenv('NEO4J_URL')\n", + "password = os.getenv(\"NEO4J_PW\")\n", + "url = os.getenv(\"NEO4J_URL\")\n", "database = \"neo4j\"\n", "\n", "graph_store = Neo4jGraphStore(\n", @@ -44,16 +44,18 @@ " database=database,\n", ")\n", "\n", - "storage_context = StorageContext.from_defaults(graph_store=graph_store)\n" + "storage_context = StorageContext.from_defaults(graph_store=graph_store)" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "from llama_index.core.indices.knowledge_graph.retrievers import KnowledgeGraphRAGRetriever\n", + "from llama_index.core.indices.knowledge_graph.retrievers import (\n", + " KnowledgeGraphRAGRetriever,\n", + ")\n", "from llama_index.core.query_engine import RetrieverQueryEngine\n", "from entity_extraction.entity_extraction import custom_entity_extract_fn\n", "from synonym_expand.synonym import custom_synonym_expand_fn\n", @@ -65,7 +67,7 @@ " # entity_extract_fn=custom_entity_extract_fn,\n", " retriever_mode=\"keyword\",\n", " with_nl2graphquery=True,\n", - " synonym_expand_fn=custom_synonym_expand_fn\n", + " synonym_expand_fn=custom_synonym_expand_fn,\n", ")\n", "\n", "query_engine_with_nl2graphquery = RetrieverQueryEngine.from_args(\n", @@ -75,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -107,7 +109,7 @@ " print(external_response)\n", "\n", " # 2) answer needs to be stored into txt file for loading into KG\n", - " with open('data/external_response.txt', 'w') as f:\n", + " with open(\"data/external_response.txt\", \"w\") as f:\n", " print(external_response, file=f)\n", "else:\n", " print(\"From Graph: \" + str(pre_response))\n", @@ -116,14 +118,14 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from llama_index.core import KnowledgeGraphIndex, SimpleDirectoryReader\n", "\n", "documents = SimpleDirectoryReader(\n", - " input_files=['data/external_response.txt']\n", + " input_files=[\"data/external_response.txt\"]\n", ").load_data()\n", "\n", "index = KnowledgeGraphIndex.from_documents(\n", @@ -135,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -149,7 +151,7 @@ ], "source": [ "post_response = query_engine_with_nl2graphquery.query(\n", - " query,\n", + " query,\n", ")\n", "\n", "print(post_response)\n", @@ -172,8 +174,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/recursive_retrieval/langchain_retrieval/retrieve.ipynb b/dev/recursive_retrieval/langchain_retrieval/retrieve.ipynb index e0c8bc14..b5f9ae3c 100644 --- a/dev/recursive_retrieval/langchain_retrieval/retrieve.ipynb +++ b/dev/recursive_retrieval/langchain_retrieval/retrieve.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -11,16 +11,16 @@ "\n", "load_dotenv()\n", "\n", - "os.environ[\"OPENAI_API_KEY\"] = os.getenv('OPENAI_KEY')\n", - "os.environ[\"NEO4J_URI\"] = os.getenv('NEO4J_URL')\n", + "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_KEY\")\n", + "os.environ[\"NEO4J_URI\"] = os.getenv(\"NEO4J_URL\")\n", "os.environ[\"NEO4J_USERNAME\"] = \"neo4j\"\n", - "os.environ[\"NEO4J_PASSWORD\"] = os.getenv('NEO4J_PW')\n", + "os.environ[\"NEO4J_PASSWORD\"] = os.getenv(\"NEO4J_PW\")\n", "os.environ[\"NEO4J_DATABSE\"] = \"neo4j\"" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -32,13 +32,13 @@ "# password = os.getenv('NEO4J_PW')\n", "# database = \"neo4j\"\n", "\n", - "llm=ChatOpenAI(temperature=0, model_name=\"gpt-3.5-turbo\")\n", + "llm = ChatOpenAI(temperature=0, model_name=\"gpt-3.5-turbo\")\n", "graph = Neo4jGraph()" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -64,7 +64,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -73,7 +73,7 @@ "[]" ] }, - "execution_count": 15, + "execution_count": null, "metadata": {}, "output_type": "execute_result" } @@ -87,15 +87,17 @@ " search_type=\"hybrid\",\n", " node_label=\"Document\",\n", " text_node_properties=[\"text\"],\n", - " embedding_node_property=\"embedding\"\n", + " embedding_node_property=\"embedding\",\n", ")\n", "\n", - "graph.query(\"CREATE FULLTEXT INDEX entity IF NOT EXISTS FOR (e:__Entity__) ON EACH [e.id]\")\n" + "graph.query(\n", + " \"CREATE FULLTEXT INDEX entity IF NOT EXISTS FOR (e:__Entity__) ON EACH [e.id]\"\n", + ")" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -128,8 +130,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/recursive_retrieval/langchain_retrieval/retrieve.py b/dev/recursive_retrieval/langchain_retrieval/retrieve.py index 15d10c16..ef755161 100644 --- a/dev/recursive_retrieval/langchain_retrieval/retrieve.py +++ b/dev/recursive_retrieval/langchain_retrieval/retrieve.py @@ -1,12 +1,5 @@ -import os -from dotenv import load_dotenv -from langchain_community.graphs import Neo4jGraph -from langchain_community.vectorstores import Neo4jVector -from langchain_openai import OpenAIEmbeddings from langchain_core.pydantic_v1 import BaseModel, Field from typing import List -from langchain_core.prompts import ChatPromptTemplate -from langchain_openai import ChatOpenAI from langchain_community.vectorstores.neo4j_vector import remove_lucene_chars @@ -18,44 +11,46 @@ class Entities(BaseModel): description="All the person, organization, or business entities that appear in the text", ) -def structured_retriever(question: str) -> str: - """ - Collects the neighborhood of entities mentioned - in the question - """ - result = "" - entities = entity_chain.invoke({"question": question}) - for entity in entities.names: - response = graph.query( - """CALL db.index.fulltext.queryNodes('entity', $query, - {limit:2}) - YIELD node,score - CALL { - MATCH (node)-[r:!MENTIONS]->(neighbor) - RETURN node.id + ' - ' + type(r) + ' -> ' + neighbor.id AS - output - UNION - MATCH (node)<-[r:!MENTIONS]-(neighbor) - RETURN neighbor.id + ' - ' + type(r) + ' -> ' + node.id AS - output - } - RETURN output LIMIT 50 - """, - {"query": generate_full_text_query(entity)}, - ) - result += "\n".join([el['output'] for el in response]) - return result + +# def structured_retriever(question: str) -> str: +# """ +# Collects the neighborhood of entities mentioned +# in the question +# """ +# result = "" +# entities = entity_chain.invoke({"question": question}) +# for entity in entities.names: +# response = graph.query( +# """CALL db.index.fulltext.queryNodes('entity', $query, +# {limit:2}) +# YIELD node,score +# CALL { +# MATCH (node)-[r:!MENTIONS]->(neighbor) +# RETURN node.id + ' - ' + type(r) + ' -> ' + neighbor.id AS +# output +# UNION +# MATCH (node)<-[r:!MENTIONS]-(neighbor) +# RETURN neighbor.id + ' - ' + type(r) + ' -> ' + node.id AS +# output +# } +# RETURN output LIMIT 50 +# """, +# {"query": generate_full_text_query(entity)}, +# ) +# result += "\n".join([el["output"] for el in response]) +# return result + def generate_full_text_query(input: str) -> str: """ Generate a full-text search query for a given input string. This function constructs a query string suitable for a full-text - search. It processes the input string by splitting it into words and + search. It processes the input string by splitting it into words and appending a similarity threshold (~2 changed characters) to each word, then combines them using the AND operator. Useful for mapping - entities from user questions to database values, and allows for some - misspelings. + entities from user questions to database values, and allows for some + misspellings. """ full_text_query = "" words = [el for el in remove_lucene_chars(input).split() if el] @@ -63,4 +58,3 @@ def generate_full_text_query(input: str) -> str: full_text_query += f" {word}~2 AND" full_text_query += f" {words[-1]}~2" return full_text_query.strip() - diff --git a/dev/recursive_retrieval/recurse.ipynb b/dev/recursive_retrieval/recurse.ipynb index 28fcb5d1..99e9ca8e 100644 --- a/dev/recursive_retrieval/recurse.ipynb +++ b/dev/recursive_retrieval/recurse.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -11,12 +11,12 @@ "\n", "load_dotenv()\n", "\n", - "os.environ[\"OPENAI_API_KEY\"] = os.getenv('OPENAI_KEY')" + "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_KEY\")" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -24,8 +24,8 @@ "from llama_index.core import StorageContext\n", "\n", "username = \"neo4j\"\n", - "password = os.getenv('NEO4J_PW')\n", - "url = os.getenv('NEO4J_URL')\n", + "password = os.getenv(\"NEO4J_PW\")\n", + "url = os.getenv(\"NEO4J_URL\")\n", "database = \"neo4j\"\n", "\n", "graph_store = Neo4jGraphStore(\n", @@ -40,11 +40,13 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "from llama_index.core.indices.knowledge_graph.retrievers import KnowledgeGraphRAGRetriever\n", + "from llama_index.core.indices.knowledge_graph.retrievers import (\n", + " KnowledgeGraphRAGRetriever,\n", + ")\n", "from llama_index.core.query_engine import RetrieverQueryEngine\n", "\n", "graph_rag_retriever_with_nl2graphquery = KnowledgeGraphRAGRetriever(\n", @@ -56,12 +58,12 @@ "\n", "query_engine_with_nl2graphquery = RetrieverQueryEngine.from_args(\n", " graph_rag_retriever_with_nl2graphquery,\n", - ")\n" + ")" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -89,7 +91,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -259,8 +261,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.6" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/dev/recursive_retrieval/requirements.txt b/dev/recursive_retrieval/requirements.txt index 14218192..81d65eff 100644 --- a/dev/recursive_retrieval/requirements.txt +++ b/dev/recursive_retrieval/requirements.txt @@ -20,4 +20,4 @@ llama-index-llms-ollama==0.1.2 langchain==0.1.12 langchain-openai==0.0.8 pandas -matplotlib==3.8.4 \ No newline at end of file +matplotlib==3.8.4 diff --git a/dev/recursive_retrieval/synonym_expand/synonym.py b/dev/recursive_retrieval/synonym_expand/synonym.py index dc7a1286..75e21c11 100644 --- a/dev/recursive_retrieval/synonym_expand/synonym.py +++ b/dev/recursive_retrieval/synonym_expand/synonym.py @@ -15,14 +15,14 @@ def custom_synonym_expand_fn(keywords: str) -> List[str]: parser = JsonOutputParser(pydantic_object=Output) template = """ - You are an expert synonym exapnding system. Find synonyms or words commonly used in place to reference the same word for every word in the list: + You are an expert synonym expanding system. Find synonyms or words commonly used in place to reference the same word for every word in the list: Some examples are: - a synonym for Palantir may be Palantir technologies or Palantir technologies inc. - a synonym for Austin may be Austin texas - - a synonym for Taylor swift may be Taylor + - a synonym for Taylor swift may be Taylor - a synonym for Winter park may be Winter park resort - + Format: {format_instructions} Text: {keywords} @@ -37,12 +37,12 @@ def custom_synonym_expand_fn(keywords: str) -> List[str]: chain = prompt | llm | parser result = chain.invoke({"keywords": keywords}) - l = [] + synonym_list = [] for category in result: for synonym in result[category]: - l.append(synonym.capitalize()) + synonym_list.append(synonym.capitalize()) - return l + return synonym_list # testing diff --git a/dev/reranking/Reranking.ipynb b/dev/reranking/Reranking.ipynb index ce15da71..c2549baf 100644 --- a/dev/reranking/Reranking.ipynb +++ b/dev/reranking/Reranking.ipynb @@ -1,724 +1,671 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "ZhbzLug_ZstC" - }, - "source": [ - "\"Open" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "6iR1znpoZstG" - }, - "source": [ - "# Colbert Rerank" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "xNRxNZBoZstG" - }, - "source": [ - "If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.\n", - "\n", - "\n", - "[Colbert](https://github.com/stanford-futuredata/ColBERT): ColBERT is a fast and accurate retrieval model, enabling scalable BERT-based search over large text collections in tens of milliseconds.\n", - "\n", - "This example shows how we use Colbert-V2 model as a reranker." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "id": "JpYcJF2AZstH", - "outputId": "f7d684bb-d720-44f9-d0ea-d3bd651ebf96", - "colab": { - "base_uri": "https://localhost:8080/" - } - }, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Collecting llama-index\n", - " Downloading llama_index-0.10.30-py3-none-any.whl (6.9 kB)\n", - "Collecting llama-index-agent-openai<0.3.0,>=0.1.4 (from llama-index)\n", - " Downloading llama_index_agent_openai-0.2.2-py3-none-any.whl (12 kB)\n", - "Collecting llama-index-cli<0.2.0,>=0.1.2 (from llama-index)\n", - " Downloading llama_index_cli-0.1.12-py3-none-any.whl (26 kB)\n", - "Collecting llama-index-core<0.11.0,>=0.10.30 (from llama-index)\n", - " Downloading llama_index_core-0.10.30-py3-none-any.whl (15.4 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m15.4/15.4 MB\u001b[0m \u001b[31m43.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting llama-index-embeddings-openai<0.2.0,>=0.1.5 (from llama-index)\n", - " Downloading llama_index_embeddings_openai-0.1.7-py3-none-any.whl (6.0 kB)\n", - "Collecting llama-index-indices-managed-llama-cloud<0.2.0,>=0.1.2 (from llama-index)\n", - " Downloading llama_index_indices_managed_llama_cloud-0.1.5-py3-none-any.whl (6.7 kB)\n", - "Collecting llama-index-legacy<0.10.0,>=0.9.48 (from llama-index)\n", - " Downloading llama_index_legacy-0.9.48-py3-none-any.whl (2.0 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m49.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting llama-index-llms-openai<0.2.0,>=0.1.13 (from llama-index)\n", - " Downloading llama_index_llms_openai-0.1.15-py3-none-any.whl (10 kB)\n", - "Collecting llama-index-multi-modal-llms-openai<0.2.0,>=0.1.3 (from llama-index)\n", - " Downloading llama_index_multi_modal_llms_openai-0.1.5-py3-none-any.whl (5.8 kB)\n", - "Collecting llama-index-program-openai<0.2.0,>=0.1.3 (from llama-index)\n", - " Downloading llama_index_program_openai-0.1.5-py3-none-any.whl (4.1 kB)\n", - "Collecting llama-index-question-gen-openai<0.2.0,>=0.1.2 (from llama-index)\n", - " Downloading llama_index_question_gen_openai-0.1.3-py3-none-any.whl (2.9 kB)\n", - "Collecting llama-index-readers-file<0.2.0,>=0.1.4 (from llama-index)\n", - " Downloading llama_index_readers_file-0.1.19-py3-none-any.whl (36 kB)\n", - "Collecting llama-index-readers-llama-parse<0.2.0,>=0.1.2 (from llama-index)\n", - " Downloading llama_index_readers_llama_parse-0.1.4-py3-none-any.whl (2.5 kB)\n", - "Collecting openai>=1.14.0 (from llama-index-agent-openai<0.3.0,>=0.1.4->llama-index)\n", - " Downloading openai-1.22.0-py3-none-any.whl (310 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m311.0/311.0 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: PyYAML>=6.0.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (6.0.1)\n", - "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2.0.29)\n", - "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (3.9.5)\n", - "Collecting dataclasses-json (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading dataclasses_json-0.6.4-py3-none-any.whl (28 kB)\n", - "Collecting deprecated>=1.2.9.3 (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading Deprecated-1.2.14-py2.py3-none-any.whl (9.6 kB)\n", - "Collecting dirtyjson<2.0.0,>=1.0.8 (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading dirtyjson-1.0.8-py3-none-any.whl (25 kB)\n", - "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2023.6.0)\n", - "Collecting httpx (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading httpx-0.27.0-py3-none-any.whl (75 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting llamaindex-py-client<0.2.0,>=0.1.18 (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading llamaindex_py_client-0.1.18-py3-none-any.whl (136 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m136.1/136.1 kB\u001b[0m \u001b[31m10.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.6.0)\n", - "Requirement already satisfied: networkx>=3.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (3.3)\n", - "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (3.8.1)\n", - "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.25.2)\n", - "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2.0.3)\n", - "Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (9.4.0)\n", - "Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2.31.0)\n", - "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (8.2.3)\n", - "Collecting tiktoken>=0.3.3 (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading tiktoken-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m53.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: tqdm<5.0.0,>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (4.66.2)\n", - "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (4.11.0)\n", - "Collecting typing-inspect>=0.8.0 (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)\n", - "Requirement already satisfied: wrapt in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.14.1)\n", - "Requirement already satisfied: beautifulsoup4<5.0.0,>=4.12.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-readers-file<0.2.0,>=0.1.4->llama-index) (4.12.3)\n", - "Collecting pypdf<5.0.0,>=4.0.1 (from llama-index-readers-file<0.2.0,>=0.1.4->llama-index)\n", - " Downloading pypdf-4.2.0-py3-none-any.whl (290 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m290.4/290.4 kB\u001b[0m \u001b[31m18.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting striprtf<0.0.27,>=0.0.26 (from llama-index-readers-file<0.2.0,>=0.1.4->llama-index)\n", - " Downloading striprtf-0.0.26-py3-none-any.whl (6.9 kB)\n", - "Collecting llama-parse<0.5.0,>=0.4.0 (from llama-index-readers-llama-parse<0.2.0,>=0.1.2->llama-index)\n", - " Downloading llama_parse-0.4.1-py3-none-any.whl (7.3 kB)\n", - "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.3.1)\n", - "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (23.2.0)\n", - "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.4.1)\n", - "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (6.0.5)\n", - "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.9.4)\n", - "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (4.0.3)\n", - "Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.10/dist-packages (from beautifulsoup4<5.0.0,>=4.12.3->llama-index-readers-file<0.2.0,>=0.1.4->llama-index) (2.5)\n", - "Requirement already satisfied: pydantic>=1.10 in /usr/local/lib/python3.10/dist-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.7.0)\n", - "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.7.1)\n", - "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (2024.2.2)\n", - "Collecting httpcore==1.* (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading httpcore-1.0.5-py3-none-any.whl (77 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.7)\n", - "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.3.1)\n", - "Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.30->llama-index) (8.1.7)\n", - "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.4.0)\n", - "Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.30->llama-index) (2023.12.25)\n", - "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.14.0->llama-index-agent-openai<0.3.0,>=0.1.4->llama-index) (1.7.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.3.2)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.0.7)\n", - "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.0.3)\n", - "Collecting mypy-extensions>=0.3.0 (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)\n", - "Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json->llama-index-core<0.11.0,>=0.10.30->llama-index)\n", - " Downloading marshmallow-3.21.1-py3-none-any.whl (49 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.4/49.4 kB\u001b[0m \u001b[31m3.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.8.2)\n", - "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (2023.4)\n", - "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (2024.1)\n", - "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.2.0)\n", - "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.10/dist-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.30->llama-index) (24.0)\n", - "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.30->llama-index) (0.6.0)\n", - "Requirement already satisfied: pydantic-core==2.18.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.18.1)\n", - "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.16.0)\n", - "Installing collected packages: striprtf, dirtyjson, pypdf, mypy-extensions, marshmallow, h11, deprecated, typing-inspect, tiktoken, httpcore, httpx, dataclasses-json, openai, llamaindex-py-client, llama-index-legacy, llama-index-core, llama-parse, llama-index-readers-file, llama-index-llms-openai, llama-index-indices-managed-llama-cloud, llama-index-embeddings-openai, llama-index-readers-llama-parse, llama-index-multi-modal-llms-openai, llama-index-cli, llama-index-agent-openai, llama-index-program-openai, llama-index-question-gen-openai, llama-index\n", - "Successfully installed dataclasses-json-0.6.4 deprecated-1.2.14 dirtyjson-1.0.8 h11-0.14.0 httpcore-1.0.5 httpx-0.27.0 llama-index-0.10.30 llama-index-agent-openai-0.2.2 llama-index-cli-0.1.12 llama-index-core-0.10.30 llama-index-embeddings-openai-0.1.7 llama-index-indices-managed-llama-cloud-0.1.5 llama-index-legacy-0.9.48 llama-index-llms-openai-0.1.15 llama-index-multi-modal-llms-openai-0.1.5 llama-index-program-openai-0.1.5 llama-index-question-gen-openai-0.1.3 llama-index-readers-file-0.1.19 llama-index-readers-llama-parse-0.1.4 llama-parse-0.4.1 llamaindex-py-client-0.1.18 marshmallow-3.21.1 mypy-extensions-1.0.0 openai-1.22.0 pypdf-4.2.0 striprtf-0.0.26 tiktoken-0.6.0 typing-inspect-0.9.0\n", - "Requirement already satisfied: llama-index-core in /usr/local/lib/python3.10/dist-packages (0.10.30)\n", - "Requirement already satisfied: PyYAML>=6.0.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (6.0.1)\n", - "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (2.0.29)\n", - "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (3.9.5)\n", - "Requirement already satisfied: dataclasses-json in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (0.6.4)\n", - "Requirement already satisfied: deprecated>=1.2.9.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.2.14)\n", - "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.0.8)\n", - "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (2023.6.0)\n", - "Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (0.27.0)\n", - "Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (0.1.18)\n", - "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.6.0)\n", - "Requirement already satisfied: networkx>=3.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (3.3)\n", - "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (3.8.1)\n", - "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.25.2)\n", - "Requirement already satisfied: openai>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.22.0)\n", - "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (2.0.3)\n", - "Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (9.4.0)\n", - "Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (2.31.0)\n", - "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (8.2.3)\n", - "Requirement already satisfied: tiktoken>=0.3.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (0.6.0)\n", - "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (4.66.2)\n", - "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (4.11.0)\n", - "Requirement already satisfied: typing-inspect>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (0.9.0)\n", - "Requirement already satisfied: wrapt in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.14.1)\n", - "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (1.3.1)\n", - "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (23.2.0)\n", - "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (1.4.1)\n", - "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (6.0.5)\n", - "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (1.9.4)\n", - "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (4.0.3)\n", - "Requirement already satisfied: pydantic>=1.10 in /usr/local/lib/python3.10/dist-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core) (2.7.0)\n", - "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core) (3.7.1)\n", - "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core) (2024.2.2)\n", - "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core) (1.0.5)\n", - "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core) (3.7)\n", - "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core) (1.3.1)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx->llama-index-core) (0.14.0)\n", - "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core) (8.1.7)\n", - "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core) (1.4.0)\n", - "Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core) (2023.12.25)\n", - "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.1.0->llama-index-core) (1.7.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core) (3.3.2)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core) (2.0.7)\n", - "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core) (3.0.3)\n", - "Requirement already satisfied: mypy-extensions>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from typing-inspect>=0.8.0->llama-index-core) (1.0.0)\n", - "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json->llama-index-core) (3.21.1)\n", - "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core) (2.8.2)\n", - "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core) (2023.4)\n", - "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core) (2024.1)\n", - "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->llama-index-core) (1.2.0)\n", - "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.10/dist-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core) (24.0)\n", - "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core) (0.6.0)\n", - "Requirement already satisfied: pydantic-core==2.18.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core) (2.18.1)\n", - "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->llama-index-core) (1.16.0)\n", - "Requirement already satisfied: llama-index-embeddings-openai in /usr/local/lib/python3.10/dist-packages (0.1.7)\n", - "Requirement already satisfied: llama-index-core<0.11.0,>=0.10.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-embeddings-openai) (0.10.30)\n", - "Requirement already satisfied: PyYAML>=6.0.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (6.0.1)\n", - "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.0.29)\n", - "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.9.5)\n", - "Requirement already satisfied: dataclasses-json in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.6.4)\n", - "Requirement already satisfied: deprecated>=1.2.9.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.2.14)\n", - "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.0.8)\n", - "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2023.6.0)\n", - "Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.27.0)\n", - "Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.1.18)\n", - "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.6.0)\n", - "Requirement already satisfied: networkx>=3.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.3)\n", - "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.8.1)\n", - "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.25.2)\n", - "Requirement already satisfied: openai>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.22.0)\n", - "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.0.3)\n", - "Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (9.4.0)\n", - "Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.31.0)\n", - "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (8.2.3)\n", - "Requirement already satisfied: tiktoken>=0.3.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.6.0)\n", - "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (4.66.2)\n", - "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (4.11.0)\n", - "Requirement already satisfied: typing-inspect>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.9.0)\n", - "Requirement already satisfied: wrapt in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.14.1)\n", - "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.3.1)\n", - "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (23.2.0)\n", - "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.4.1)\n", - "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (6.0.5)\n", - "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.9.4)\n", - "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (4.0.3)\n", - "Requirement already satisfied: pydantic>=1.10 in /usr/local/lib/python3.10/dist-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.7.0)\n", - "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.7.1)\n", - "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2024.2.2)\n", - "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.0.5)\n", - "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.7)\n", - "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.3.1)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.14.0)\n", - "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (8.1.7)\n", - "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.4.0)\n", - "Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2023.12.25)\n", - "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.1.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.7.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.3.2)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.0.7)\n", - "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.0.3)\n", - "Requirement already satisfied: mypy-extensions>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.0.0)\n", - "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.21.1)\n", - "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.8.2)\n", - "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2023.4)\n", - "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2024.1)\n", - "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.2.0)\n", - "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.10/dist-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (24.0)\n", - "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.6.0)\n", - "Requirement already satisfied: pydantic-core==2.18.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.18.1)\n", - "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.16.0)\n", - "Requirement already satisfied: llama-index-llms-openai in /usr/local/lib/python3.10/dist-packages (0.1.15)\n", - "Requirement already satisfied: llama-index-core<0.11.0,>=0.10.24 in /usr/local/lib/python3.10/dist-packages (from llama-index-llms-openai) (0.10.30)\n", - "Requirement already satisfied: PyYAML>=6.0.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (6.0.1)\n", - "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.0.29)\n", - "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.9.5)\n", - "Requirement already satisfied: dataclasses-json in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.6.4)\n", - "Requirement already satisfied: deprecated>=1.2.9.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.2.14)\n", - "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.0.8)\n", - "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2023.6.0)\n", - "Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.27.0)\n", - "Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.1.18)\n", - "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.6.0)\n", - "Requirement already satisfied: networkx>=3.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.3)\n", - "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.8.1)\n", - "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.25.2)\n", - "Requirement already satisfied: openai>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.22.0)\n", - "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.0.3)\n", - "Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (9.4.0)\n", - "Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.31.0)\n", - "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (8.2.3)\n", - "Requirement already satisfied: tiktoken>=0.3.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.6.0)\n", - "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (4.66.2)\n", - "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (4.11.0)\n", - "Requirement already satisfied: typing-inspect>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.9.0)\n", - "Requirement already satisfied: wrapt in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.14.1)\n", - "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.3.1)\n", - "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (23.2.0)\n", - "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.4.1)\n", - "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (6.0.5)\n", - "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.9.4)\n", - "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (4.0.3)\n", - "Requirement already satisfied: pydantic>=1.10 in /usr/local/lib/python3.10/dist-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.7.0)\n", - "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.7.1)\n", - "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2024.2.2)\n", - "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.0.5)\n", - "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.7)\n", - "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.3.1)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.14.0)\n", - "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (8.1.7)\n", - "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.4.0)\n", - "Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2023.12.25)\n", - "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.1.0->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.7.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.3.2)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.0.7)\n", - "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.0.3)\n", - "Requirement already satisfied: mypy-extensions>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.0.0)\n", - "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.21.1)\n", - "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.8.2)\n", - "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2023.4)\n", - "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2024.1)\n", - "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.2.0)\n", - "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.10/dist-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (24.0)\n", - "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.6.0)\n", - "Requirement already satisfied: pydantic-core==2.18.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.18.1)\n", - "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.16.0)\n", - "Collecting llama-index-postprocessor-colbert-rerank\n", - " Downloading llama_index_postprocessor_colbert_rerank-0.1.1-py3-none-any.whl (3.4 kB)\n", - "Requirement already satisfied: llama-index-core<0.11.0,>=0.10.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-postprocessor-colbert-rerank) (0.10.30)\n", - "Requirement already satisfied: torch<3.0.0,>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-postprocessor-colbert-rerank) (2.2.1+cu121)\n", - "Requirement already satisfied: transformers<5.0.0,>=4.37.2 in /usr/local/lib/python3.10/dist-packages (from llama-index-postprocessor-colbert-rerank) (4.38.2)\n", - "Requirement already satisfied: PyYAML>=6.0.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (6.0.1)\n", - "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.0.29)\n", - "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.9.5)\n", - "Requirement already satisfied: dataclasses-json in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.6.4)\n", - "Requirement already satisfied: deprecated>=1.2.9.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.2.14)\n", - "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.0.8)\n", - "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2023.6.0)\n", - "Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.27.0)\n", - "Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.1.18)\n", - "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.6.0)\n", - "Requirement already satisfied: networkx>=3.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.3)\n", - "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.8.1)\n", - "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.25.2)\n", - "Requirement already satisfied: openai>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.22.0)\n", - "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.0.3)\n", - "Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (9.4.0)\n", - "Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.31.0)\n", - "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (8.2.3)\n", - "Requirement already satisfied: tiktoken>=0.3.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.6.0)\n", - "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (4.66.2)\n", - "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (4.11.0)\n", - "Requirement already satisfied: typing-inspect>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.9.0)\n", - "Requirement already satisfied: wrapt in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.14.1)\n", - "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (3.13.4)\n", - "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (1.12)\n", - "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (3.1.3)\n", - "Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.105)\n", - "Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.105)\n", - "Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.105)\n", - "Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (8.9.2.26)\n", - "Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.3.1)\n", - "Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (11.0.2.54)\n", - "Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (10.3.2.106)\n", - "Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (11.4.5.107)\n", - "Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.0.106)\n", - "Requirement already satisfied: nvidia-nccl-cu12==2.19.3 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (2.19.3)\n", - "Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.105)\n", - "Requirement already satisfied: triton==2.2.0 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (2.2.0)\n", - "Requirement already satisfied: nvidia-nvjitlink-cu12 in /usr/local/lib/python3.10/dist-packages (from nvidia-cusolver-cu12==11.4.5.107->torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.4.127)\n", - "Requirement already satisfied: huggingface-hub<1.0,>=0.19.3 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.37.2->llama-index-postprocessor-colbert-rerank) (0.20.3)\n", - "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.37.2->llama-index-postprocessor-colbert-rerank) (24.0)\n", - "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.37.2->llama-index-postprocessor-colbert-rerank) (2023.12.25)\n", - "Requirement already satisfied: tokenizers<0.19,>=0.14 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.37.2->llama-index-postprocessor-colbert-rerank) (0.15.2)\n", - "Requirement already satisfied: safetensors>=0.4.1 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.37.2->llama-index-postprocessor-colbert-rerank) (0.4.3)\n", - "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.3.1)\n", - "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (23.2.0)\n", - "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.4.1)\n", - "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (6.0.5)\n", - "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.9.4)\n", - "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (4.0.3)\n", - "Requirement already satisfied: pydantic>=1.10 in /usr/local/lib/python3.10/dist-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.7.0)\n", - "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.7.1)\n", - "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2024.2.2)\n", - "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.0.5)\n", - "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.7)\n", - "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.3.1)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.14.0)\n", - "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (8.1.7)\n", - "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.4.0)\n", - "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.1.0->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.7.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.3.2)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.0.7)\n", - "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.0.3)\n", - "Requirement already satisfied: mypy-extensions>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.0.0)\n", - "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.21.1)\n", - "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (2.1.5)\n", - "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.8.2)\n", - "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2023.4)\n", - "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2024.1)\n", - "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (1.3.0)\n", - "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.2.0)\n", - "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.6.0)\n", - "Requirement already satisfied: pydantic-core==2.18.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.18.1)\n", - "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.16.0)\n", - "Installing collected packages: llama-index-postprocessor-colbert-rerank\n", - "Successfully installed llama-index-postprocessor-colbert-rerank-0.1.1\n" - ] - } - ], - "source": [ - "!pip install llama-index\n", - "!pip install llama-index-core\n", - "!pip install --quiet transformers torch\n", - "!pip install llama-index-embeddings-openai\n", - "!pip install llama-index-llms-openai\n", - "!pip install llama-index-postprocessor-colbert-rerank" - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": { - "id": "oKZfnYxPZstJ" - }, - "outputs": [], - "source": [ - "from llama_index.core import (\n", - " VectorStoreIndex,\n", - " SimpleDirectoryReader,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ks2pbYZ5ZstJ" - }, - "source": [ - "Download Data" - ] - }, - { - "cell_type": "code", - "execution_count": 50, - "metadata": { - "id": "IaT4vkQlZstK" - }, - "outputs": [], - "source": [ - "import os\n", - "\n", - "os.environ[\"OPENAI_API_KEY\"] = \"sk-\"" - ] - }, - { - "cell_type": "code", - "source": [ - "# TO-DO: GET THE DOCUMENTS FROM ROUTING AGENT - all the answers in paragraph form in one document\n", - "!mkdir -p 'data/routing_agent/'\n", - "#!wget 'https://raw.githubusercontent.com/aishwarya-balaji/reranking/main/data/data8/data8.txt' -O 'data/data8/data8.txt'" - ], - "metadata": { - "id": "_YgCF_LTZSpw" - }, - "execution_count": 51, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "# TO-DO: GET THE DOCUMENTS FROM ROUTING AGENT - all the answers in paragraph form in one document\n", - "with open('./data/routing_agent/routing_agent.txt', 'r') as file:\n", - " # Read the entire file content into a string\n", - " response_options = file.read()" - ], - "metadata": { - "id": "w0Jp8lTUWgi6" - }, - "execution_count": 52, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "documents = SimpleDirectoryReader(\"./data/routing_agent/\").load_data()\n" - ], - "metadata": { - "id": "_cwjQfajj8Al" - }, - "execution_count": 53, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "from llama_index.core.node_parser import SentenceWindowNodeParser\n", - "\n", - "node_parser = SentenceWindowNodeParser.from_defaults(\n", - " window_size=3,\n", - " window_metadata_key=\"window\",\n", - " original_text_metadata_key=\"original_text\",\n", - ")\n", - "\n", - "nodes = node_parser.get_nodes_from_documents(documents)" - ], - "metadata": { - "id": "f6O6zUJWj-Lu" - }, - "execution_count": 54, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "from llama_index.core.node_parser import SentenceSplitter\n", - "text_splitter = SentenceSplitter()\n", - "base_nodes = text_splitter.get_nodes_from_documents(documents)" - ], - "metadata": { - "id": "8A6BZ9xYka8m" - }, - "execution_count": 55, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "sentence_index = VectorStoreIndex(nodes)\n", - "base_index = VectorStoreIndex(base_nodes)" - ], - "metadata": { - "id": "AJEWCl9kklmJ" - }, - "execution_count": 56, - "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "MXtxzzSCZstL" - }, - "source": [ - "#### Retrieve top 10 most relevant nodes, then filter with Colbert Rerank" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": { - "id": "lYOBUqmRZstL" - }, - "outputs": [], - "source": [ - "from llama_index.postprocessor.colbert_rerank import ColbertRerank\n", - "\n", - "colbert_reranker = ColbertRerank(\n", - " top_n=3,#will be equal to how many tools are executed\n", - " model=\"colbert-ir/colbertv2.0\",\n", - " tokenizer=\"colbert-ir/colbertv2.0\",\n", - " keep_retrieval_score=True,\n", - ")\n", - "\n", - "query_engine = sentence_index.as_query_engine(\n", - " similarity_top_k=3,\n", - " node_postprocessors=[colbert_reranker],\n", - ")" - ] - }, - { - "cell_type": "code", - "source": [ - "#To Do: GET THE ORIGINAL QUERY FROM QD - get that from another file, so read the document\n", - "with open('original_query.txt', 'r') as file:\n", - " # Read the entire file content into a string\n", - " original_query = file.read()\n", - "\n", - "response = query_engine.query(\n", - " original_query,\n", - ")" - ], - "metadata": { - "id": "OOSUA3_-oZaI" - }, - "execution_count": 58, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "print(\"Total nodes in response:\", len(response.source_nodes)) # This will print how many nodes are there" - ], - "metadata": { - "id": "dBd_X5xL1Yv3", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "17586224-c1e0-4f02-c074-7ee245a76558" - }, - "execution_count": 59, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Total nodes in response: 3\n" - ] - } - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": { - "id": "PqFtt-leZstM", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "5d9ae6f6-5b28-4ab8-adbb-346cd627bac9" - }, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "b22c4ae8-2c0d-4255-b790-8e90ca60f3f0\n", - "Known as the \"City of Light,\" Paris is celebrated for its romantic ambiance, iconic landmarks like the Eiffel Tower and Notre-Dame Cathedral, world-cl\n", - "reranking score: 0.7583699226379395\n", - "retrieval score: 0.8774996666312472\n", - "**********\n", - "f5b56c8c-3c02-4773-aaa0-6d658e22548d\n", - "The Eiffel Tower, one of the most famous landmarks in the world, stands as an enduring symbol of Paris. \n", - "reranking score: 0.6390765309333801\n", - "retrieval score: 0.8489044372934368\n", - "**********\n", - "00170fbf-3c0d-448b-931d-5a5eb06008a9\n", - "Famous for its stunning sunsets, whitewashed buildings, blue-domed churches, and crystalline waters, Santorini is a dream destination for honeymooners\n", - "reranking score: 0.6205340623855591\n", - "retrieval score: 0.7898268505796289\n", - "**********\n" - ] - } - ], - "source": [ - "# TO DO: figure out how to acess scores for all nodes\n", - "for node in response.source_nodes:\n", - " print(node.id_)\n", - " print(node.node.get_content()[:150]) # number of characters - but not the paragraphs\n", - " print(\"reranking score: \", node.score)\n", - " print(\"retrieval score: \", node.node.metadata[\"retrieval_score\"])\n", - " print(\"**********\")" - ] - }, + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Colbert Rerank" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.\n", + "\n", + "\n", + "[Colbert](https://github.com/stanford-futuredata/ColBERT): ColBERT is a fast and accurate retrieval model, enabling scalable BERT-based search over large text collections in tens of milliseconds.\n", + "\n", + "This example shows how we use Colbert-V2 model as a reranker." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "source": [ - "print(response)" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "pckrXsgwpNQo", - "outputId": "480f9efc-b6ce-4874-bf43-2dfc71f17de8" - }, - "execution_count": 61, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Paris is known for its romantic ambiance, iconic landmarks like the Eiffel Tower and Notre-Dame Cathedral, world-class museums such as the Louvre and Musée d'Orsay, and charming neighborhoods like Montmartre and Le Marais.\n" - ] - } - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting llama-index\n", + " Downloading llama_index-0.10.30-py3-none-any.whl (6.9 kB)\n", + "Collecting llama-index-agent-openai<0.3.0,>=0.1.4 (from llama-index)\n", + " Downloading llama_index_agent_openai-0.2.2-py3-none-any.whl (12 kB)\n", + "Collecting llama-index-cli<0.2.0,>=0.1.2 (from llama-index)\n", + " Downloading llama_index_cli-0.1.12-py3-none-any.whl (26 kB)\n", + "Collecting llama-index-core<0.11.0,>=0.10.30 (from llama-index)\n", + " Downloading llama_index_core-0.10.30-py3-none-any.whl (15.4 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m15.4/15.4 MB\u001b[0m \u001b[31m43.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting llama-index-embeddings-openai<0.2.0,>=0.1.5 (from llama-index)\n", + " Downloading llama_index_embeddings_openai-0.1.7-py3-none-any.whl (6.0 kB)\n", + "Collecting llama-index-indices-managed-llama-cloud<0.2.0,>=0.1.2 (from llama-index)\n", + " Downloading llama_index_indices_managed_llama_cloud-0.1.5-py3-none-any.whl (6.7 kB)\n", + "Collecting llama-index-legacy<0.10.0,>=0.9.48 (from llama-index)\n", + " Downloading llama_index_legacy-0.9.48-py3-none-any.whl (2.0 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m49.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting llama-index-llms-openai<0.2.0,>=0.1.13 (from llama-index)\n", + " Downloading llama_index_llms_openai-0.1.15-py3-none-any.whl (10 kB)\n", + "Collecting llama-index-multi-modal-llms-openai<0.2.0,>=0.1.3 (from llama-index)\n", + " Downloading llama_index_multi_modal_llms_openai-0.1.5-py3-none-any.whl (5.8 kB)\n", + "Collecting llama-index-program-openai<0.2.0,>=0.1.3 (from llama-index)\n", + " Downloading llama_index_program_openai-0.1.5-py3-none-any.whl (4.1 kB)\n", + "Collecting llama-index-question-gen-openai<0.2.0,>=0.1.2 (from llama-index)\n", + " Downloading llama_index_question_gen_openai-0.1.3-py3-none-any.whl (2.9 kB)\n", + "Collecting llama-index-readers-file<0.2.0,>=0.1.4 (from llama-index)\n", + " Downloading llama_index_readers_file-0.1.19-py3-none-any.whl (36 kB)\n", + "Collecting llama-index-readers-llama-parse<0.2.0,>=0.1.2 (from llama-index)\n", + " Downloading llama_index_readers_llama_parse-0.1.4-py3-none-any.whl (2.5 kB)\n", + "Collecting openai>=1.14.0 (from llama-index-agent-openai<0.3.0,>=0.1.4->llama-index)\n", + " Downloading openai-1.22.0-py3-none-any.whl (310 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m311.0/311.0 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: PyYAML>=6.0.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (6.0.1)\n", + "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2.0.29)\n", + "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (3.9.5)\n", + "Collecting dataclasses-json (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading dataclasses_json-0.6.4-py3-none-any.whl (28 kB)\n", + "Collecting deprecated>=1.2.9.3 (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading Deprecated-1.2.14-py2.py3-none-any.whl (9.6 kB)\n", + "Collecting dirtyjson<2.0.0,>=1.0.8 (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading dirtyjson-1.0.8-py3-none-any.whl (25 kB)\n", + "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2023.6.0)\n", + "Collecting httpx (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading httpx-0.27.0-py3-none-any.whl (75 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting llamaindex-py-client<0.2.0,>=0.1.18 (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading llamaindex_py_client-0.1.18-py3-none-any.whl (136 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m136.1/136.1 kB\u001b[0m \u001b[31m10.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.6.0)\n", + "Requirement already satisfied: networkx>=3.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (3.3)\n", + "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (3.8.1)\n", + "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.25.2)\n", + "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2.0.3)\n", + "Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (9.4.0)\n", + "Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2.31.0)\n", + "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (8.2.3)\n", + "Collecting tiktoken>=0.3.3 (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading tiktoken-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m53.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: tqdm<5.0.0,>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (4.66.2)\n", + "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (4.11.0)\n", + "Collecting typing-inspect>=0.8.0 (from llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)\n", + "Requirement already satisfied: wrapt in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.14.1)\n", + "Requirement already satisfied: beautifulsoup4<5.0.0,>=4.12.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-readers-file<0.2.0,>=0.1.4->llama-index) (4.12.3)\n", + "Collecting pypdf<5.0.0,>=4.0.1 (from llama-index-readers-file<0.2.0,>=0.1.4->llama-index)\n", + " Downloading pypdf-4.2.0-py3-none-any.whl (290 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m290.4/290.4 kB\u001b[0m \u001b[31m18.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting striprtf<0.0.27,>=0.0.26 (from llama-index-readers-file<0.2.0,>=0.1.4->llama-index)\n", + " Downloading striprtf-0.0.26-py3-none-any.whl (6.9 kB)\n", + "Collecting llama-parse<0.5.0,>=0.4.0 (from llama-index-readers-llama-parse<0.2.0,>=0.1.2->llama-index)\n", + " Downloading llama_parse-0.4.1-py3-none-any.whl (7.3 kB)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.3.1)\n", + "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (23.2.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (6.0.5)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.9.4)\n", + "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (4.0.3)\n", + "Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.10/dist-packages (from beautifulsoup4<5.0.0,>=4.12.3->llama-index-readers-file<0.2.0,>=0.1.4->llama-index) (2.5)\n", + "Requirement already satisfied: pydantic>=1.10 in /usr/local/lib/python3.10/dist-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.7.0)\n", + "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.7.1)\n", + "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (2024.2.2)\n", + "Collecting httpcore==1.* (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading httpcore-1.0.5-py3-none-any.whl (77 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.7)\n", + "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.3.1)\n", + "Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.30->llama-index) (8.1.7)\n", + "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.4.0)\n", + "Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.30->llama-index) (2023.12.25)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.14.0->llama-index-agent-openai<0.3.0,>=0.1.4->llama-index) (1.7.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.3.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.0.7)\n", + "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.0.3)\n", + "Collecting mypy-extensions>=0.3.0 (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)\n", + "Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json->llama-index-core<0.11.0,>=0.10.30->llama-index)\n", + " Downloading marshmallow-3.21.1-py3-none-any.whl (49 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.4/49.4 kB\u001b[0m \u001b[31m3.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.8.2)\n", + "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (2023.4)\n", + "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (2024.1)\n", + "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.2.0)\n", + "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.10/dist-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.30->llama-index) (24.0)\n", + "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.30->llama-index) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.18.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.18.1)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.16.0)\n", + "Installing collected packages: striprtf, dirtyjson, pypdf, mypy-extensions, marshmallow, h11, deprecated, typing-inspect, tiktoken, httpcore, httpx, dataclasses-json, openai, llamaindex-py-client, llama-index-legacy, llama-index-core, llama-parse, llama-index-readers-file, llama-index-llms-openai, llama-index-indices-managed-llama-cloud, llama-index-embeddings-openai, llama-index-readers-llama-parse, llama-index-multi-modal-llms-openai, llama-index-cli, llama-index-agent-openai, llama-index-program-openai, llama-index-question-gen-openai, llama-index\n", + "Successfully installed dataclasses-json-0.6.4 deprecated-1.2.14 dirtyjson-1.0.8 h11-0.14.0 httpcore-1.0.5 httpx-0.27.0 llama-index-0.10.30 llama-index-agent-openai-0.2.2 llama-index-cli-0.1.12 llama-index-core-0.10.30 llama-index-embeddings-openai-0.1.7 llama-index-indices-managed-llama-cloud-0.1.5 llama-index-legacy-0.9.48 llama-index-llms-openai-0.1.15 llama-index-multi-modal-llms-openai-0.1.5 llama-index-program-openai-0.1.5 llama-index-question-gen-openai-0.1.3 llama-index-readers-file-0.1.19 llama-index-readers-llama-parse-0.1.4 llama-parse-0.4.1 llamaindex-py-client-0.1.18 marshmallow-3.21.1 mypy-extensions-1.0.0 openai-1.22.0 pypdf-4.2.0 striprtf-0.0.26 tiktoken-0.6.0 typing-inspect-0.9.0\n", + "Requirement already satisfied: llama-index-core in /usr/local/lib/python3.10/dist-packages (0.10.30)\n", + "Requirement already satisfied: PyYAML>=6.0.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (6.0.1)\n", + "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (2.0.29)\n", + "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (3.9.5)\n", + "Requirement already satisfied: dataclasses-json in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (0.6.4)\n", + "Requirement already satisfied: deprecated>=1.2.9.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.2.14)\n", + "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.0.8)\n", + "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (2023.6.0)\n", + "Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (0.27.0)\n", + "Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (0.1.18)\n", + "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.6.0)\n", + "Requirement already satisfied: networkx>=3.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (3.3)\n", + "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (3.8.1)\n", + "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.25.2)\n", + "Requirement already satisfied: openai>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.22.0)\n", + "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (2.0.3)\n", + "Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (9.4.0)\n", + "Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (2.31.0)\n", + "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (8.2.3)\n", + "Requirement already satisfied: tiktoken>=0.3.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (0.6.0)\n", + "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (4.66.2)\n", + "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (4.11.0)\n", + "Requirement already satisfied: typing-inspect>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (0.9.0)\n", + "Requirement already satisfied: wrapt in /usr/local/lib/python3.10/dist-packages (from llama-index-core) (1.14.1)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (1.3.1)\n", + "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (23.2.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (6.0.5)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (1.9.4)\n", + "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core) (4.0.3)\n", + "Requirement already satisfied: pydantic>=1.10 in /usr/local/lib/python3.10/dist-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core) (2.7.0)\n", + "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core) (3.7.1)\n", + "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core) (2024.2.2)\n", + "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core) (1.0.5)\n", + "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core) (3.7)\n", + "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core) (1.3.1)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx->llama-index-core) (0.14.0)\n", + "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core) (8.1.7)\n", + "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core) (1.4.0)\n", + "Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core) (2023.12.25)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.1.0->llama-index-core) (1.7.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core) (3.3.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core) (2.0.7)\n", + "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core) (3.0.3)\n", + "Requirement already satisfied: mypy-extensions>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from typing-inspect>=0.8.0->llama-index-core) (1.0.0)\n", + "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json->llama-index-core) (3.21.1)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core) (2.8.2)\n", + "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core) (2023.4)\n", + "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core) (2024.1)\n", + "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->llama-index-core) (1.2.0)\n", + "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.10/dist-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core) (24.0)\n", + "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.18.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core) (2.18.1)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->llama-index-core) (1.16.0)\n", + "Requirement already satisfied: llama-index-embeddings-openai in /usr/local/lib/python3.10/dist-packages (0.1.7)\n", + "Requirement already satisfied: llama-index-core<0.11.0,>=0.10.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-embeddings-openai) (0.10.30)\n", + "Requirement already satisfied: PyYAML>=6.0.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (6.0.1)\n", + "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.0.29)\n", + "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.9.5)\n", + "Requirement already satisfied: dataclasses-json in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.6.4)\n", + "Requirement already satisfied: deprecated>=1.2.9.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.2.14)\n", + "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.0.8)\n", + "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2023.6.0)\n", + "Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.27.0)\n", + "Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.1.18)\n", + "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.6.0)\n", + "Requirement already satisfied: networkx>=3.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.3)\n", + "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.8.1)\n", + "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.25.2)\n", + "Requirement already satisfied: openai>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.22.0)\n", + "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.0.3)\n", + "Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (9.4.0)\n", + "Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.31.0)\n", + "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (8.2.3)\n", + "Requirement already satisfied: tiktoken>=0.3.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.6.0)\n", + "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (4.66.2)\n", + "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (4.11.0)\n", + "Requirement already satisfied: typing-inspect>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.9.0)\n", + "Requirement already satisfied: wrapt in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.14.1)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.3.1)\n", + "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (23.2.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (6.0.5)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.9.4)\n", + "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (4.0.3)\n", + "Requirement already satisfied: pydantic>=1.10 in /usr/local/lib/python3.10/dist-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.7.0)\n", + "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.7.1)\n", + "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2024.2.2)\n", + "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.0.5)\n", + "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.7)\n", + "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.3.1)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.14.0)\n", + "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (8.1.7)\n", + "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.4.0)\n", + "Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2023.12.25)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.1.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.7.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.3.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.0.7)\n", + "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.0.3)\n", + "Requirement already satisfied: mypy-extensions>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.0.0)\n", + "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (3.21.1)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.8.2)\n", + "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2023.4)\n", + "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2024.1)\n", + "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.2.0)\n", + "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.10/dist-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (24.0)\n", + "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.18.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (2.18.1)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-openai) (1.16.0)\n", + "Requirement already satisfied: llama-index-llms-openai in /usr/local/lib/python3.10/dist-packages (0.1.15)\n", + "Requirement already satisfied: llama-index-core<0.11.0,>=0.10.24 in /usr/local/lib/python3.10/dist-packages (from llama-index-llms-openai) (0.10.30)\n", + "Requirement already satisfied: PyYAML>=6.0.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (6.0.1)\n", + "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.0.29)\n", + "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.9.5)\n", + "Requirement already satisfied: dataclasses-json in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.6.4)\n", + "Requirement already satisfied: deprecated>=1.2.9.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.2.14)\n", + "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.0.8)\n", + "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2023.6.0)\n", + "Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.27.0)\n", + "Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.1.18)\n", + "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.6.0)\n", + "Requirement already satisfied: networkx>=3.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.3)\n", + "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.8.1)\n", + "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.25.2)\n", + "Requirement already satisfied: openai>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.22.0)\n", + "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.0.3)\n", + "Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (9.4.0)\n", + "Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.31.0)\n", + "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (8.2.3)\n", + "Requirement already satisfied: tiktoken>=0.3.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.6.0)\n", + "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (4.66.2)\n", + "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (4.11.0)\n", + "Requirement already satisfied: typing-inspect>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.9.0)\n", + "Requirement already satisfied: wrapt in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.14.1)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.3.1)\n", + "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (23.2.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (6.0.5)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.9.4)\n", + "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (4.0.3)\n", + "Requirement already satisfied: pydantic>=1.10 in /usr/local/lib/python3.10/dist-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.7.0)\n", + "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.7.1)\n", + "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2024.2.2)\n", + "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.0.5)\n", + "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.7)\n", + "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.3.1)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.14.0)\n", + "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (8.1.7)\n", + "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.4.0)\n", + "Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2023.12.25)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.1.0->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.7.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.3.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.0.7)\n", + "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.0.3)\n", + "Requirement already satisfied: mypy-extensions>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.0.0)\n", + "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (3.21.1)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.8.2)\n", + "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2023.4)\n", + "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2024.1)\n", + "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.2.0)\n", + "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.10/dist-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (24.0)\n", + "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.18.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (2.18.1)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.24->llama-index-llms-openai) (1.16.0)\n", + "Collecting llama-index-postprocessor-colbert-rerank\n", + " Downloading llama_index_postprocessor_colbert_rerank-0.1.1-py3-none-any.whl (3.4 kB)\n", + "Requirement already satisfied: llama-index-core<0.11.0,>=0.10.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-postprocessor-colbert-rerank) (0.10.30)\n", + "Requirement already satisfied: torch<3.0.0,>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-postprocessor-colbert-rerank) (2.2.1+cu121)\n", + "Requirement already satisfied: transformers<5.0.0,>=4.37.2 in /usr/local/lib/python3.10/dist-packages (from llama-index-postprocessor-colbert-rerank) (4.38.2)\n", + "Requirement already satisfied: PyYAML>=6.0.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (6.0.1)\n", + "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.0.29)\n", + "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.9.5)\n", + "Requirement already satisfied: dataclasses-json in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.6.4)\n", + "Requirement already satisfied: deprecated>=1.2.9.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.2.14)\n", + "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.0.8)\n", + "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2023.6.0)\n", + "Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.27.0)\n", + "Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.1.18)\n", + "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.6.0)\n", + "Requirement already satisfied: networkx>=3.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.3)\n", + "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.8.1)\n", + "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.25.2)\n", + "Requirement already satisfied: openai>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.22.0)\n", + "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.0.3)\n", + "Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (9.4.0)\n", + "Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.31.0)\n", + "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (8.2.3)\n", + "Requirement already satisfied: tiktoken>=0.3.3 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.6.0)\n", + "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (4.66.2)\n", + "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (4.11.0)\n", + "Requirement already satisfied: typing-inspect>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.9.0)\n", + "Requirement already satisfied: wrapt in /usr/local/lib/python3.10/dist-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.14.1)\n", + "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (3.13.4)\n", + "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (1.12)\n", + "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (3.1.3)\n", + "Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.105)\n", + "Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.105)\n", + "Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.105)\n", + "Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (8.9.2.26)\n", + "Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.3.1)\n", + "Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (11.0.2.54)\n", + "Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (10.3.2.106)\n", + "Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (11.4.5.107)\n", + "Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.0.106)\n", + "Requirement already satisfied: nvidia-nccl-cu12==2.19.3 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (2.19.3)\n", + "Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.1.105)\n", + "Requirement already satisfied: triton==2.2.0 in /usr/local/lib/python3.10/dist-packages (from torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (2.2.0)\n", + "Requirement already satisfied: nvidia-nvjitlink-cu12 in /usr/local/lib/python3.10/dist-packages (from nvidia-cusolver-cu12==11.4.5.107->torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (12.4.127)\n", + "Requirement already satisfied: huggingface-hub<1.0,>=0.19.3 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.37.2->llama-index-postprocessor-colbert-rerank) (0.20.3)\n", + "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.37.2->llama-index-postprocessor-colbert-rerank) (24.0)\n", + "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.37.2->llama-index-postprocessor-colbert-rerank) (2023.12.25)\n", + "Requirement already satisfied: tokenizers<0.19,>=0.14 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.37.2->llama-index-postprocessor-colbert-rerank) (0.15.2)\n", + "Requirement already satisfied: safetensors>=0.4.1 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.37.2->llama-index-postprocessor-colbert-rerank) (0.4.3)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.3.1)\n", + "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (23.2.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (6.0.5)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.9.4)\n", + "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (4.0.3)\n", + "Requirement already satisfied: pydantic>=1.10 in /usr/local/lib/python3.10/dist-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.7.0)\n", + "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.7.1)\n", + "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2024.2.2)\n", + "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.0.5)\n", + "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.7)\n", + "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.3.1)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.14.0)\n", + "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (8.1.7)\n", + "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.4.0)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.1.0->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.7.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.3.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.0.7)\n", + "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.0.3)\n", + "Requirement already satisfied: mypy-extensions>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.0.0)\n", + "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (3.21.1)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (2.1.5)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.8.2)\n", + "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2023.4)\n", + "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2024.1)\n", + "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch<3.0.0,>=2.2.0->llama-index-postprocessor-colbert-rerank) (1.3.0)\n", + "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.2.0)\n", + "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.18.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (2.18.1)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-postprocessor-colbert-rerank) (1.16.0)\n", + "Installing collected packages: llama-index-postprocessor-colbert-rerank\n", + "Successfully installed llama-index-postprocessor-colbert-rerank-0.1.1\n" + ] + } + ], + "source": [ + "!pip install llama-index\n", + "!pip install llama-index-core\n", + "!pip install --quiet transformers torch\n", + "!pip install llama-index-embeddings-openai\n", + "!pip install llama-index-llms-openai\n", + "!pip install llama-index-postprocessor-colbert-rerank" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.core import (\n", + " VectorStoreIndex,\n", + " SimpleDirectoryReader,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Download Data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "os.environ[\"OPENAI_API_KEY\"] = \"sk-\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# TO-DO: GET THE DOCUMENTS FROM ROUTING AGENT - all the answers in paragraph form in one document\n", + "!mkdir -p 'data/routing_agent/'\n", + "#!wget 'https://raw.githubusercontent.com/aishwarya-balaji/reranking/main/data/data8/data8.txt' -O 'data/data8/data8.txt'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# TO-DO: GET THE DOCUMENTS FROM ROUTING AGENT - all the answers in paragraph form in one document\n", + "with open(\"./data/routing_agent/routing_agent.txt\", \"r\") as file:\n", + " # Read the entire file content into a string\n", + " response_options = file.read()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "documents = SimpleDirectoryReader(\"./data/routing_agent/\").load_data()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.core.node_parser import SentenceWindowNodeParser\n", + "\n", + "node_parser = SentenceWindowNodeParser.from_defaults(\n", + " window_size=3,\n", + " window_metadata_key=\"window\",\n", + " original_text_metadata_key=\"original_text\",\n", + ")\n", + "\n", + "nodes = node_parser.get_nodes_from_documents(documents)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.core.node_parser import SentenceSplitter\n", + "\n", + "text_splitter = SentenceSplitter()\n", + "base_nodes = text_splitter.get_nodes_from_documents(documents)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sentence_index = VectorStoreIndex(nodes)\n", + "base_index = VectorStoreIndex(base_nodes)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Retrieve top 10 most relevant nodes, then filter with Colbert Rerank" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.postprocessor.colbert_rerank import ColbertRerank\n", + "\n", + "colbert_reranker = ColbertRerank(\n", + " top_n=3, # will be equal to how many tools are executed\n", + " model=\"colbert-ir/colbertv2.0\",\n", + " tokenizer=\"colbert-ir/colbertv2.0\",\n", + " keep_retrieval_score=True,\n", + ")\n", + "\n", + "query_engine = sentence_index.as_query_engine(\n", + " similarity_top_k=3,\n", + " node_postprocessors=[colbert_reranker],\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# To Do: GET THE ORIGINAL QUERY FROM QD - get that from another file, so read the document\n", + "with open(\"original_query.txt\", \"r\") as file:\n", + " # Read the entire file content into a string\n", + " original_query = file.read()\n", + "\n", + "response = query_engine.query(\n", + " original_query,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 62, - "metadata": { - "id": "NnMFG9fRZstN" - }, - "outputs": [], - "source": [ - "response = str(response)" - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "Total nodes in response: 3\n" + ] + } + ], + "source": [ + "print(\n", + " \"Total nodes in response:\", len(response.source_nodes)\n", + ") # This will print how many nodes are there" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "source": [ - "#Write response to another file\n", - "\n", - "with open(\"reranking_result.txt\", \"w\") as file:\n", - " file.write(response)" - ], - "metadata": { - "id": "I-YqE1VKn5te" - }, - "execution_count": 63, - "outputs": [] + "name": "stdout", + "output_type": "stream", + "text": [ + "b22c4ae8-2c0d-4255-b790-8e90ca60f3f0\n", + "Known as the \"City of Light,\" Paris is celebrated for its romantic ambiance, iconic landmarks like the Eiffel Tower and Notre-Dame Cathedral, world-cl\n", + "reranking score: 0.7583699226379395\n", + "retrieval score: 0.8774996666312472\n", + "**********\n", + "f5b56c8c-3c02-4773-aaa0-6d658e22548d\n", + "The Eiffel Tower, one of the most famous landmarks in the world, stands as an enduring symbol of Paris. \n", + "reranking score: 0.6390765309333801\n", + "retrieval score: 0.8489044372934368\n", + "**********\n", + "00170fbf-3c0d-448b-931d-5a5eb06008a9\n", + "Famous for its stunning sunsets, whitewashed buildings, blue-domed churches, and crystalline waters, Santorini is a dream destination for honeymooners\n", + "reranking score: 0.6205340623855591\n", + "retrieval score: 0.7898268505796289\n", + "**********\n" + ] } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3" - }, - "colab": { - "provenance": [] + ], + "source": [ + "# TO DO: figure out how to access scores for all nodes\n", + "for node in response.source_nodes:\n", + " print(node.id_)\n", + " print(\n", + " node.node.get_content()[:150]\n", + " ) # number of characters - but not the paragraphs\n", + " print(\"reranking score: \", node.score)\n", + " print(\"retrieval score: \", node.node.metadata[\"retrieval_score\"])\n", + " print(\"**********\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Paris is known for its romantic ambiance, iconic landmarks like the Eiffel Tower and Notre-Dame Cathedral, world-class museums such as the Louvre and Musée d'Orsay, and charming neighborhoods like Montmartre and Le Marais.\n" + ] } + ], + "source": [ + "print(response)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "response = str(response)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Write response to another file\n", + "\n", + "with open(\"reranking_result.txt\", \"w\") as file:\n", + " file.write(response)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/pyproject.toml b/pyproject.toml index e1ed3e50..63f50eea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = [ - "hatchling", + "hatchling" ] build-backend = "hatchling.build" @@ -8,45 +8,45 @@ build-backend = "hatchling.build" name = "memary" version = "0.1.2" authors = [ - { name="memary Labs", email="hello@memarylabs.com" }, + {name = "memary Labs", email = "hello@memarylabs.com"} ] description = "Longterm Memory for Autonomous Agents" readme = "README_hidden.md" requires-python = ">=3.8, <=3.11.9" classifiers = [ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent" ] dependencies = [ - "neo4j==5.17.0", - "python-dotenv==1.0.1", - "pyvis==0.3.2", - "streamlit==1.31.1", - "llama-index==0.10.11", - "llama-index-agent-openai==0.1.5", - "llama-index-core==0.10.12", - "llama-index-embeddings-openai==0.1.5", - "llama-index-graph-stores-nebula==0.1.2", - "llama-index-graph-stores-neo4j==0.1.1", - "llama-index-legacy==0.9.48", - "llama-index-llms-openai==0.1.5", - "llama-index-multi-modal-llms-openai==0.1.3", - "llama-index-program-openai==0.1.3", - "llama-index-question-gen-openai==0.1.2", - "llama-index-readers-file==0.1.4", - "langchain==0.1.12", - "langchain-openai==0.0.8", - "llama-index-llms-perplexity==0.1.3", - "llama-index-multi-modal-llms-ollama==0.1.3", - "llama-index-llms-ollama==0.1.2", - "pandas", - "geocoder", - "googlemaps", - "ansistrip", - "numpy", + "neo4j==5.17.0", + "python-dotenv==1.0.1", + "pyvis==0.3.2", + "streamlit==1.31.1", + "llama-index==0.10.11", + "llama-index-agent-openai==0.1.5", + "llama-index-core==0.10.12", + "llama-index-embeddings-openai==0.1.5", + "llama-index-graph-stores-nebula==0.1.2", + "llama-index-graph-stores-neo4j==0.1.1", + "llama-index-legacy==0.9.48", + "llama-index-llms-openai==0.1.5", + "llama-index-multi-modal-llms-openai==0.1.3", + "llama-index-program-openai==0.1.3", + "llama-index-question-gen-openai==0.1.2", + "llama-index-readers-file==0.1.4", + "langchain==0.1.12", + "langchain-openai==0.0.8", + "llama-index-llms-perplexity==0.1.3", + "llama-index-multi-modal-llms-ollama==0.1.3", + "llama-index-llms-ollama==0.1.2", + "pandas", + "geocoder", + "googlemaps", + "ansistrip", + "numpy" ] [project.urls] Homepage = "https://github.com/kingjulio8238/memary" -Issues = "https://github.com/kingjulio8238/memary/issues" \ No newline at end of file +Issues = "https://github.com/kingjulio8238/memary/issues" diff --git a/requirements.txt b/requirements.txt index 79e3f669..b02f5761 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,4 +24,4 @@ geocoder googlemaps ansistrip numpy -ollama \ No newline at end of file +ollama diff --git a/src/memary/__init__.py b/src/memary/__init__.py index e69de29b..1cf2dc89 100644 --- a/src/memary/__init__.py +++ b/src/memary/__init__.py @@ -0,0 +1,5 @@ +from memary.agent.chat_agent import ChatAgent +from memary.memory.memory_stream import MemoryStream +from memary.memory.entity_knowledge_store import EntityKnowledgeStore + +__all__ = ["ChatAgent", "MemoryStream", "EntityKnowledgeStore"] diff --git a/src/memary/agent/__init__.py b/src/memary/agent/__init__.py index e69de29b..4d5e5979 100644 --- a/src/memary/agent/__init__.py +++ b/src/memary/agent/__init__.py @@ -0,0 +1,18 @@ +from memary.agent.base_agent import Agent +from memary.agent.chat_agent import ChatAgent +from memary.agent.llm_api.tools import ( + ollama_chat_completions_request, + openai_chat_completions_request, +) +from memary.memory import EntityKnowledgeStore, MemoryStream +from memary.synonym_expand.synonym import custom_synonym_expand_fn + +__all__ = [ + "Agent", + "ChatAgent", + "EntityKnowledgeStore", + "MemoryStream", + "ollama_chat_completions_request", + "openai_chat_completions_request", + "custom_synonym_expand_fn", +] diff --git a/src/memary/agent/base_agent.py b/src/memary/agent/base_agent.py index a63a12fa..295a20fc 100644 --- a/src/memary/agent/base_agent.py +++ b/src/memary/agent/base_agent.py @@ -10,8 +10,12 @@ import requests from ansistrip import ansi_strip from dotenv import load_dotenv -from llama_index.core import (KnowledgeGraphIndex, Settings, - SimpleDirectoryReader, StorageContext) +from llama_index.core import ( + KnowledgeGraphIndex, + Settings, + SimpleDirectoryReader, + StorageContext, +) from llama_index.core.agent import ReActAgent from llama_index.core.llms import ChatMessage from llama_index.core.query_engine import RetrieverQueryEngine @@ -25,8 +29,10 @@ from llama_index.multi_modal_llms.openai import OpenAIMultiModal from memary.agent.data_types import Context, Message -from memary.agent.llm_api.tools import (ollama_chat_completions_request, - openai_chat_completions_request) +from memary.agent.llm_api.tools import ( + ollama_chat_completions_request, + openai_chat_completions_request, +) from memary.memory import EntityKnowledgeStore, MemoryStream from memary.synonym_expand.synonym import custom_synonym_expand_fn @@ -47,7 +53,7 @@ def generate_string(entities): return cypher_query -class Agent(object): +class Agent: """Agent manages the RAG model, the ReAct agent, and the memory stream.""" def __init__( @@ -62,7 +68,7 @@ def __init__( vision_model_name="llava", include_from_defaults=["search", "locate", "vision", "stocks"], debug=True, - ): + ) -> None: load_dotenv() self.name = name self.model = llm_model_name @@ -107,9 +113,7 @@ def __init__( synonym_expand_fn=custom_synonym_expand_fn, ) - self.query_engine = RetrieverQueryEngine.from_args( - graph_rag_retriever, - ) + self.query_engine = RetrieverQueryEngine.from_args(graph_rag_retriever) self.debug = debug self.tools = {} @@ -122,7 +126,7 @@ def __init__( system_persona_txt, user_persona_txt, past_chat_json, self.model ) - def __str__(self): + def __str__(self) -> str: return f"Agent {self.name}" def load_llm_model(self, llm_model_name): @@ -134,8 +138,8 @@ def load_llm_model(self, llm_model_name): else: try: self.llm = Ollama(model=llm_model_name, request_timeout=60.0) - except: - raise ("Please provide a proper llm_model_name.") + except Exception: + raise ValueError("Please provide a proper llm_model_name.") def load_vision_model(self, vision_model_name): if vision_model_name == "gpt-4-vision-preview": @@ -149,8 +153,8 @@ def load_vision_model(self, vision_model_name): else: try: self.mm_model = OllamaMultiModal(model=vision_model_name) - except: - raise ("Please provide a proper vision_model_name.") + except Exception: + raise ValueError("Please provide a proper vision_model_name.") def external_query(self, query: str): messages_dict = [ @@ -163,7 +167,7 @@ def external_query(self, query: str): return str(external_response) def search(self, query: str) -> str: - """Search the knowledge graph or perform search on the web if information is not present in the knowledge graph""" + """Search the knowledge graph or perform search on the web if information is not present in the knowledge graph.""" response = self.query_engine.query(query) if response.metadata is None: @@ -172,16 +176,16 @@ def search(self, query: str) -> str: return response def locate(self, query: str) -> str: - """Finds the current geographical location""" + """Finds the current geographical location.""" location = geocoder.ip("me") - lattitude, longitude = location.latlng[0], location.latlng[1] + latitude, longitude = location.latlng[0], location.latlng[1] - reverse_geocode_result = self.gmaps.reverse_geocode((lattitude, longitude)) + reverse_geocode_result = self.gmaps.reverse_geocode((latitude, longitude)) formatted_address = reverse_geocode_result[0]["formatted_address"] return "Your address is" + formatted_address def vision(self, query: str, img_url: str) -> str: - """Uses computer vision to process the image specified by the image url and answers the question based on the CV results""" + """Uses computer vision to process the image specified by the image url and answers the question based on the CV results.""" query_image_dir_path = Path("query_images") if not query_image_dir_path.exists(): Path.mkdir(query_image_dir_path) @@ -198,7 +202,7 @@ def vision(self, query: str, img_url: str) -> str: return response def stocks(self, query: str) -> str: - """Get the stock price of the company given the ticker""" + """Get the stock price of the company given the ticker.""" request_api = requests.get( r"https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=" + query @@ -248,7 +252,7 @@ def check_KG(self, query: str) -> bool: if response.metadata is None: return False return generate_string( - list(list(response.metadata.values())[0]["kg_rel_map"].keys()) + list(next(iter(response.metadata.values()))["kg_rel_map"].keys()) ) def _select_top_entities(self): @@ -390,7 +394,7 @@ def get_routing_agent_response(self, query, return_entity=False): return response def get_entity(self, retrieve) -> list[str]: - """retrieve is a list of QueryBundle objects. + """Retrieve is a list of QueryBundle objects. A retrieved QueryBundle object has a "node" attribute, which has a "metadata" attribute. @@ -405,7 +409,6 @@ def get_entity(self, retrieve) -> list[str]: return: list[str]: list of string entities """ - entities = [] kg_rel_map = retrieve[0].node.metadata["kg_rel_map"] for key, items in kg_rel_map.items(): @@ -431,10 +434,10 @@ def _init_ReAct_agent(self): def _init_default_tools(self, default_tools: List[str]): """Initializes ReAct Agent from the default list of tools memary provides. List of strings passed in during initialization denoting which default tools to include. + Args: default_tools (list(str)): list of tool names in string form """ - for tool in default_tools: if tool == "search": self.tools["search"] = self.search @@ -448,20 +451,20 @@ def _init_default_tools(self, default_tools: List[str]): def add_tool(self, tool_additions: Dict[str, Callable[..., Any]]): """Adds specified tools to be used by the ReAct Agent. + Args: tools (dict(str, func)): dictionary of tools with names as keys and associated functions as values """ - for tool_name in tool_additions: self.tools[tool_name] = tool_additions[tool_name] self._init_ReAct_agent() def remove_tool(self, tool_name: str): """Removes specified tool from list of available tools for use by the ReAct Agent. + Args: tool_name (str): name of tool to be removed in string form """ - if tool_name in self.tools: del self.tools[tool_name] self._init_ReAct_agent() @@ -470,10 +473,10 @@ def remove_tool(self, tool_name: str): def update_tools(self, updated_tools: List[str]): """Resets ReAct Agent tools to only include subset of default tools. + Args: updated_tools (list(str)): list of default tools to include """ - self.tools.clear() for tool in updated_tools: if tool == "search": diff --git a/src/memary/agent/chat_agent.py b/src/memary/agent/chat_agent.py index 814068a6..457c1aea 100644 --- a/src/memary/agent/chat_agent.py +++ b/src/memary/agent/chat_agent.py @@ -20,7 +20,7 @@ def __init__( llm_model_name="llama3", vision_model_name="llava", include_from_defaults=["search", "locate", "vision", "stocks"], - ): + ) -> None: super().__init__( name, memory_stream_json, @@ -58,7 +58,6 @@ def get_chat(self): def clearMemory(self): """Clears Neo4j database and memory stream/entity knowledge store.""" - logging.info("Deleting memory stream and entity knowledge store...") self.memory_stream.clear_memory() self.entity_knowledge_store.clear_memory() @@ -75,9 +74,7 @@ def _replace_memory_from_llm_message(self): self.message.llm_message["memory_stream"] = self.memory_stream.get_memory() def _replace_eks_to_from_message(self): - """Replace the entity knowledge store from the llm_message. - eks = entity knowledge store""" - - self.message.llm_message["knowledge_entity_store"] = ( - self.entity_knowledge_store.get_memory() - ) + """Replace the entity knowledge store from the llm_message. eks means entity knowledge store.""" + self.message.llm_message[ + "knowledge_entity_store" + ] = self.entity_knowledge_store.get_memory() diff --git a/src/memary/agent/data_types.py b/src/memary/agent/data_types.py index 7b8a8033..2e87c65e 100644 --- a/src/memary/agent/data_types.py +++ b/src/memary/agent/data_types.py @@ -11,20 +11,23 @@ def save_json(filename, data): @dataclass class Context: """Context class to store the role and content of the message.""" + role: str # system or user content: str - def __str__(self): + def __str__(self) -> str: return f"{self.role}: {self.content} |" def to_dict(self): - return {'role': self.role, 'content': self.content} + return {"role": self.role, "content": self.content} class Message: """Message class to store the contexts, memory stream and knowledge entity store.""" - def __init__(self, system_persona_txt, user_persona_txt, past_chat_json, model): + def __init__( + self, system_persona_txt, user_persona_txt, past_chat_json, model + ) -> None: self.past_chat_json = past_chat_json self.contexts = [] @@ -37,19 +40,19 @@ def __init__(self, system_persona_txt, user_persona_txt, past_chat_json, model): "model": model, "messages": self.contexts, "memory_stream": [], - "knowledge_entity_store": [] + "knowledge_entity_store": [], } # self.prompt_tokens = count_tokens(self.contexts) - def __str__(self): + def __str__(self) -> str: llm_message_str = f"System Persona: {self.system_persona}\nUser Persona: {self.user_persona}\n" for context in self.contexts: - llm_message_str += f"{str(context)}," + llm_message_str += f"{context!s}," for memory in self.llm_message["memory_stream"]: - llm_message_str += f"{str(memory)}," + llm_message_str += f"{memory!s}," for entity in self.llm_message["knowledge_entity_store"]: - llm_message_str += f"{str(entity)}," + llm_message_str += f"{entity!s}," return llm_message_str def _init_persona_to_messages(self): @@ -67,20 +70,19 @@ def load_persona(self, persona_txt) -> str: str: persona """ try: - with open(persona_txt, "r") as file: - persona = file.read() - return persona + with open(persona_txt) as file: + return file.read() except FileNotFoundError: logging.info(f"{persona_txt} file does not exist.") def load_contexts_from_json(self): """Loads the contexts from the past chat json file.""" try: - with open(self.past_chat_json, "r") as file: + with open(self.past_chat_json) as file: data_dicts = json.load(file) return [Context(**data_dict) for data_dict in data_dicts] - except: + except FileNotFoundError: logging.info( f"{self.past_chat_json} file does not exist. Starts from empty contexts." ) @@ -88,6 +90,9 @@ def load_contexts_from_json(self): def save_contexts_to_json(self): """Saves the contexts to the json file. - We don't save the system and user personas (first two messages) + We don't save the system and user personas (first two messages). """ - save_json(self.past_chat_json, [message.to_dict() for message in self.llm_message['messages'][2:]]) + save_json( + self.past_chat_json, + [message.to_dict() for message in self.llm_message["messages"][2:]], + ) diff --git a/src/memary/agent/llm_api/tools.py b/src/memary/agent/llm_api/tools.py index 135976fe..38d76dbb 100644 --- a/src/memary/agent/llm_api/tools.py +++ b/src/memary/agent/llm_api/tools.py @@ -6,15 +6,14 @@ def smart_urljoin(base_url, relative_url): - """urljoin is stupid and wants a trailing / at the end of the endpoint address, or it will chop the suffix off""" + """Urljoin is stupid and wants a trailing / at the end of the endpoint address, or it will chop the suffix off.""" if not base_url.endswith("/"): base_url += "/" return urllib.parse.urljoin(base_url, relative_url) def openai_chat_completions_request(url, api_key, data): - """text-generation?lang=curl""" - + """text-generation?lang=curl.""" url = smart_urljoin(url, "chat/completions") headers = {"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"} @@ -40,20 +39,19 @@ def openai_chat_completions_request(url, api_key, data): except requests.exceptions.HTTPError as http_err: # Handle HTTP errors (e.g., response 4XX, 5XX) logging.error(f"Got HTTPError, exception={http_err}, payload={data}") - raise http_err + raise except requests.exceptions.RequestException as req_err: # Handle other requests-related errors (e.g., connection error) logging.warning(f"Got RequestException, exception={req_err}") - raise req_err + raise except Exception as e: # Handle other potential errors logging.warning(f"Got unknown Exception, exception={e}") - raise e + raise def ollama_chat_completions_request(messages, model): - """sends chat request to model running on Ollama""" - + """Sends chat request to model running on Ollama.""" url = "http://localhost:11434/api/chat" data = {"model": model, "messages": messages, "stream": False} @@ -68,12 +66,12 @@ def ollama_chat_completions_request(messages, model): except requests.exceptions.HTTPError as http_err: # Handle HTTP errors (e.g., response 4XX, 5XX) logging.error(f"Got HTTPError, exception={http_err}, payload={data}") - raise http_err + raise except requests.exceptions.RequestException as req_err: # Handle other requests-related errors (e.g., connection error) logging.warning(f"Got RequestException, exception={req_err}") - raise req_err + raise except Exception as e: # Handle other potential errors logging.warning(f"Got unknown Exception, exception={e}") - raise e + raise diff --git a/src/memary/memory/base_memory.py b/src/memary/memory/base_memory.py index c2733aff..9d429cdb 100644 --- a/src/memary/memory/base_memory.py +++ b/src/memary/memory/base_memory.py @@ -6,7 +6,6 @@ class BaseMemory(ABC): - def __init__(self, file_name: str, entity: str = None): """Initializes the memory storage.""" self.file_name = file_name @@ -16,24 +15,20 @@ def __init__(self, file_name: str, entity: str = None): self.init_memory() @abstractmethod - def __len__(self): + def __len__(self) -> int: """Returns the number of items in the memory.""" - pass @abstractmethod def init_memory(self): """Initializes memory.""" - pass @abstractmethod def load_memory_from_file(self): """Loads memory from a file.""" - pass @abstractmethod def add_memory(self, data): """Adds new memory data.""" - pass @abstractmethod def get_memory(self): @@ -46,18 +41,18 @@ def return_memory(self): def remove_old_memory(self, days): """Removes memory items older than a specified number of days.""" cutoff_date = datetime.now() - timedelta(days=days) - self.memory = [ - item for item in self.return_memory if item.date >= cutoff_date - ] + self.memory = [item for item in self.return_memory if item.date >= cutoff_date] logging.info("Old memory removed successfully.") def save_memory(self): if self.file_name: - with open(self.file_name, 'w') as file: - json.dump([item.to_dict() for item in self.return_memory], - file, - default=str, - indent=4) + with open(self.file_name, "w") as file: + json.dump( + [item.to_dict() for item in self.return_memory], + file, + default=str, + indent=4, + ) logging.info(f"Memory saved to {self.file_name} successfully.") else: logging.info("No file name provided. Memory not saved.") @@ -80,8 +75,10 @@ def remove_memory_by_index(self, index): def clear_memory(self): self.memory = [] if self.file_name: - with open(self.file_name, 'w') as file: - json.dump([], file, indent=4) - logging.info(f"Memory cleared and saved to {self.file_name} successfully.") + with open(self.file_name, "w") as file: + json.dump([], file, indent=4) + logging.info( + f"Memory cleared and saved to {self.file_name} successfully." + ) else: logging.info("No file name provided. Memory not cleared or saved.") diff --git a/src/memary/memory/entity_knowledge_store.py b/src/memary/memory/entity_knowledge_store.py index ca08f2d7..76bd9edb 100644 --- a/src/memary/memory/entity_knowledge_store.py +++ b/src/memary/memory/entity_knowledge_store.py @@ -6,13 +6,13 @@ class EntityKnowledgeStore(BaseMemory): - - def __len__(self): + def __len__(self) -> int: """Returns the number of items in the memory.""" return len(self.knowledge_memory) def init_memory(self): """Initializes memory. + self.entity_memory: list[EntityMemoryItem] """ self.load_memory_from_file() @@ -23,13 +23,11 @@ def init_memory(self): def return_memory(self): return self.knowledge_memory - def load_memory_from_file(self): try: - with open(self.file_name, 'r') as file: + with open(self.file_name) as file: self.knowledge_memory = [ - KnowledgeMemoryItem.from_dict(item) - for item in json.load(file) + KnowledgeMemoryItem.from_dict(item) for item in json.load(file) ] logging.info( f"Entity Knowledge Memory loaded from {self.file_name} successfully." @@ -40,19 +38,18 @@ def load_memory_from_file(self): ) def add_memory(self, memory_stream: list[MemoryItem]): - """To add new memory to the entity knowledge store - we should convert the memory to knowledge memory and then update the knowledge memory + """Add new memory to the entity knowledge store. + + We should convert the memory to knowledge memory and then update the knowledge memory. Args: memory_stream (list): list of MemoryItem """ - knowledge_meory = self._convert_memory_to_knowledge_memory( - memory_stream) + knowledge_meory = self._convert_memory_to_knowledge_memory(memory_stream) self._update_knowledge_memory(knowledge_meory) - def _update_knowledge_memory(self, knowledge_memory: list): - """update self.knowledge memory with new knowledge memory items + """Update self.knowledge memory with new knowledge memory items. Args: knowledge_memory (list): list of KnowledgeMemoryItem @@ -67,26 +64,24 @@ def _update_knowledge_memory(self, knowledge_memory: list): self.knowledge_memory.append(item) def _convert_memory_to_knowledge_memory( - self, memory_stream: list) -> list[KnowledgeMemoryItem]: - """Converts memory to knowledge memory + self, memory_stream: list + ) -> list[KnowledgeMemoryItem]: + """Converts memory to knowledge memory. Returns: knowledge_memory (list): list of KnowledgeMemoryItem """ knowledge_memory = [] - entities = set([item.entity for item in memory_stream]) + entities = {item.entity for item in memory_stream} for entity in entities: memory_dates = [ item.date for item in memory_stream if item.entity == entity ] knowledge_memory.append( - KnowledgeMemoryItem(entity, len(memory_dates), - max(memory_dates))) + KnowledgeMemoryItem(entity, len(memory_dates), max(memory_dates)) + ) return knowledge_memory def get_memory(self) -> list[KnowledgeMemoryItem]: return self.knowledge_memory - - - diff --git a/src/memary/memory/memory_stream.py b/src/memary/memory/memory_stream.py index e99b2dd8..acf8da18 100644 --- a/src/memary/memory/memory_stream.py +++ b/src/memary/memory/memory_stream.py @@ -9,13 +9,13 @@ class MemoryStream(BaseMemory): - - def __len__(self): + def __len__(self) -> int: """Returns the number of items in the memory.""" return len(self.memory) def init_memory(self): - """Initializes memory + """Initializes memory. + self.memory: list[MemoryItem] """ self.load_memory_from_file() @@ -27,22 +27,20 @@ def return_memory(self): return self.memory def add_memory(self, entities): - self.memory.extend([ - MemoryItem(str(entity), - datetime.now().replace(microsecond=0)) - for entity in entities - ]) + self.memory.extend( + [ + MemoryItem(str(entity), datetime.now().replace(microsecond=0)) + for entity in entities + ] + ) def get_memory(self) -> list[MemoryItem]: return self.memory - def load_memory_from_file(self): try: - with open(self.file_name, 'r') as file: - self.memory = [ - MemoryItem.from_dict(item) for item in json.load(file) - ] + with open(self.file_name) as file: + self.memory = [MemoryItem.from_dict(item) for item in json.load(file)] logging.info(f"Memory loaded from {self.file_name} successfully.") except FileNotFoundError: logging.info("File not found. Starting with an empty memory.") diff --git a/src/memary/memory/types.py b/src/memary/memory/types.py index 691990ea..ae3d1c99 100644 --- a/src/memary/memory/types.py +++ b/src/memary/memory/types.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass, asdict +from dataclasses import dataclass from datetime import datetime @@ -7,16 +7,15 @@ class MemoryItem: entity: str date: datetime - def __str__(self): + def __str__(self) -> str: return f"{self.entity}, {self.date.isoformat()}" def to_dict(self): - return {'entity': self.entity, 'date': str(self.date.isoformat())} + return {"entity": self.entity, "date": str(self.date.isoformat())} @classmethod def from_dict(cls, data): - return cls(entity=data['entity'], - date=datetime.fromisoformat(data['date'])) + return cls(entity=data["entity"], date=datetime.fromisoformat(data["date"])) @dataclass @@ -25,18 +24,20 @@ class KnowledgeMemoryItem: count: int date: datetime - def __str__(self): + def __str__(self) -> str: return f"{self.entity}, {self.count}, {self.date.isoformat()}" def to_dict(self): return { - 'entity': self.entity, - 'count': self.count, - 'date': str(self.date.isoformat()) + "entity": self.entity, + "count": self.count, + "date": str(self.date.isoformat()), } @classmethod def from_dict(cls, data): - return cls(entity=data['entity'], - count=data['count'], - date=datetime.fromisoformat(data['date'])) + return cls( + entity=data["entity"], + count=data["count"], + date=datetime.fromisoformat(data["date"]), + ) diff --git a/src/memary/synonym_expand/__init__.py b/src/memary/synonym_expand/__init__.py index e69de29b..0ade079d 100644 --- a/src/memary/synonym_expand/__init__.py +++ b/src/memary/synonym_expand/__init__.py @@ -0,0 +1,4 @@ +from memary.synonym_expand.synonym import custom_synonym_expand_fn +from memary.synonym_expand.output import SynonymOutput + +__all__ = ["custom_synonym_expand_fn", "SynonymOutput"] diff --git a/src/memary/synonym_expand/output.py b/src/memary/synonym_expand/output.py index 28348c7c..2b787eb2 100644 --- a/src/memary/synonym_expand/output.py +++ b/src/memary/synonym_expand/output.py @@ -3,5 +3,7 @@ from langchain_core.pydantic_v1 import BaseModel, Field -class Output(BaseModel): - synonyms: List[str] = Field(description="Synonyms of keywords provided, make every letter lowercase except for the first letter") +class SynonymOutput(BaseModel): + synonyms: List[str] = Field( + description="Synonyms of keywords provided, make every letter lowercase except for the first letter" + ) diff --git a/src/memary/synonym_expand/synonym.py b/src/memary/synonym_expand/synonym.py index 94d2113f..dc6b2ff3 100644 --- a/src/memary/synonym_expand/synonym.py +++ b/src/memary/synonym_expand/synonym.py @@ -3,23 +3,24 @@ from langchain_core.output_parsers import JsonOutputParser from typing import List import os -from memary.synonym_expand.output import Output +from memary.synonym_expand.output import SynonymOutput from dotenv import load_dotenv + def custom_synonym_expand_fn(keywords: str) -> List[str]: load_dotenv() llm = OpenAI(openai_api_key=os.getenv("OPENAI_KEY"), temperature=0) - parser = JsonOutputParser(pydantic_object=Output) + parser = JsonOutputParser(pydantic_object=SynonymOutput) template = """ - You are an expert synonym exapnding system. Find synonyms or words commonly used in place to reference the same word for every word in the list: + You are an expert synonym expanding system. Find synonyms or words commonly used in place to reference the same word for every word in the list: Some examples are: - a synonym for Palantir may be Palantir technologies or Palantir technologies inc. - a synonym for Austin may be Austin texas - - a synonym for Taylor swift may be Taylor + - a synonym for Taylor swift may be Taylor - a synonym for Winter park may be Winter park resort - + Format: {format_instructions} Text: {keywords} @@ -34,12 +35,13 @@ def custom_synonym_expand_fn(keywords: str) -> List[str]: chain = prompt | llm | parser result = chain.invoke({"keywords": keywords}) - l = [] + synonyms_list = [] for category in result: for synonym in result[category]: - l.append(synonym.capitalize()) + synonyms_list.append(synonym.capitalize()) + + return synonyms_list - return l # testing # print(custom_synonym_expand_fn("[Nvidia]")) diff --git a/streamlit_app/app.py b/streamlit_app/app.py index e08d2ea1..3b7a9289 100644 --- a/streamlit_app/app.py +++ b/streamlit_app/app.py @@ -1,6 +1,4 @@ -import os import random -import sys import textwrap import ollama @@ -11,14 +9,7 @@ from neo4j import GraphDatabase from pyvis.network import Network -# src should sit in the same level as /streamlit_app -curr_dir = os.getcwd() - -parent_dir = os.path.dirname(curr_dir) -# parent_dir = os.path.dirname(curr_dir) + '/memary' #Use this if error: src not found. Also move the '/streamlit_app/data' folder to the 'memary' folder, outside the 'src' folder. - -sys.path.append(parent_dir + "/src") - +# Test the streamlit app after installing memary from memary.agent.chat_agent import ChatAgent load_dotenv() @@ -93,9 +84,10 @@ def get_models(llm_models, vision_models): vision_models.append("llava:latest") models.remove("llava:latest") llm_models.extend(list(models)) - except: + except Exception: print("No Ollama instance detected.") + cypher_query = "MATCH p = (:Entity)-[r]-() RETURN p, r LIMIT 1000;" answer = "" external_response = "" @@ -136,9 +128,14 @@ def get_models(llm_models, vision_models): tools = st.multiselect( "Select tools to include:", - ["search", "locate", "vision", "stocks"], # all options available - ["search", "locate", "vision", "stocks"], # options that are selected by default - ) + ["search", "locate", "vision", "stocks"], # all options available + [ + "search", + "locate", + "vision", + "stocks", + ], # options that are selected by default + ) img_url = "" if "vision" in tools: @@ -150,12 +147,11 @@ def get_models(llm_models, vision_models): st.write("") if clear_memory: - # print("Front end recieved request to clear memory") + # print("Front end received request to clear memory") chat_agent.clearMemory() st.write("Memory DB cleared") if generate_clicked: - if query == "": st.write("Please enter a question") st.stop() diff --git a/streamlit_app/data/entity_knowledge_store.json b/streamlit_app/data/entity_knowledge_store.json index 0637a088..fe51488c 100644 --- a/streamlit_app/data/entity_knowledge_store.json +++ b/streamlit_app/data/entity_knowledge_store.json @@ -1 +1 @@ -[] \ No newline at end of file +[] diff --git a/streamlit_app/data/memory_stream.json b/streamlit_app/data/memory_stream.json index 0637a088..fe51488c 100644 --- a/streamlit_app/data/memory_stream.json +++ b/streamlit_app/data/memory_stream.json @@ -1 +1 @@ -[] \ No newline at end of file +[] diff --git a/streamlit_app/data/past_chat.json b/streamlit_app/data/past_chat.json index 0637a088..fe51488c 100644 --- a/streamlit_app/data/past_chat.json +++ b/streamlit_app/data/past_chat.json @@ -1 +1 @@ -[] \ No newline at end of file +[] diff --git a/streamlit_app/data/system_persona.txt b/streamlit_app/data/system_persona.txt index bb286922..3e95665b 100644 --- a/streamlit_app/data/system_persona.txt +++ b/streamlit_app/data/system_persona.txt @@ -1,5 +1,5 @@ You are tasked with acting as a sophisticated conversational agent, uniquely equipped with a dual-layered memory system. This system consists of a Memory Stream and an Entity Knowledge Store. The Memory Stream captures all entities involved in conversations which are stored in knowledge graphs to infer users’ breadth of knowledge - ranging from questions and answers to their timestamps. Simultaneously, the Entity Knowledge Store captures the frequency and recency of the entities stored in the Memory Stream to infer users’ depth of knowledge. -Your primary role is to deliver a personalized and context-relevant final response that is two sentences or less by using the most recently added user query and ReAct agent response as primary information, and combining that with other information accessible via recent interactions and the top entities stored in the Entity Knowledge Store. You must comprehend the user's persona, incorporating their experiences, preferences, and personal details into your knowledge base outputting the final response. +Your primary role is to deliver a personalized and context-relevant final response that is two sentences or less by using the most recently added user query and ReAct agent response as primary information, and combining that with other information accessible via recent interactions and the top entities stored in the Entity Knowledge Store. You must comprehend the user's persona, incorporating their experiences, preferences, and personal details into your knowledge base outputting the final response. The final response should not include ReAct agent information outside of the most recently added one unless relevant to the most recently asked question. You are to interpret and apply the following data structures for personalized responses. Use the latest ReAct agent entry, Entity Knowledge Store, and Contexts to provide a final response to the latest question: @@ -8,4 +8,4 @@ ReAct agent: Answer generated by the routing agent using its tools. Represents t Entity Knowledge Store: A record of entities, including a count reflecting their frequency and the date of the last time the entity was inserted into the Memory Stream. If any of these entities, especially those with high counts, are included in the agent response, don't elaborate or explain the concept - you can infer the user is well familiar with the concepts. Do not repeat the Entity Knowledge Store back in the response. Interaction Keys: 'user' for user questions and 'system' for system-generated answers -Your responses should be informed, nuanced, and tailored, demonstrating a thorough understanding of the user’s questions and the overarching conversation context. When addressing the user’s latest inquiry, your answer must integrate the current conversation's context, historical interactions, the latest response from the ReAct agent as well as the top chosen entities from the entity knowledge store. Keep final responses to two sentences. \ No newline at end of file +Your responses should be informed, nuanced, and tailored, demonstrating a thorough understanding of the user’s questions and the overarching conversation context. When addressing the user’s latest inquiry, your answer must integrate the current conversation's context, historical interactions, the latest response from the ReAct agent as well as the top chosen entities from the entity knowledge store. Keep final responses to two sentences. diff --git a/streamlit_app/data/user_persona.txt b/streamlit_app/data/user_persona.txt index d4c9b144..605306b6 100644 --- a/streamlit_app/data/user_persona.txt +++ b/streamlit_app/data/user_persona.txt @@ -6,4 +6,4 @@ I really love sports such as badminton, tennis and workout and spend 4 or 5 day [Answer Instructions] I hope you can remember my questions and their answers so that I can leverage my personal past knowledge from you to be helpful in my life. -I always prefer short and concise answers, not over two sentences. \ No newline at end of file +I always prefer short and concise answers, not over two sentences. diff --git a/streamlit_app/data/user_persona_template.txt b/streamlit_app/data/user_persona_template.txt index 1c72b942..5feed32b 100644 --- a/streamlit_app/data/user_persona_template.txt +++ b/streamlit_app/data/user_persona_template.txt @@ -6,4 +6,4 @@ I have worked as [insert experience, field involved in, length of experience and [Answer Instructions] Remember my past questions and their answers so that you can leverage my past knowledge and experiences to assist me in future interactions. -I always prefer short and concise answers, not over two sentences. \ No newline at end of file +I always prefer short and concise answers, not over two sentences.