apify-haystack 0.0.1a3__tar.gz → 0.0.1a5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apify_haystack
3
- Version: 0.0.1a3
3
+ Version: 0.0.1a5
4
4
  Summary: Apify-haystack integration
5
5
  Home-page: https://apify.com
6
6
  License: Apache-2.0
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.11
19
19
  Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Topic :: Software Development :: Libraries
21
21
  Requires-Dist: apify-client (>=1.7.1,<2.0.0)
22
- Requires-Dist: haystack-ai (>=2.3.0,<3.0.0)
22
+ Requires-Dist: haystack-ai (>=2.3.1,<3.0.0)
23
23
  Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
24
24
  Project-URL: Changelog, https://github.com/apify/apify-haystack/blob/master/CHANGELOG.md
25
25
  Project-URL: Documentation, https://github.com/apify/apify-haystack
@@ -29,11 +29,12 @@ Description-Content-Type: text/markdown
29
29
 
30
30
  # Apify-Haystack integration
31
31
 
32
- Apify-Haystack integration allows to quickly fetch results from Apify Actors.
32
+ The Apify-Haystack integration allows easy interaction between the Apify platform and Haystack.
33
33
 
34
- 🚧 **Work In Progress** 🚧
34
+ Apify is a platform for web scraping, data extraction, and web automation tasks.
35
+ It provides serverless applications called Actors for different tasks, like crawling websites, and scraping Facebook, Instagram, and Google results, etc.
35
36
 
36
- This project is currently under active development.
37
+ Haystack offers an ecosystem of tools for building, managing, and deploying search engines and LLM applications.
37
38
 
38
39
  ## Installation
39
40
 
@@ -45,9 +46,10 @@ pip install apify-haystack
45
46
 
46
47
  ## Examples
47
48
 
48
- Here are some practical examples to help you get started ...
49
-
50
- ## Features
49
+ - Load a dataset from Apify and convert it to Haystack Documents: [apify_dataset_load.py](src/apify_haystack/examples/apify_dataset_load.py)
50
+ - Call Apify Actor and load a dataset to convert it to Haystack Documents: [apify_actor_call.py](src/apify_haystack/examples/apify_actor_call.py)
51
+ - Crawl website, scrape text content, and store it in the InMemoryDocumentStore: [crawl_and_process_data.py](src/apify_haystack/examples/crawl_and_process_data.py)
52
+ - Retrieval-Augmented Generation (RAG): Extracting text content from a website and using it for question answering [rag_with_crawled_website.py](src/apify_haystack/examples/rag_with_crawled_website.py)
51
53
 
52
54
  ## Support
53
55
 
@@ -0,0 +1,38 @@
1
+ # Apify-Haystack integration
2
+
3
+ The Apify-Haystack integration allows easy interaction between the Apify platform and Haystack.
4
+
5
+ Apify is a platform for web scraping, data extraction, and web automation tasks.
6
+ It provides serverless applications called Actors for different tasks, like crawling websites, and scraping Facebook, Instagram, and Google results, etc.
7
+
8
+ Haystack offers an ecosystem of tools for building, managing, and deploying search engines and LLM applications.
9
+
10
+ ## Installation
11
+
12
+ Apify-haystack is available as the [`apify-haystack`](https://pypi.org/project/apify-haystack/) PyPI package.
13
+
14
+ ```sh
15
+ pip install apify-haystack
16
+ ```
17
+
18
+ ## Examples
19
+
20
+ - Load a dataset from Apify and convert it to Haystack Documents: [apify_dataset_load.py](src/apify_haystack/examples/apify_dataset_load.py)
21
+ - Call Apify Actor and load a dataset to convert it to Haystack Documents: [apify_actor_call.py](src/apify_haystack/examples/apify_actor_call.py)
22
+ - Crawl website, scrape text content, and store it in the InMemoryDocumentStore: [crawl_and_process_data.py](src/apify_haystack/examples/crawl_and_process_data.py)
23
+ - Retrieval-Augmented Generation (RAG): Extracting text content from a website and using it for question answering [rag_with_crawled_website.py](src/apify_haystack/examples/rag_with_crawled_website.py)
24
+
25
+ ## Support
26
+
27
+ If you find any bug or issue, please [submit an issue on GitHub](https://github.com/apify/apify-haystack/issues).
28
+ For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify), in GitHub Discussions or you can join our [Discord server](https://discord.com/invite/jyEM2PRvMU).
29
+
30
+ ## Contributing
31
+
32
+ Your code contributions are welcome, and you'll be praised for eternity!
33
+ If you have any ideas for improvements, either submit an issue or create a pull request.
34
+ For contribution guidelines and the code of conduct, see [CONTRIBUTING.md](https://github.com/apify/apify-haystack/blob/master/CONTRIBUTING.md).
35
+
36
+ ## License
37
+
38
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](https://github.com/apify/apify-haystack/blob/master/LICENSE) file for details.
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "apify_haystack"
7
- version = "0.0.1a3"
7
+ version = "0.0.1a5"
8
8
  description = "Apify-haystack integration"
9
9
  authors = ["Apify Technologies s.r.o. <support@apify.com>"]
10
10
  homepage = "https://apify.com"
@@ -44,7 +44,7 @@ keywords = [
44
44
  [tool.poetry.dependencies]
45
45
  python = "^3.9"
46
46
  apify-client = "^1.7.1"
47
- haystack-ai = "^2.3.0"
47
+ haystack-ai = "^2.3.1"
48
48
  python-dotenv = "^1.0.1"
49
49
 
50
50
  [tool.poetry.group.dev.dependencies]
@@ -1,4 +1,6 @@
1
1
  """
2
+ Crawl website, scrape text content, and store it in the InMemoryDocumentStore.
3
+
2
4
  This script demonstrates how to extract content from a website using the Apify actor: Website Content Crawler.
3
5
  The content is then cleaned, split into smaller chunks, embedded, and stored in the InMemoryDocumentStore.
4
6
 
@@ -14,17 +16,23 @@ meta: {'url': 'https://haystack.deepset.ai/overview/quick-start',
14
16
  .....
15
17
  """
16
18
 
19
+ import os
20
+
17
21
  from dotenv import load_dotenv
18
22
  from haystack import Document, Pipeline
19
- from haystack.components.embedders import SentenceTransformersDocumentEmbedder
23
+ from haystack.components.embedders import OpenAIDocumentEmbedder
20
24
  from haystack.components.preprocessors import DocumentCleaner, DocumentSplitter
21
25
  from haystack.components.writers import DocumentWriter
22
26
  from haystack.document_stores.in_memory import InMemoryDocumentStore
27
+ from haystack.utils.auth import Secret
23
28
 
24
29
  from apify_haystack import ApifyDatasetFromActorCall
25
30
 
26
- # Sey APIFY-API-TOKEN here or load it from .env file
27
- apify_token = "" or load_dotenv()
31
+ load_dotenv()
32
+
33
+ # Set APIFY-API-TOKEN here or use it from .env file
34
+ apify_token = "" or os.getenv("APIFY_API_TOKEN")
35
+ openai_api_key = "" or os.getenv("OPENAI_API_KEY")
28
36
 
29
37
  actor_id = "apify/website-content-crawler"
30
38
  run_input = {
@@ -46,7 +54,7 @@ print(f"Initialized InMemoryDocumentStore with {document_store.count_documents()
46
54
 
47
55
  document_cleaner = DocumentCleaner()
48
56
  document_splitter = DocumentSplitter(split_by="word", split_length=150, split_overlap=50)
49
- document_embedder = SentenceTransformersDocumentEmbedder(model="sentence-transformers/all-MiniLM-L6-v2")
57
+ document_embedder = OpenAIDocumentEmbedder(api_key=Secret.from_token(openai_api_key))
50
58
  document_writer = DocumentWriter(document_store)
51
59
 
52
60
  pipe = Pipeline()
@@ -73,5 +81,6 @@ pipe.run({"document_loader": {}})
73
81
  print(f"Added {document_store.count_documents()} to vector from Website Content Crawler")
74
82
 
75
83
  print("Retrieving documents from the document store: query='Haystack'")
84
+ print("query='Haystack'")
76
85
  for doc in document_store.bm25_retrieval("Haystack", top_k=1):
77
86
  print(doc)
@@ -1,8 +1,5 @@
1
1
  """
2
- Retrieval-Augmented Generation (RAG)
3
-
4
- This script demonstrates how to extract text content from a website, store it in a vector database, and use
5
- it for question answering.
2
+ Retrieval-Augmented Generation (RAG): Extracting text content from a website and using it for question answering.
6
3
 
7
4
  Steps involved:
8
5
  - Load environment variables, including API keys.
@@ -21,18 +18,23 @@ Haystack is an open-source framework for building production-ready LLM applicati
21
18
  ......
22
19
  """
23
20
 
21
+ import os
22
+
24
23
  from dotenv import load_dotenv
25
24
  from haystack import Document, Pipeline
26
25
  from haystack.components.builders import PromptBuilder
27
- from haystack.components.embedders import SentenceTransformersDocumentEmbedder, SentenceTransformersTextEmbedder
26
+ from haystack.components.embedders import OpenAIDocumentEmbedder, OpenAITextEmbedder
28
27
  from haystack.components.generators import OpenAIGenerator
29
28
  from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
30
29
  from haystack.document_stores.in_memory import InMemoryDocumentStore
30
+ from haystack.utils.auth import Secret
31
31
 
32
32
  from apify_haystack import ApifyDatasetFromActorCall
33
33
 
34
- # Load OPENAI_API_KEY and APIFY_API_TOKEN from .env file
34
+ # Set APIFY-API-TOKEN here or use it from .env file
35
35
  load_dotenv()
36
+ apify_token = "" or os.getenv("APIFY_API_TOKEN")
37
+ openai_api_key = "" or os.getenv("OPENAI_API_KEY")
36
38
 
37
39
  actor_id = "apify/website-content-crawler"
38
40
  run_input = {
@@ -50,12 +52,11 @@ apify_dataset_loader = ApifyDatasetFromActorCall(
50
52
  )
51
53
 
52
54
  # Components
55
+ print("Initializing components...")
53
56
  document_store = InMemoryDocumentStore()
54
57
 
55
- docs_embedder = SentenceTransformersDocumentEmbedder(model="sentence-transformers/all-MiniLM-L6-v2")
56
- docs_embedder.warm_up()
57
- text_embedder = SentenceTransformersTextEmbedder(model="sentence-transformers/all-MiniLM-L6-v2")
58
- text_embedder.warm_up()
58
+ docs_embedder = OpenAIDocumentEmbedder(api_key=Secret.from_token(openai_api_key))
59
+ text_embedder = OpenAITextEmbedder(api_key=Secret.from_token(openai_api_key))
59
60
  retriever = InMemoryEmbeddingRetriever(document_store)
60
61
  generator = OpenAIGenerator(model="gpt-3.5-turbo")
61
62
 
@@ -79,6 +80,7 @@ Answer:
79
80
  prompt_builder = PromptBuilder(template=template)
80
81
 
81
82
  # Add components to your pipeline
83
+ print("Initializing pipeline...")
82
84
  pipe = Pipeline()
83
85
  pipe.add_component("embedder", text_embedder)
84
86
  pipe.add_component("retriever", retriever)
@@ -92,6 +94,9 @@ pipe.connect("prompt_builder", "llm")
92
94
 
93
95
  question = "What is haystack?"
94
96
 
97
+ print("Running pipeline ... crawling will take some time ...")
98
+ print("You can visit https://console.apify.com/actors/runs to monitor the progress")
99
+
95
100
  response = pipe.run({"embedder": {"text": question}, "prompt_builder": {"question": question}})
96
101
 
97
102
  print(f"question: {question}")
@@ -105,4 +110,5 @@ examples = [
105
110
 
106
111
  for example in examples:
107
112
  response = pipe.run({"embedder": {"text": example}, "prompt_builder": {"question": example}})
108
- print(response["llm"]["replies"][0])
113
+ print(f"question: {question}")
114
+ print(f"answer: {response['llm']['replies'][0]}")
@@ -1,36 +0,0 @@
1
- # Apify-Haystack integration
2
-
3
- Apify-Haystack integration allows to quickly fetch results from Apify Actors.
4
-
5
- 🚧 **Work In Progress** 🚧
6
-
7
- This project is currently under active development.
8
-
9
- ## Installation
10
-
11
- Apify-haystack is available as the [`apify-haystack`](https://pypi.org/project/apify-haystack/) PyPI package.
12
-
13
- ```sh
14
- pip install apify-haystack
15
- ```
16
-
17
- ## Examples
18
-
19
- Here are some practical examples to help you get started ...
20
-
21
- ## Features
22
-
23
- ## Support
24
-
25
- If you find any bug or issue, please [submit an issue on GitHub](https://github.com/apify/apify-haystack/issues).
26
- For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify), in GitHub Discussions or you can join our [Discord server](https://discord.com/invite/jyEM2PRvMU).
27
-
28
- ## Contributing
29
-
30
- Your code contributions are welcome, and you'll be praised for eternity!
31
- If you have any ideas for improvements, either submit an issue or create a pull request.
32
- For contribution guidelines and the code of conduct, see [CONTRIBUTING.md](https://github.com/apify/apify-haystack/blob/master/CONTRIBUTING.md).
33
-
34
- ## License
35
-
36
- This project is licensed under the Apache License 2.0 - see the [LICENSE](https://github.com/apify/apify-haystack/blob/master/LICENSE) file for details.