Skip to content

Commit

Permalink
updated demo
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Feb 8, 2024
1 parent 1eea0c9 commit e5d25e4
Showing 1 changed file with 127 additions and 50 deletions.
177 changes: 127 additions & 50 deletions demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,31 @@
"cells": [
{
"cell_type": "code",
"execution_count": 26,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"!pip install langchain-iris\n",
"\n",
"!pip install testcontainers-iris \\\n",
" fastembed \\\n",
" openai \\\n",
" tiktoken \\\n",
" python-dotenv\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We want to use `OpenAIEmbeddings` so we have to get the OpenAI API Key."
"!pip install langchain-iris"
]
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"import getpass\n",
"import os\n",
"from dotenv import load_dotenv\n",
"\n",
"load_dotenv(override=True)\n",
"\n",
"if not os.environ.get(\"OPENAI_API_KEY\"):\n",
" os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")\n"
"%%capture\n",
"!pip install testcontainers-iris \\\n",
" fastembed \\\n",
" openai \\\n",
" tiktoken \\\n",
" python-dotenv\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -57,7 +42,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -66,29 +51,40 @@
"text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
"docs = text_splitter.split_documents(documents)\n",
"\n",
"# embeddings = OpenAIEmbeddings()\n",
"embeddings = FastEmbedEmbeddings()"
"import getpass\n",
"import os\n",
"from dotenv import load_dotenv\n",
"\n",
"load_dotenv(override=True)\n",
"\n",
"# if not os.environ.get(\"OPENAI_API_KEY\"):\n",
"# os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")\n",
"\n",
"if not os.environ.get(\"OPENAI_API_KEY\"):\n",
" embeddings = FastEmbedEmbeddings()\n",
"else:\n",
" embeddings = OpenAIEmbeddings()\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Pulling image containers.intersystems.com/intersystems/iris:2023.3\n",
"Container started: bd7acb4e7e13\n",
"Pulling image containers.intersystems.com/intersystems/iris-community:2023.3\n",
"Container started: 8ae00b2dcf6c\n",
"Waiting to be ready...\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Started\n"
"Started iris://demo:demo@localhost:62287/demo\n"
]
}
],
Expand All @@ -105,21 +101,49 @@
"license_key = None\n",
"image = 'containers.intersystems.com/intersystems/iris-community:2023.3'\n",
"\n",
"# image = 'iris:2024.1'\n",
"container = IRISContainer(image, username=\"demo\", password=\"demo\", namespace=\"demo\", license_key=license_key)\n",
"container.with_exposed_ports(1972, 52773)\n",
"container.start()\n",
"CONNECTION_STRING = container.get_connection_url()\n",
"CONNECTION_STRING = container.get_connection_url(\"localhost\")\n",
"\n",
"time.sleep(1)\n",
"print('Started')\n"
"print('Started', CONNECTION_STRING)\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 25,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
"To disable this warning, you can either:\n",
"\t- Avoid using `tokenizers` before the fork if possible\n",
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n",
"Exception during reset or similar\n",
"Traceback (most recent call last):\n",
" File \"/Users/daimor/Projects/langchain-iris/.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py\", line 988, in _finalize_fairy\n",
" fairy._reset(\n",
" File \"/Users/daimor/Projects/langchain-iris/.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py\", line 1438, in _reset\n",
" pool._dialect.do_rollback(self)\n",
" File \"/Users/daimor/Projects/langchain-iris/.venv/lib/python3.11/site-packages/sqlalchemy_iris/base.py\", line 1047, in do_rollback\n",
" connection.rollback()\n",
" File \"/Users/daimor/Projects/langchain-iris/.venv/lib/python3.11/site-packages/intersystems_iris/_IRISConnection.py\", line 494, in rollback\n",
" self._in_message._read_message_sql(sequence_number, -1, 0, [0])\n",
" File \"/Users/daimor/Projects/langchain-iris/.venv/lib/python3.11/site-packages/intersystems_iris/_InStream.py\", line 46, in _read_message_sql\n",
" is_for_gateway = self.__read_message_internal(expected_message_id, expected_statement_id, type)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/daimor/Projects/langchain-iris/.venv/lib/python3.11/site-packages/intersystems_iris/_InStream.py\", line 59, in __read_message_internal\n",
" self.__read_buffer(header.buffer, 0, _MessageHeader.HEADER_SIZE)\n",
" File \"/Users/daimor/Projects/langchain-iris/.venv/lib/python3.11/site-packages/intersystems_iris/_InStream.py\", line 146, in __read_buffer\n",
" raise Exception(\"Server unexpectedly closing communication device\")\n",
"Exception: Server unexpectedly closing communication device\n"
]
}
],
"source": [
"COLLECTION_NAME = \"state_of_the_union_test\"\n",
"\n",
Expand All @@ -133,17 +157,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"ids=db.get()[\"ids\"]\n",
"db.delete(ids)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -153,9 +167,72 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 27,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--------------------------------------------------------------------------------\n",
"Score: 0.18465027104149012\n",
"Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n",
"\n",
"Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \n",
"\n",
"One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \n",
"\n",
"And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.\n",
"--------------------------------------------------------------------------------\n",
"--------------------------------------------------------------------------------\n",
"Score: 0.2175391168776707\n",
"A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \n",
"\n",
"And if we are to advance liberty and justice, we need to secure the Border and fix the immigration system. \n",
"\n",
"We can do both. At our border, we’ve installed new technology like cutting-edge scanners to better detect drug smuggling. \n",
"\n",
"We’ve set up joint patrols with Mexico and Guatemala to catch more human traffickers. \n",
"\n",
"We’re putting in place dedicated immigration judges so families fleeing persecution and violence can have their cases heard faster. \n",
"\n",
"We’re securing commitments and supporting partners in South and Central America to host more refugees and secure their own borders.\n",
"--------------------------------------------------------------------------------\n",
"--------------------------------------------------------------------------------\n",
"Score: 0.22691661118838602\n",
"And for our LGBTQ+ Americans, let’s finally get the bipartisan Equality Act to my desk. The onslaught of state laws targeting transgender Americans and their families is wrong. \n",
"\n",
"As I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \n",
"\n",
"While it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice. \n",
"\n",
"And soon, we’ll strengthen the Violence Against Women Act that I first wrote three decades ago. It is important for us to show the nation that we can come together and do big things. \n",
"\n",
"So tonight I’m offering a Unity Agenda for the Nation. Four big things we can do together. \n",
"\n",
"First, beat the opioid epidemic.\n",
"--------------------------------------------------------------------------------\n",
"--------------------------------------------------------------------------------\n",
"Score: 0.22702497974350289\n",
"Tonight, I’m announcing a crackdown on these companies overcharging American businesses and consumers. \n",
"\n",
"And as Wall Street firms take over more nursing homes, quality in those homes has gone down and costs have gone up. \n",
"\n",
"That ends on my watch. \n",
"\n",
"Medicare is going to set higher standards for nursing homes and make sure your loved ones get the care they deserve and expect. \n",
"\n",
"We’ll also cut costs and keep the economy going strong by giving workers a fair shot, provide more training and apprenticeships, hire them based on their skills not degrees. \n",
"\n",
"Let’s pass the Paycheck Fairness Act and paid leave. \n",
"\n",
"Raise the minimum wage to $15 an hour and extend the Child Tax Credit, so no one has to raise a family in poverty. \n",
"\n",
"Let’s increase Pell Grants and increase our historic support of HBCUs, and invest in what Jill—our First Lady who teaches full-time—calls America’s best-kept secret: community colleges.\n",
"--------------------------------------------------------------------------------\n"
]
}
],
"source": [
"for doc, score in docs_with_score:\n",
" print(\"-\" * 80)\n",
Expand Down

0 comments on commit e5d25e4

Please sign in to comment.