diff --git a/sources/platform/integrations/ai/langchain.md b/sources/platform/integrations/ai/langchain.md index f5f8455918..3a2b5b793b 100644 --- a/sources/platform/integrations/ai/langchain.md +++ b/sources/platform/integrations/ai/langchain.md @@ -15,8 +15,8 @@ slug: /integrations/langchain In this example, we'll use the [Website Content Crawler](https://apify.com/apify/website-content-crawler) Actor, which can deeply crawl websites such as documentation, knowledge bases, help centers, or blogs and extract text content from the web pages. Then we feed the documents into a vector index and answer questions from it. -This example focuses on how to integrate Apify with LangChain using the Python language, -but if you prefer to use JavaScript, you can follow the same steps in the [JavaScript LangChain documentation](https://js.langchain.com/docs/modules/indexes/document_loaders/examples/web_loaders/apify_dataset). +This example demonstrates how to integrate Apify with LangChain using the Python language. +If you prefer to use JavaScript, you can follow the [JavaScript LangChain documentation](https://js.langchain.com/docs/integrations/document_loaders/web_loaders/apify_dataset/). Before we start with the integration, we need to install all dependencies: @@ -122,11 +122,27 @@ answer: LangChain is a framework for developing applications powered by language source: https://python.langchain.com ``` -LangChain is a standard interface through which you can interact with a variety of large language models (LLMs). It provides modules you can use to build language model applications. It also provides chains and agents with memory capabilities. +LangChain is a standard interface through which you can interact with a variety of large language models (LLMs). +It provides modules you can use to build language model applications as well as chains and agents with memory capabilities. + +You can use all of Apify’s Actors as document loaders in LangChain. +For example, to incorporate web browsing functionality, you can use the [RAG-Web-Browser Actor](https://apify.com/apify/rag-web-browser). +This allows you to either crawl and scrape top pages from Google Search results or directly scrape text content from a URL and return it as Markdown. +To set this up, change the `actor_id` to `apify/rag-web-browser` and specify the `run_input`. + +```python +loader = apify.call_actor( + actor_id="apify/rag-web-browser", + run_input={"query": "apify langchain web browser", "maxResults": 3}, + dataset_mapping_function=lambda item: Document(page_content=item["text"] or "", metadata={"source": item["metadata"]["url"]}), +) +print("Documents:", loader.load()) +``` + +Similarly, you can use other Apify Actors to load data into LangChain and query the vector index. ## Resources -- https://python.langchain.com/docs/get_started/introduction -- https://python.langchain.com/docs/integrations/document_loaders/apify_dataset -- https://python.langchain.com/docs/integrations/providers/apify -- https://python.langchain.com/docs/modules/model_io/llms/ +- [LangChain introduction](https://python.langchain.com/docs/get_started/introduction) +- [Apify Dataset loader](https://python.langchain.com/docs/integrations/document_loaders/apify_dataset) +- [LangChain Apify Provider](https://python.langchain.com/docs/integrations/providers/apify)