Skip to content

Commit

Permalink
docs: update langchain integration docs as the Document has moved to …
Browse files Browse the repository at this point in the history
…langchain_core (apify#934)

- update langchain integration as the Document has moved to
langchain_core and ApifyWrapper to langchain_community.
- change langchain URL links
  • Loading branch information
jirispilka committed Apr 22, 2024
1 parent 5d6a93b commit 23a5b98
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions sources/platform/integrations/langchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ but if you prefer to use JavaScript, you can follow the same steps in the [JavaS

Before we start with the integration, we need to install all dependencies:

`pip install apify-client langchain openai`
`pip install apify-client langchain langchain_community openai tiktoken`

After successful installation of all dependencies, we can start writing code.

First, import `os`, `Document`, `VectorstoreIndexCreator`, and `ApifyWrapper` into your source code:
First, import `os`, `VectorstoreIndexCreator`, `ApifyWrapper`, and `Document` into your source code:

```python
import os

from langchain.document_loaders.base import Document
from langchain.indexes import VectorstoreIndexCreator
from langchain.utilities import ApifyWrapper
from langchain_community.utilities import ApifyWrapper
from langchain_core.document_loaders.base import Document
```

Find your [Apify API token](https://console.apify.com/account/integrations) and [OpenAI API key](https://platform.openai.com/account/api-keys) and initialize these into environment variable:
Expand All @@ -50,7 +50,7 @@ apify = ApifyWrapper()

loader = apify.call_actor(
actor_id="apify/website-content-crawler",
run_input={"startUrls": [{"url": "https://python.langchain.com/en/latest/"}], "maxCrawlPages": 10, "crawlerType": "cheerio"},
run_input={"startUrls": [{"url": "https://python.langchain.com/docs/get_started/introduction"}], "maxCrawlPages": 10, "crawlerType": "cheerio"},
dataset_mapping_function=lambda item: Document(
page_content=item["text"] or "", metadata={"source": item["url"]}
),
Expand Down Expand Up @@ -80,9 +80,9 @@ If you want to test the whole example, you can simply create a new file, `langch
```python
import os

from langchain.document_loaders.base import Document
from langchain.indexes import VectorstoreIndexCreator
from langchain.utilities import ApifyWrapper
from langchain_community.utilities import ApifyWrapper
from langchain_core.document_loaders.base import Document

os.environ["OPENAI_API_KEY"] = "Your OpenAI API key"
os.environ["APIFY_API_TOKEN"] = "Your Apify API token"
Expand All @@ -91,7 +91,7 @@ apify = ApifyWrapper()

loader = apify.call_actor(
actor_id="apify/website-content-crawler",
run_input={"startUrls": [{"url": "https://python.langchain.com/en/latest/"}], "maxCrawlPages": 10, "crawlerType": "cheerio"},
run_input={"startUrls": [{"url": "https://python.langchain.com/docs/get_started/introduction"}], "maxCrawlPages": 10, "crawlerType": "cheerio"},
dataset_mapping_function=lambda item: Document(
page_content=item["text"] or "", metadata={"source": item["url"]}
),
Expand All @@ -118,7 +118,7 @@ LangChain is a standard interface through which you can interact with a variety

## Resources

- <https://python.langchain.com/docs/get_started/introduction/>
- <https://python.langchain.com/docs/get_started/introduction>
- <https://python.langchain.com/docs/integrations/providers/apify>
- <https://python.langchain.com/docs/integrations/tools/apify>
- <https://python.langchain.com/docs/modules/model_io/llms/>

0 comments on commit 23a5b98

Please sign in to comment.