Wfh/ref links (#8454)

This commit is contained in:
William FH
2023-07-29 08:44:32 -07:00
committed by GitHub
parent 13b4f465e2
commit b7c0eb9ecb
23 changed files with 189 additions and 379 deletions

View File

@@ -216,7 +216,7 @@
},
"outputs": [],
"source": [
"from langchain.experimental.llms import JsonFormer\n",
"from langchain_experimental.llms import JsonFormer\n",
"\n",
"json_former = JsonFormer(json_schema=decoder_schema, pipeline=hf_model)"
]

View File

@@ -162,7 +162,7 @@
}
],
"source": [
"from langchain.experimental.llms import RELLM\n",
"from langchain_experimental.llms import RELLM\n",
"\n",
"model = RELLM(pipeline=hf_model, regex=pattern, max_new_tokens=200)\n",
"\n",

View File

@@ -13,7 +13,7 @@ This page provides instructions on how to use the DataForSEO search APIs within
The DataForSEO utility wraps the API. To import this utility, use:
```python
from langchain.utilities import DataForSeoAPIWrapper
from langchain.utilities.dataforseo_api_search import DataForSeoAPIWrapper
```
For a detailed walkthrough of this wrapper, see [this notebook](/docs/integrations/tools/dataforseo.ipynb).

View File

@@ -177,8 +177,9 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.chains import TransformChain, SQLDatabaseChain, SimpleSequentialChain\n",
"from langchain.sql_database import SQLDatabase"
"from langchain.chains import TransformChain, SimpleSequentialChain\n",
"from langchain.sql_database import SQLDatabase\n",
"from langchain_experimental.sql import SQLDatabaseChain"
]
},
{

View File

@@ -15,7 +15,7 @@ pip install rockset
See a [usage example](/docs/integrations/vectorstores/rockset).
```python
from langchain.vectorstores import RocksetDB
from langchain.vectorstores import Rockset
```
## Document Loader

View File

@@ -16,5 +16,5 @@ pip install spacy
See a [usage example](/docs/modules/data_connection/document_transformers/text_splitters/split_by_token.html#spacy).
```python
from langchain.llms import SpacyTextSplitter
from langchain.text_splitter import SpacyTextSplitter
```

View File

@@ -77,7 +77,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.embeddings.openai import LocalAIEmbeddings"
"from langchain.embeddings import LocalAIEmbeddings"
]
},
{

View File

@@ -15,7 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.utilities import DataForSeoAPIWrapper"
"from langchain.utilities.dataforseo_api_search import DataForSeoAPIWrapper"
]
},
{

View File

@@ -124,7 +124,7 @@
"from langchain.embeddings.openai import OpenAIEmbeddings\n",
"from langchain.text_splitter import CharacterTextSplitter\n",
"from langchain.document_loaders import TextLoader\n",
"from langchain.vectorstores.rocksetdb import RocksetDB\n",
"from langchain.vectorstores import Rockset\n",
"\n",
"loader = TextLoader(\"../../../state_of_the_union.txt\")\n",
"documents = loader.load()\n",
@@ -150,7 +150,7 @@
"# Make sure the environment variable OPENAI_API_KEY is set up\n",
"embeddings = OpenAIEmbeddings()\n",
"\n",
"docsearch = RocksetDB(\n",
"docsearch = Rockset(\n",
" client=rockset_client,\n",
" embeddings=embeddings,\n",
" collection_name=COLLECTION_NAME,\n",
@@ -185,7 +185,7 @@
"source": [
"query = \"What did the president say about Ketanji Brown Jackson\"\n",
"output = docsearch.similarity_search_with_relevance_scores(\n",
" query, 4, RocksetDB.DistanceFunction.COSINE_SIM\n",
" query, 4, Rockset.DistanceFunction.COSINE_SIM\n",
")\n",
"print(\"output length:\", len(output))\n",
"for d, dist in output:\n",
@@ -221,7 +221,7 @@
"output = docsearch.similarity_search_with_relevance_scores(\n",
" query,\n",
" 4,\n",
" RocksetDB.DistanceFunction.COSINE_SIM,\n",
" Rockset.DistanceFunction.COSINE_SIM,\n",
" where_str=\"{} NOT LIKE '%citizens%'\".format(TEXT_KEY),\n",
")\n",
"print(\"output length:\", len(output))\n",
@@ -237,15 +237,16 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "0765b822",
"metadata": {},
"source": [
"### 3. [Optional] Drop all inserted documents\n",
"\n",
"In order to delete texts from the Rockset collection, you need to know the unique ID associated with each document inside Rockset. These ids can either be supplied directly by the user while inserting the texts (in the `RocksetDB.add_texts()` function), else Rockset will generate a unique ID or each document. Either way, `Rockset.add_texts()` returns the ids for the inserted documents.\n",
"In order to delete texts from the Rockset collection, you need to know the unique ID associated with each document inside Rockset. These ids can either be supplied directly by the user while inserting the texts (in the `Rockset.add_texts()` function), else Rockset will generate a unique ID or each document. Either way, `Rockset.add_texts()` returns the ids for the inserted documents.\n",
"\n",
"To delete these docs, simply use the `RocksetDB.delete_texts()` function."
"To delete these docs, simply use the `Rockset.delete_texts()` function."
]
},
{

View File

@@ -15,10 +15,7 @@
"execution_count": 11,
"id": "c19c736e-ca74-4726-bb77-0a849bcc2960",
"metadata": {
"tags": [],
"vscode": {
"languageId": "python"
}
"tags": []
},
"outputs": [],
"source": [
@@ -28,7 +25,7 @@
"\n",
"from pydantic import Extra\n",
"\n",
"from langchain.schema import BaseLanguageModel\n",
"from langchain.schema.language_model import BaseLanguageModel\n",
"from langchain.callbacks.manager import (\n",
" AsyncCallbackManagerForChainRun,\n",
" CallbackManagerForChainRun,\n",
@@ -130,11 +127,7 @@
"cell_type": "code",
"execution_count": 12,
"id": "18361f89",
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",

View File

@@ -35,19 +35,16 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 2,
"id": "91f1ca7f-a748-44c7-a1c6-a89a2d1414ba",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from langchain.schema import SystemMessage\n",
"from langchain.prompts import (\n",
" FewShotChatMessagePromptTemplate,\n",
" HumanMessagePromptTemplate,\n",
" AIMessagePromptTemplate,\n",
" SystemMessagePromptTemplate,\n",
" ChatPromptTemplate,\n",
")"
]
},
@@ -61,7 +58,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 3,
"id": "0fc5a02a-6249-4e92-95c3-30fff9671e8b",
"metadata": {
"tags": []
@@ -84,7 +81,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 4,
"id": "65e72ad1-9060-47d0-91a1-bc130c8b98ac",
"metadata": {
"tags": []
@@ -103,9 +100,12 @@
],
"source": [
"# This is a prompt template used to format each individual example.\n",
"example_prompt = HumanMessagePromptTemplate.from_template(\n",
" \"{input}\"\n",
") + AIMessagePromptTemplate.from_template(\"{output}\")\n",
"example_prompt = ChatPromptTemplate.from_messages(\n",
" [\n",
" (\"human\", \"{input}\"),\n",
" (\"ai\", \"{output}\"),\n",
" ]\n",
")\n",
"few_shot_prompt = FewShotChatMessagePromptTemplate(\n",
" example_prompt=example_prompt,\n",
" examples=examples,\n",
@@ -124,23 +124,25 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 5,
"id": "9f86d6d9-50de-41b6-b6c7-0f9980cc0187",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"final_prompt = (\n",
" SystemMessagePromptTemplate.from_template(\"You are wonderous wizard of math.\")\n",
" + few_shot_prompt\n",
" + HumanMessagePromptTemplate.from_template(\"{input}\")\n",
"final_prompt = ChatPromptTemplate.from_messages(\n",
" [\n",
" (\"system\", \"You are wonderous wizard of math.\"),\n",
" few_shot_prompt,\n",
" (\"human\", \"{input}\"),\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 6,
"id": "97d443b1-6fae-4b36-bede-3ff7306288a3",
"metadata": {
"tags": []
@@ -149,10 +151,10 @@
{
"data": {
"text/plain": [
"AIMessage(content=' Triangles do not have a \"square\". A square refers to a shape with 4 equal sides and 4 right angles. Triangles have 3 sides and 3 angles.\\n\\nThe area of a triangle can be calculated using the formula:\\n\\nA = 1/2 * b * h\\n\\nWhere:\\n\\nA is the area \\nb is the base (the length of one of the sides)\\nh is the height (the length from the base to the opposite vertex)\\n\\nSo the area depends on the specific dimensions of the triangle. There is no single \"square of a triangle\". The area can vary greatly between different triangles.', additional_kwargs={}, example=False)"
"AIMessage(content=' Triangles do not have a \"square\". A square refers to a shape with 4 equal sides and 4 right angles. Triangles have 3 sides and 3 angles.\\n\\nThe area of a triangle can be calculated using the formula:\\n\\nA = 1/2 * b * h\\n\\nWhere:\\n\\nA is the area \\nb is the base (the length of one of the sides)\\nh is the height (the length from the base to the opposite vertex)\\n\\nSo the area depends on the specific dimensions of the triangle. There is no single \"square of a triangle\". The area can vary greatly depending on the base and height measurements.', additional_kwargs={}, example=False)"
]
},
"execution_count": 14,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
@@ -182,7 +184,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 7,
"id": "6f7b5e86-4ca7-4edd-bf2b-9663030b2393",
"metadata": {
"tags": []
@@ -204,7 +206,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 8,
"id": "ad66f06a-66fd-4fcc-8166-5d0e3c801e57",
"metadata": {
"tags": []
@@ -239,7 +241,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 9,
"id": "7790303a-f722-452e-8921-b14bdf20bdff",
"metadata": {
"tags": []
@@ -252,7 +254,7 @@
" {'input': '2+4', 'output': '6'}]"
]
},
"execution_count": 17,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@@ -279,17 +281,17 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 10,
"id": "253c255e-41d7-45f6-9d88-c7a0ced4b1bd",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from langchain.schema import SystemMessage\n",
"from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate\n",
"from langchain.prompts.few_shot import FewShotChatMessagePromptTemplate\n",
"\n",
"from langchain.prompts import (\n",
" FewShotChatMessagePromptTemplate,\n",
" ChatPromptTemplate,\n",
")\n",
"\n",
"# Define the few-shot prompt.\n",
"few_shot_prompt = FewShotChatMessagePromptTemplate(\n",
@@ -299,9 +301,8 @@
" # Define how each example will be formatted.\n",
" # In this case, each example will become 2 messages:\n",
" # 1 human, and 1 AI\n",
" example_prompt=(\n",
" HumanMessagePromptTemplate.from_template(\"{input}\")\n",
" + AIMessagePromptTemplate.from_template(\"{output}\")\n",
" example_prompt=ChatPromptTemplate.from_messages(\n",
" [(\"human\", \"{input}\"), (\"ai\", \"{output}\")]\n",
" ),\n",
")"
]
@@ -316,7 +317,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 11,
"id": "860bf682-c469-40e9-b657-27bfe7026099",
"metadata": {
"tags": []
@@ -347,23 +348,25 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 12,
"id": "e731cb45-f0ea-422c-be37-42af2a6cb2c4",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"final_prompt = (\n",
" SystemMessagePromptTemplate.from_template(\"You are wonderous wizard of math.\")\n",
" + few_shot_prompt\n",
" + HumanMessagePromptTemplate.from_template(\"{input}\")\n",
"final_prompt = ChatPromptTemplate.from_messages(\n",
" [\n",
" (\"system\", \"You are wonderous wizard of math.\"),\n",
" few_shot_prompt,\n",
" (\"human\", \"{input}\"),\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 13,
"id": "e6cc4199-8947-42d7-91f0-375de1e15bd9",
"metadata": {
"tags": []
@@ -396,7 +399,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 14,
"id": "0568cbc6-5354-47f1-ab4d-dfcc616cf583",
"metadata": {
"tags": []
@@ -408,7 +411,7 @@
"AIMessage(content=' 3 + 3 = 6', additional_kwargs={}, example=False)"
]
},
"execution_count": 26,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}

View File

@@ -101,7 +101,7 @@
},
"outputs": [],
"source": [
"from langchain.experimental.generative_agents import (\n",
"from langchain_experimental.generative_agents import (\n",
" GenerativeAgent,\n",
" GenerativeAgentMemory,\n",
")"

View File

@@ -100,7 +100,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.experimental import AutoGPT\n",
"from langchain_experimental.autonomous_agents import AutoGPT\n",
"from langchain.chat_models import ChatOpenAI"
]
},
@@ -124,43 +124,47 @@
},
{
"cell_type": "markdown",
"id": "f0f208d9",
"metadata": {
"collapsed": false
},
"source": [
"## Run an example\n",
"\n",
"Here we will make it write a weather report for SF"
],
"metadata": {
"collapsed": false
},
"id": "f0f208d9"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"agent.run([\"write a weather report for SF today\"])"
],
"id": "d119d788",
"metadata": {
"collapsed": false
},
"id": "d119d788"
"outputs": [],
"source": [
"agent.run([\"write a weather report for SF today\"])"
]
},
{
"cell_type": "markdown",
"id": "f13f8322",
"metadata": {
"collapsed": false
},
"source": [
"## Chat History Memory\n",
"\n",
"In addition to the memory that holds the agent immediate steps, we also have a chat history memory. By default, the agent will use 'ChatMessageHistory' and it can be changed. This is useful when you want to use a different type of memory for example 'FileChatHistoryMemory'"
],
"metadata": {
"collapsed": false
},
"id": "f13f8322"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2a81f5ad",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from langchain.memory.chat_message_histories import FileChatMessageHistory\n",
@@ -173,19 +177,15 @@
" memory=vectorstore.as_retriever(),\n",
" chat_history_memory=FileChatMessageHistory(\"chat_history.txt\"),\n",
")"
],
"metadata": {
"collapsed": false
},
"id": "2a81f5ad"
]
},
{
"cell_type": "markdown",
"source": [],
"id": "b1403008",
"metadata": {
"collapsed": false
},
"id": "b1403008"
"source": []
}
],
"metadata": {
@@ -209,4 +209,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}

View File

@@ -39,7 +39,7 @@
"from langchain.vectorstores.base import VectorStore\n",
"from pydantic import BaseModel, Field\n",
"from langchain.chains.base import Chain\n",
"from langchain.experimental import BabyAGI"
"from langchain_experimental.autonomous_agents import BabyAGI"
]
},
{

View File

@@ -35,7 +35,7 @@
"from langchain.vectorstores.base import VectorStore\n",
"from pydantic import BaseModel, Field\n",
"from langchain.chains.base import Chain\n",
"from langchain.experimental import BabyAGI"
"from langchain_experimental.autonomous_agents import BabyAGI"
]
},
{

View File

@@ -36,7 +36,7 @@
"# General\n",
"import os\n",
"import pandas as pd\n",
"from langchain.experimental.autonomous_agents.autogpt.agent import AutoGPT\n",
"from langchain_experimental.autonomous_agents import AutoGPT\n",
"from langchain.chat_models import ChatOpenAI\n",
"\n",
"from langchain.agents.agent_toolkits.pandas.base import create_pandas_dataframe_agent\n",

File diff suppressed because one or more lines are too long