Skip to content

Commit

Permalink
Fix affected snippets after the breaking changes (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
bilgeyucel authored Feb 7, 2024
1 parent e642229 commit 3274994
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 15 deletions.
6 changes: 4 additions & 2 deletions integrations/assemblyai.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ The example below illustrates a generative QA pipeline that seamlessly integrate

```python
from haystack import Pipeline
from haystack.utils import Secret
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
from haystack.components.builders.prompt_builder import PromptBuilder
from haystack.components.generators import OpenAIGenerator
Expand All @@ -133,7 +134,7 @@ Question: {{ question }}
summary_qa = Pipeline()
summary_qa.add_component("transcriber", AssemblyAITranscriber(api_key=assemblyai_api_key))
summary_qa.add_component("prompt_builder", PromptBuilder(template=template))
summary_qa.add_component("llm", OpenAIGenerator(api_key=openai_api_key, model_name="gpt-3.5-turbo"))
summary_qa.add_component("llm", OpenAIGenerator(api_key=Secret.from_token("YOUR_OPENAI_API_KEY"), model="gpt-3.5-turbo"))
summary_qa.connect("transcriber.summarization", "prompt_builder.summary")
summary_qa.connect("prompt_builder", "llm")

Expand All @@ -152,6 +153,7 @@ Explore the example below to see how to index speaker diarization information an
```python
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack import Pipeline
from haystack.utils import Secret
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
from haystack.components.builders.prompt_builder import PromptBuilder
from haystack.components.generators import OpenAIGenerator
Expand All @@ -176,7 +178,7 @@ Question: {{ question }}
pipe = Pipeline()
pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store, top_k=3))
pipe.add_component("prompt_builder", PromptBuilder(template=template))
pipe.add_component("llm", OpenAIGenerator(api_key=openai_api_key, model_name="gpt-3.5-turbo"))
pipe.add_component("llm", OpenAIGenerator(api_key=Secret.from_token("YOUR_OPENAI_API_KEY"), model="gpt-3.5-turbo"))

pipe.connect("retriever", "prompt_builder.documents")
pipe.connect("prompt_builder", "llm")
Expand Down
3 changes: 2 additions & 1 deletion integrations/huggingface.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Below is the example query pipeline that uses `mistralai/Mistral-7B-v0.1` hosted

```python
from haystack import Pipeline
from haystack.utils import Secret
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
from haystack.components.builders.prompt_builder import PromptBuilder
from haystack.components.generators import HuggingFaceTGIGenerator
Expand All @@ -98,7 +99,7 @@ pipe = Pipeline()

pipe.add_component("retriever", InMemoryBM25Retriever(document_store=docstore))
pipe.add_component("prompt_builder", PromptBuilder(template=template))
pipe.add_component("llm", HuggingFaceTGIGenerator(model="mistralai/Mistral-7B-v0.1", token="HF_TOKEN"))
pipe.add_component("llm", HuggingFaceTGIGenerator(model="mistralai/Mistral-7B-v0.1", token=Secret.from_token("YOUR_HF_API_TOKEN")))
pipe.connect("retriever", "prompt_builder.documents")
pipe.connect("prompt_builder", "llm")

Expand Down
2 changes: 1 addition & 1 deletion integrations/instructor-embedder.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ indexing_pipeline.add_component(
instance=DocumentWriter(document_store=doc_store), name="DocWriter"
)
# Connect the output of DocEmbedder to the input of DocWriter
indexing_pipeline.connect(connect_from="DocEmbedder", connect_to="DocWriter")
indexing_pipeline.connect("DocEmbedder", "DocWriter")

# Load the 'XSum' dataset from HuggingFace (https://huggingface.co/datasets/xsum)
dataset = load_dataset("xsum", split="train")
Expand Down
2 changes: 1 addition & 1 deletion integrations/llama_cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ doc_embedder = SentenceTransformersDocumentEmbedder(model="sentence-transformers
indexing_pipeline = Pipeline()
indexing_pipeline.add_component(instance=doc_embedder, name="DocEmbedder")
indexing_pipeline.add_component(instance=DocumentWriter(document_store=doc_store), name="DocWriter")
indexing_pipeline.connect(connect_from="DocEmbedder", connect_to="DocWriter")
indexing_pipeline.connect("DocEmbedder", "DocWriter")

indexing_pipeline.run({"DocEmbedder": {"documents": docs}})
```
Expand Down
2 changes: 1 addition & 1 deletion integrations/lmformatenforcer.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ schema_json_str = AnswerFormat.schema_json()
prompt = f'{question}{schema_json_str}'


model = HuggingFaceLocalGenerator(model_name_or_path="meta-llama/Llama-2-7b-chat-hf")
model = HuggingFaceLocalGenerator(model="meta-llama/Llama-2-7b-chat-hf")
format_enforcer = LMFormatEnforcerLocalGenerator(model, character_level_parser)
pipeline = Pipeline()
pipeline.add_component(instance=format_enforcer, name='model')
Expand Down
3 changes: 2 additions & 1 deletion integrations/mastodon-fetcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ mastodon_fetcher.run(username="[email protected]")

```python
from haystack import Pipeline
from haystack.utils import Secret
from mastodon_fetcher_haystack.mastodon_fetcher import MastodonFetcher
from haystack.components.generators import OpenAIGenerator
from haystack.components.builders import PromptBuilder

prompt_builder = PromptBuilder(template='YOUR_PROMPT_TEMPLATE')
llm = OpenAIGenerator(api_key'YOUR_OPENAI_API_KEY')
llm = OpenAIGenerator(api_key=Secret.from_token("YOUR_OPENAI_API_KEY"))

pipe = Pipeline()
pipe.add_component("fetcher", mastodon_fetcher)
Expand Down
14 changes: 8 additions & 6 deletions integrations/openai.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Below is the example indexing pipeline with `InMemoryDocumentStore`, `OpenAIDocu

```python
from haystack import Document, Pipeline
from haystack.utils import Secret
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.embedders import OpenAIDocumentEmbedder
from haystack.components.writers import DocumentWriter
Expand All @@ -61,7 +62,7 @@ documents = [Document(content="My name is Wolfgang and I live in Berlin"),
Document(content="Germany has many big cities")]

indexing_pipeline = Pipeline()
indexing_pipeline.add_component("embedder", OpenAIDocumentEmbedder(api_key="OPENAI_API_KEY", model="text-embedding-ada-002"))
indexing_pipeline.add_component("embedder", OpenAIDocumentEmbedder(api_key=Secret.from_token("YOUR_OPENAI_API_KEY"), model="text-embedding-ada-002"))
indexing_pipeline.add_component("writer", DocumentWriter(document_store=document_store))
indexing_pipeline.connect("embedder", "writer")

Expand All @@ -70,17 +71,18 @@ indexing_pipeline.run({"embedder": {"documents": documents}})

#### Generative Models (LLMs)

You can leverage OpenAI models through two components: [GPTGenerator](https://docs.haystack.deepset.ai/v2.0/docs/gptgenerator) and [GPTChatGenerator](https://docs.haystack.deepset.ai/v2.0/docs/gptchatgenerator).
You can leverage OpenAI models through two components: [OpenAIGenerator](https://docs.haystack.deepset.ai/v2.0/docs/openaigenerator) and [OpenAIChatGenerator](https://docs.haystack.deepset.ai/v2.0/docs/openaichatgenerator).

To use OpenAI's GPT models for text generation, initialize a `GPTGenerator` with the model name and OpenAI API key. You can then use the `GPTGenerator` instance in a question answering pipeline after the `PromptBuilder`.
To use OpenAI's GPT models for text generation, initialize a `OpenAIGenerator` with the model name and OpenAI API key. You can then use the `OpenAIGenerator` instance in a question answering pipeline after the `PromptBuilder`.

Below is the example of generative questions answering pipeline using RAG with `PromptBuilder` and `GPTGenerator`:
Below is the example of generative questions answering pipeline using RAG with `PromptBuilder` and `OpenAIGenerator`:

```python
from haystack import Pipeline
from haystack.utils import Secret
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
from haystack.components.builders.prompt_builder import PromptBuilder
from haystack.components.generators import GPTGenerator
from haystack.components.generators import OpenAIGenerator

template = """
Given the following information, answer the question.
Expand All @@ -96,7 +98,7 @@ pipe = Pipeline()

pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
pipe.add_component("prompt_builder", PromptBuilder(template=template))
pipe.add_component("llm", GPTGenerator(model="gpt-4", api_key="OPENAI_API_KEY"))
pipe.add_component("llm", OpenAIGenerator(model="gpt-4", api_key=Secret.from_token("YOUR_OPENAI_API_KEY")))
pipe.connect("retriever", "prompt_builder.documents")
pipe.connect("prompt_builder", "llm")

Expand Down
3 changes: 2 additions & 1 deletion integrations/pinecone-document-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ indexing.run({"converter": {"sources": ["filename.md"]}})
Once you have documents in your `PineconeDocumentStore`, it's ready to be used in any Haystack pipeline. Then, you can use `PineconeDenseRetriever` to retrieve data from your PineconeDocumentStore. For example, below is a pipeline that makes use of a custom prompt that is designed to answer questions for the retrieved documents.

```python
from haystack.utils import Secret
from haystack.components.embedders import SentenceTransformersTextEmbedder
from haystack.components.builders import PromptBuilder
from haystack.components.generators import OpenAIGenerator
Expand All @@ -125,7 +126,7 @@ query_pipeline = Pipeline()
query_pipeline.add_component("text_embedder", SentenceTransformersTextEmbedder())
query_pipeline.add_component("retriever", PineconeDenseRetriever(document_store=document_store))
query_pipeline.add_component("prompt_builder", PromptBuilder(template=prompt_template))
query_pipeline.add_component("generator", OpenAIGenerator(api_key=YOUR_OPENAI_KEY, model="gpt-4"))
query_pipeline.add_component("generator", OpenAIGenerator(api_key=Secret.from_token("YOUR_OPENAI_API_KEY"), model="gpt-4"))
query_pipeline.connect("text_embedder.embedding", "retriever.query_embedding")
query_pipeline.connect("retriever.documents", "prompt_builder.documents")
query_pipeline.connect("prompt_builder", "generator")
Expand Down
2 changes: 1 addition & 1 deletion integrations/voyage.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ doc_embedder = VoyageDocumentEmbedder(
indexing_pipeline = Pipeline()
indexing_pipeline.add_component(instance=doc_embedder, name="DocEmbedder")
indexing_pipeline.add_component(instance=DocumentWriter(document_store=doc_store), name="DocWriter")
indexing_pipeline.connect(connect_from="DocEmbedder", connect_to="DocWriter")
indexing_pipeline.connect("DocEmbedder", "DocWriter")

indexing_pipeline.run({"DocEmbedder": {"documents": docs}})

Expand Down

0 comments on commit 3274994

Please sign in to comment.