mirror of https://github.com/hwchase17/langchain
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
216 lines
6.3 KiB
Plaintext
216 lines
6.3 KiB
Plaintext
2 years ago
|
{
|
||
|
"cells": [
|
||
2 years ago
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "b4462a94",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Manifest\n",
|
||
|
"\n",
|
||
|
"This notebook goes over how to use Manifest and LangChain."
|
||
|
]
|
||
|
},
|
||
2 years ago
|
{
|
||
2 years ago
|
"cell_type": "markdown",
|
||
|
"id": "59fcaebc",
|
||
2 years ago
|
"metadata": {},
|
||
|
"source": [
|
||
2 years ago
|
"For more detailed information on `manifest`, and how to use it with local hugginface models like in this example, see https://github.com/HazyResearch/manifest"
|
||
2 years ago
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": 3,
|
||
|
"id": "04a0170a",
|
||
2 years ago
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
2 years ago
|
"from manifest import Manifest\n",
|
||
|
"from langchain.llms.manifest import ManifestWrapper"
|
||
2 years ago
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": 4,
|
||
|
"id": "de250a6a",
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"{'model_name': 'bigscience/T0_3B', 'model_path': 'bigscience/T0_3B'}\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
2 years ago
|
"source": [
|
||
2 years ago
|
"manifest = Manifest(\n",
|
||
|
" client_name = \"huggingface\",\n",
|
||
|
" client_connection = \"http://127.0.0.1:5000\"\n",
|
||
|
")\n",
|
||
|
"print(manifest.client.get_model_params())"
|
||
2 years ago
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": 5,
|
||
2 years ago
|
"id": "67b719d6",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
2 years ago
|
"llm = ManifestWrapper(client=manifest, llm_kwargs={\"temperature\": 0.001, \"max_tokens\": 256})"
|
||
2 years ago
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": 6,
|
||
2 years ago
|
"id": "5af505a8",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# Map reduce example\n",
|
||
|
"from langchain import Prompt\n",
|
||
|
"from langchain.text_splitter import CharacterTextSplitter\n",
|
||
|
"from langchain.chains.mapreduce import MapReduceChain\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"_prompt = \"\"\"Write a concise summary of the following:\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"{text}\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"CONCISE SUMMARY:\"\"\"\n",
|
||
|
"prompt = Prompt(template=_prompt, input_variables=[\"text\"])\n",
|
||
|
"\n",
|
||
|
"text_splitter = CharacterTextSplitter()\n",
|
||
|
"\n",
|
||
|
"mp_chain = MapReduceChain.from_params(llm, prompt, text_splitter)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": 7,
|
||
2 years ago
|
"id": "485b3ec3",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
2 years ago
|
"'President Obama delivered his annual State of the Union address on Tuesday night, laying out his priorities for the coming year. Obama said the government will provide free flu vaccines to all Americans, ending the government shutdown and allowing businesses to reopen. The president also said that the government will continue to send vaccines to 112 countries, more than any other nation. \"We have lost so much to COVID-19,\" Trump said. \"Time with one another. And worst of all, so much loss of life.\" He said the CDC is working on a vaccine for kids under 5, and that the government will be ready with plenty of vaccines when they are available. Obama says the new guidelines are a \"great step forward\" and that the virus is no longer a threat. He says the government is launching a \"Test to Treat\" initiative that will allow people to get tested at a pharmacy and get antiviral pills on the spot at no cost. Obama says the new guidelines are a \"great step forward\" and that the virus is no longer a threat. He says the government will continue to send vaccines to 112 countries, more than any other nation. \"We are coming for your'"
|
||
2 years ago
|
]
|
||
|
},
|
||
2 years ago
|
"execution_count": 7,
|
||
2 years ago
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
2 years ago
|
"with open('../state_of_the_union.txt') as f:\n",
|
||
2 years ago
|
" state_of_the_union = f.read()\n",
|
||
|
"mp_chain.run(state_of_the_union)"
|
||
|
]
|
||
|
},
|
||
2 years ago
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"id": "6e9d45a8",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Compare HF Models"
|
||
|
]
|
||
|
},
|
||
2 years ago
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": 8,
|
||
|
"id": "33407ab3",
|
||
2 years ago
|
"metadata": {},
|
||
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
|
"from langchain.model_laboratory import ModelLaboratory\n",
|
||
|
"\n",
|
||
|
"manifest1 = ManifestWrapper(\n",
|
||
|
" client=Manifest(\n",
|
||
|
" client_name=\"huggingface\",\n",
|
||
|
" client_connection=\"http://127.0.0.1:5000\"\n",
|
||
|
" ),\n",
|
||
|
" llm_kwargs={\"temperature\": 0.01}\n",
|
||
|
")\n",
|
||
|
"manifest2 = ManifestWrapper(\n",
|
||
|
" client=Manifest(\n",
|
||
|
" client_name=\"huggingface\",\n",
|
||
|
" client_connection=\"http://127.0.0.1:5001\"\n",
|
||
|
" ),\n",
|
||
|
" llm_kwargs={\"temperature\": 0.01}\n",
|
||
|
")\n",
|
||
|
"manifest3 = ManifestWrapper(\n",
|
||
|
" client=Manifest(\n",
|
||
|
" client_name=\"huggingface\",\n",
|
||
|
" client_connection=\"http://127.0.0.1:5002\"\n",
|
||
|
" ),\n",
|
||
|
" llm_kwargs={\"temperature\": 0.01}\n",
|
||
|
")\n",
|
||
|
"llms = [manifest1, manifest2, manifest3]\n",
|
||
|
"model_lab = ModelLaboratory(llms)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"id": "448935c3",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"\u001b[1mInput:\u001b[0m\n",
|
||
|
"What color is a flamingo?\n",
|
||
|
"\n",
|
||
|
"\u001b[1mManifestWrapper\u001b[0m\n",
|
||
|
"Params: {'model_name': 'bigscience/T0_3B', 'model_path': 'bigscience/T0_3B', 'temperature': 0.01}\n",
|
||
|
"\u001b[104mpink\u001b[0m\n",
|
||
|
"\n",
|
||
|
"\u001b[1mManifestWrapper\u001b[0m\n",
|
||
|
"Params: {'model_name': 'EleutherAI/gpt-neo-125M', 'model_path': 'EleutherAI/gpt-neo-125M', 'temperature': 0.01}\n",
|
||
|
"\u001b[103mA flamingo is a small, round\u001b[0m\n",
|
||
|
"\n",
|
||
|
"\u001b[1mManifestWrapper\u001b[0m\n",
|
||
|
"Params: {'model_name': 'google/flan-t5-xl', 'model_path': 'google/flan-t5-xl', 'temperature': 0.01}\n",
|
||
|
"\u001b[101mpink\u001b[0m\n",
|
||
|
"\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"model_lab.compare(\"What color is a flamingo?\")"
|
||
|
]
|
||
2 years ago
|
}
|
||
|
],
|
||
|
"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",
|
||
2 years ago
|
"version": "3.7.6"
|
||
|
},
|
||
|
"vscode": {
|
||
|
"interpreter": {
|
||
|
"hash": "51b9b5b89a4976ad21c8b4273a6c78d700e2954ce7d7452948b7774eb33bbce4"
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|