diff --git a/.gitignore b/.gitignore index 070eec4..06f1333 100644 --- a/.gitignore +++ b/.gitignore @@ -133,4 +133,5 @@ dmypy.json *config.py *embeddings.npy *.pickle -*.pkl \ No newline at end of file +*.pkl +src/Embeddings Search/tmp.py \ No newline at end of file diff --git a/src/Embeddings Search/testing.ipynb b/src/Embeddings Search/testing.ipynb index fe759c8..4f0d7ae 100644 --- a/src/Embeddings Search/testing.ipynb +++ b/src/Embeddings Search/testing.ipynb @@ -71,62 +71,6 @@ "```" ] }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "https://aipulse.org: title links link authors author text (tags)\n", - "\n", - "None: title url text\n", - "\n", - "ebook: title book_title authors text (publication_date)\n", - "\n", - "https://qualiacomputing.com: title link authors author text (tags)\n", - "\n", - "alignment forum: title url authors text (tags)\n", - "\n", - "lesswrong: title authors url text (tags score date_published)\n", - "\n", - "manual: title authors text (date_published)\n", - "\n", - "arxiv: title authors url text (citation_level alignment_text confidence_score date_published)\n", - "\n", - "https://deepmindsafetyresearch.medium.com/: title url text\n", - "\n", - "waitbutwhy.com: title authors text (date_published)\n", - "\n", - "GitHub: book_title authors author text\n", - "\n", - "https://aiimpacts.org: title link authors author text (tags)\n", - "\n", - "arbital.com: title authors url text (date_published)\n", - "\n", - "carado.moe: title authors text (date_published)\n", - "\n", - "nonarxiv_papers: title authors doi text (date_published)\n", - "\n", - "https://vkrakovna.wordpress.com: title link authors author text (tags)\n", - "\n", - "https://jsteinhardt.wordpress.com: title link authors author text (tags)\n", - "\n", - "audio-transcripts: title authors text (date_published)\n", - "\n", - "https://intelligence.org: title link authors author text (tags)\n", - "\n", - "youtube: title authors url text (date_published)\n", - "\n", - "reports: title authors doi text (date_published)\n", - "\n", - "https://aisafety.camp: title link authors author text (tags)\n", - "\n", - "curriculum: title authors text (date_published)\n", - "\n", - "https://www.yudkowsky.net: title link authors author text (tags)\n", - "\n", - "distill: title authors doi text (date_published)" - ] - }, { "attachments": {}, "cell_type": "markdown", @@ -134,9 +78,19 @@ "source": [ "Useful links:\n", "\n", - "- https://github.com/openai/openai-cookbook/blob/main/examples/Semantic_text_search_using_embeddings.ipynb\n", + "- Semantic Search OpenAI Cookbook: https://github.com/openai/openai-cookbook/blob/main/examples/Semantic_text_search_using_embeddings.ipynb\n", "\n", - "- https://github.com/openai/openai-cookbook/blob/main/examples/Question_answering_using_embeddings.ipynb" + "- Question-Answering OpenAI Cookbook: https://github.com/openai/openai-cookbook/blob/main/examples/Question_answering_using_embeddings.ipynb\n", + "\n", + "- Pinecone: https://app.pinecone.io\n", + "\n", + "- Retrieval Enhanced Generative Question Answering with Pinecone: https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/pinecone/Gen_QA.ipynb\n", + "\n", + "- Moderation: https://platform.openai.com/docs/guides/moderation/quickstart\n", + "\n", + "- 5k Bounty: https://www.lesswrong.com/posts/SLRLuiuDykfTdmesK/speed-running-everyone-through-the-bad-alignement-bingo\n", + "\n", + "- Handling rate-limits Cookbook: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_handle_rate_limits.ipynb" ] }, { @@ -168,8 +122,7 @@ " wait_random_exponential,\n", ") # for exponential backoff\n", "\n", - "import config\n", - "from pathlib import Path" + "import config" ] }, { @@ -187,11 +140,9 @@ "outputs": [], "source": [ "LEN_EMBEDDINGS = 1536\n", - "\n", - "project_path = Path(__file__).parent.parent.parent\n", - "PATH_TO_DATA = project_path / \"data\" / \"alignment_texts.jsonl\" # Path to the dataset .jsonl file.\n", - "PATH_TO_EMBEDDINGS = project_path / \"src\" / \"Embeddings Search\" / \"data\" / \"embeddings.npy\" # Path to the saved embeddings (.npy) file.\n", - "PATH_TO_DATASET = project_path / \"src\" / \"Embeddings Search\" / \"data\" / \"dataset.pkl\" # Path to the saved dataset (.pkl) file.\n", + "PATH_TO_DATA = r\"C:\\Users\\Henri\\Documents\\GitHub\\AlignmentSearch\\src\\Embeddings Search\\data\\alignment_texts.jsonl\"\n", + "PATH_TO_EMBEDDINGS = r\"C:\\Users\\Henri\\Documents\\GitHub\\AlignmentSearch\\src\\Embeddings Search\\data\\embeddings.npy\"\n", + "PATH_TO_DATASET = r\"C:\\Users\\Henri\\Documents\\GitHub\\AlignmentSearch\\src\\Embeddings Search\\data\\dataset.pkl\"\n", "\n", "COMPLETIONS_MODEL = \"gpt-3.5-turbo\"\n", "EMBEDDING_MODEL = \"text-embedding-ada-002\"\n", @@ -2953,40 +2904,49 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Average time for len(string): 0.0008568000048398972\n", - "Average time for len(tiktoken): 15.112917799997376\n" - ] - } - ], + "outputs": [], "source": [ - "import random\n", - "from timeit import timeit\n", - "import string\n", - "import tiktoken\n", - "encoding = tiktoken.get_encoding(\"cl100k_base\")\n", + "import os\n", + "import json\n", + "import argparse\n", + "import openai\n", + "from typing import List\n", "\n", - "#we want to compare the speed of len(string) vs len(encoding.encode(string))\n", - "#we will use a random string of length 1000 to do this\n", + "from rich.console import Console\n", + "from rich.markdown import Markdown#, MarkdownIt\n", + "from rich.live import Live\n", "\n", - "def len_string(string):\n", - " return len(string)\n", - "\n", - "def len_tiktoken(string):\n", - " return len(encoding.encode(string))\n", - "\n", - "random_str = ''.join(random.choice(string.ascii_letters) for i in range(1000))\n", - "\n", - "#we will run each function 1000 times and compare the average time\n", - "print(\"Average time for len(string):\", timeit(lambda: len_string(random_str), number=3000))\n", - "print(\"Average time for len(tiktoken):\", timeit(lambda: len_tiktoken(random_str), number=3000))\n" + "# import readline\n", + "try:\n", + " import rlcompleter\n", + "except ImportError:\n", + " pass" ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "assistant_prompt = \"You are a helpful assistant, and you help users by answering questions and providing information about AI Alignment, on which you are extremely knowledgeable. Answer the user's question even if you are not certain of the answer; it is supremely important that you do attempt to offer an answer related to the user's query.\"\n", + "\n", + "question = \"What are the most important things to know about AI Alignment?\"\n", + "\n", + "messages = [\n", + " {\"role\": \"system\", \"content\": assistant_prompt},\n", + " {\"role\": \"user\", \"content\": question},\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -3005,7 +2965,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.7" + "version": "3.10.6" }, "orig_nbformat": 4, "vscode": {