Repository: deepset-ai/haystack

Issue:
OpenAIAnswerGenerator not working with custom prompt_template
**Describe the bug**
`class OpenAIAnswerGenerato` has an error in the required params check.
https://github.com/deepset-ai/haystack/blob/e6af353530a723344ad607d903a46121374ea61d/haystack/nodes/answer_generator/openai.py#L141

**Error message**
```ValueError                                Traceback (most recent call last)
[<ipython-input-41-fbc29f0e30ff>](https://localhost:8080/#) in <module>
      7 required_params = ["context", "query"]
      8 if all(p in lfqa_prompt.prompt_params for p in required_params):
----> 9     raise ValueError(
     10         "The OpenAIAnswerGenerator requires a PromptTemplate that has `context` and "
     11         "`query` in its `prompt_params`. Supply a different `prompt_template` or "

ValueError: The OpenAIAnswerGenerator requires a PromptTemplate that has `context` and `query` in its `prompt_params`. Supply a different `prompt_template` or use the default one.
```


**To Reproduce**
```from haystack.nodes import OpenAIAnswerGenerator,PromptTemplate
lfqa_prompt = PromptTemplate(name="lfqa",
                             prompt_text=""" 
                             Synthesize a comprehensive answer from your knowledge and the following topk most relevant paragraphs and the given question. 
                             \n===\Paragraphs: $context\n===\n$query""",
                              prompt_params=["context", "query"]) 
# Let's initiate the OpenAIAnswerGenerator 
generator = OpenAIAnswerGenerator(
    api_key='',
    model="text-curie-001",
    max_tokens=500,
    presence_penalty=0.1,
    frequency_penalty=0.1,
    top_k=1,
    temperature=0.3,
    prompt_template=lfqa_prompt
)```


**System:**
 - Haystack version (commit or version number): 1.13.2



Discussion:
Seems like this is a bug, where on the 8th line should be `if not all(p in lfqa_prompt.prompt_params for p in required_params):` 

Resolving patch:
diff --git a/haystack/nodes/answer_generator/openai.py b/haystack/nodes/answer_generator/openai.py
--- a/haystack/nodes/answer_generator/openai.py
+++ b/haystack/nodes/answer_generator/openai.py
@@ -138,7 +138,7 @@ def __init__(
         else:
             # Check for required prompts
             required_params = ["context", "query"]
-            if all(p in prompt_template.prompt_params for p in required_params):
+            if not all(p in prompt_template.prompt_params for p in required_params):
                 raise ValueError(
                     "The OpenAIAnswerGenerator requires a PromptTemplate that has `context` and "
                     "`query` in its `prompt_params`. Supply a different `prompt_template` or "


Test patch:
diff --git a/test/nodes/test_generator.py b/test/nodes/test_generator.py
--- a/test/nodes/test_generator.py
+++ b/test/nodes/test_generator.py
@@ -7,6 +7,7 @@
 from haystack.schema import Document
 from haystack.nodes.answer_generator import Seq2SeqGenerator, OpenAIAnswerGenerator
 from haystack.pipelines import TranslationWrapperPipeline, GenerativeQAPipeline
+from haystack.nodes import PromptTemplate
 
 import logging
 
@@ -142,6 +143,26 @@ def test_openai_answer_generator(openai_generator, docs):
     assert "Carla" in prediction["answers"][0].answer
 
 
+@pytest.mark.integration
+@pytest.mark.skipif(
+    not os.environ.get("OPENAI_API_KEY", None),
+    reason="No OpenAI API key provided. Please export an env var called OPENAI_API_KEY containing the OpenAI API key to run this test.",
+)
+def test_openai_answer_generator_custom_template(docs):
+    lfqa_prompt = PromptTemplate(
+        name="lfqa",
+        prompt_text="""
+        Synthesize a comprehensive answer from your knowledge and the following topk most relevant paragraphs and the given question.
+        \n===\Paragraphs: $context\n===\n$query""",
+        prompt_params=["context", "query"],
+    )
+    node = OpenAIAnswerGenerator(
+        api_key=os.environ.get("OPENAI_API_KEY", ""), model="text-babbage-001", top_k=1, prompt_template=lfqa_prompt
+    )
+    prediction = node.predict(query="Who lives in Berlin?", documents=docs, top_k=1)
+    assert len(prediction["answers"]) == 1
+
+
 @pytest.mark.integration
 @pytest.mark.skipif(
     not os.environ.get("OPENAI_API_KEY", None),