|
73 | 73 | "source": [
|
74 | 74 | "%%bash\n",
|
75 | 75 | "pip install haystack-ai\n",
|
76 |
| - "pip install \"sentence-transformers>=2.2.0\" \"huggingface_hub>=0.22.0\" transformers\n", |
| 76 | + "pip install \"sentence-transformers>=2.2.0\" \"huggingface_hub>=0.22.0\"\n", |
77 | 77 | "pip install markdown-it-py mdit_plain pypdf\n",
|
78 | 78 | "pip install gdown"
|
79 | 79 | ]
|
|
320 | 320 | "id": "I06qdWsZibSz"
|
321 | 321 | },
|
322 | 322 | "source": [
|
323 |
| - "Now, let's build a RAG pipeline that answers queries based on the documents you just created in the section above. For this step, we will be using the [`HuggingFaceTGIGenerator`](https://docs.haystack.deepset.ai/v2.0/docs/huggingfacetgigenerator) so must have a [Hugging Face API Key](https://huggingface.co/settings/tokens) for this section. We will be using the `mistralai/Mistral-7B-Instruct-v0.1` model." |
| 323 | + "Now, let's build a RAG pipeline that answers queries based on the documents you just created in the section above. For this step, we will be using the [`HuggingFaceAPIGenerator`](https://docs.haystack.deepset.ai/docs/huggingfaceapigenerator) so must have a [Hugging Face API Key](https://huggingface.co/settings/tokens) for this section. We will be using the `HuggingFaceH4/zephyr-7b-beta` model." |
324 | 324 | ]
|
325 | 325 | },
|
326 | 326 | {
|
|
371 | 371 | "from haystack.components.embedders import SentenceTransformersTextEmbedder\n",
|
372 | 372 | "from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever\n",
|
373 | 373 | "from haystack.components.builders import PromptBuilder\n",
|
374 |
| - "from haystack.components.generators import HuggingFaceTGIGenerator\n", |
| 374 | + "from haystack.components.generators import HuggingFaceAPIGenerator\n", |
375 | 375 | "\n",
|
376 | 376 | "template = \"\"\"\n",
|
377 | 377 | "Answer the questions based on the given context.\n",
|
|
388 | 388 | "pipe.add_component(\"embedder\", SentenceTransformersTextEmbedder(model=\"sentence-transformers/all-MiniLM-L6-v2\"))\n",
|
389 | 389 | "pipe.add_component(\"retriever\", InMemoryEmbeddingRetriever(document_store=document_store))\n",
|
390 | 390 | "pipe.add_component(\"prompt_builder\", PromptBuilder(template=template))\n",
|
391 |
| - "pipe.add_component(\"llm\", HuggingFaceTGIGenerator(\"mistralai/Mistral-7B-Instruct-v0.1\"))\n", |
| 391 | + "pipe.add_component(\n", |
| 392 | + " \"llm\",\n", |
| 393 | + " HuggingFaceAPIGenerator(api_type=\"serverless_inference_api\", api_params={\"model\": \"HuggingFaceH4/zephyr-7b-beta\"}),\n", |
| 394 | + ")\n", |
392 | 395 | "\n",
|
393 | 396 | "pipe.connect(\"embedder.embedding\", \"retriever.query_embedding\")\n",
|
394 | 397 | "pipe.connect(\"retriever\", \"prompt_builder.documents\")\n",
|
|
432 | 435 | },
|
433 | 436 | "source": [
|
434 | 437 | "```python\n",
|
435 |
| - "{'llm': {'replies': ['\\n\\nFor vegan keto eggplant lasagna, you would need:\\n\\n* 2 large eggplants\\n* a lot of salt (Hella salt)\\n* 1/2 cup store-bought vegan mozzarella (for topping)\\n* Pesto: 4 oz basil, 1/4 cup almonds, 1/4 cup nutritional yeast, 1/4 cup olive oil, 1 recipe vegan pesto, 1 recipe spinach tofu ricotta, 1 tsp garlic powder, juice of half a lemon, salt to taste\\n* Macadamia nut cheese: 1 cup macadamia nuts, 10 oz spinach, juice of 1 lemon, garlic powder to taste, salt to taste\\n\\nFor vegan persimmon flan, you would need:\\n\\n* ½ cup persimmon pulp, strained\\n* 1 tbsp cornstarch\\n* ½ tsp agar agar\\n* 1 tbsp agave nectar, or to taste\\n* 2 tbsp granulated sugar\\n* ¼ cup coconut creme\\n* ½ cup almond milk\\n* ½ tsp vanilla\\n\\nFor vegan hemp cheese, you would need:\\n\\n* ½ cup sunflower seeds\\n* ½ cup hemp hearts\\n* 1.5 teaspoons miso paste\\n* 1 tsp nutritional yeast\\n* ¼ cup rejuvelac*\\n* 1/4th teaspoon salt, or to taste\\n\\nNote:'],\n", |
436 |
| - " 'meta': [{'model': 'mistralai/Mistral-7B-Instruct-v0.1',\n", |
437 |
| - " 'index': 0,\n", |
438 |
| - " 'finish_reason': 'length',\n", |
439 |
| - " 'usage': {'completion_tokens': 350,\n", |
440 |
| - " 'prompt_tokens': 3454,\n", |
441 |
| - " 'total_tokens': 3804}}]}}\n", |
| 438 | + "{'llm': {'replies': [\"\\n\\nVegan Keto Eggplant Lasagna:\\n\\nIngredients:\\n- 2 large eggplants\\n- A lot of salt (you should have this in your house already)\\n- 1/2 cup store-bought vegan mozzarella (for topping)\\n\\nPesto:\\n- 4 oz basil (generally one large clamshell or 2 small ones)\\n- 1/4 cup almonds\\n- 1/4 cup nutritional yeast\\n- 1/4 cup olive oil\\n- 1 recipe vegan pesto (you can find this in the recipe)\\n- 1 recipe spinach tofu ricotta (you can find this in the recipe)\\n- 1 tsp garlic powder\\n- Juice of half a lemon\\n- Salt to taste\\n\\nSpinach Tofu Ricotta:\\n- 10 oz firm or extra firm tofu\\n- Juice of 1 lemon\\n- Garlic powder to taste\\n- Salt to taste\\n\\nInstructions:\\n1. Slice the eggplants into 1/4 inch thick slices. Some slices will need to be scrapped because it's difficult to get them all uniformly thin. Use them in soup or something, IDK, man.\\n2. Take the eggplant slices and rub both sides with salt. Don't be shy about how much, you're gonna rinse it off anyway.\\n3. Put them in a colander with something underneath it and let them sit for half an hour. This draws the water out so that the egg\"],\n", |
| 439 | + " 'meta': [{'model': 'HuggingFaceH4/zephyr-7b-beta',\n", |
| 440 | + " ...\n", |
| 441 | + " }]}}\n", |
442 | 442 | "```"
|
443 | 443 | ]
|
444 | 444 | },
|
|
0 commit comments