Repository: deepset-ai/haystack

Issue:
Add Azure Chat GPT Endpoints to the Chat Invocation Layer
**Is your feature request related to a problem? Please describe.**
The OpenAI Chat Invocation layer is pretty cool, but it doesn't support Azure Chat endpoints.

**Describe the solution you'd like**
Add Azure Chat endpoints to allow you to chat to Azure OpenAI API's, rather than OpenAI's, in the same way the OpenAI Invocation Layer has an Azure equivalent.

**Describe alternatives you've considered**
None.

**Additional context**
None.



Discussion:

Resolving patch:
diff --git a/haystack/nodes/prompt/invocation_layer/__init__.py b/haystack/nodes/prompt/invocation_layer/__init__.py
--- a/haystack/nodes/prompt/invocation_layer/__init__.py
+++ b/haystack/nodes/prompt/invocation_layer/__init__.py
@@ -1,6 +1,7 @@
 from haystack.nodes.prompt.invocation_layer.azure_open_ai import AzureOpenAIInvocationLayer
 from haystack.nodes.prompt.invocation_layer.base import PromptModelInvocationLayer
 from haystack.nodes.prompt.invocation_layer.chatgpt import ChatGPTInvocationLayer
+from haystack.nodes.prompt.invocation_layer.azure_chatgpt import AzureChatGPTInvocationLayer
 from haystack.nodes.prompt.invocation_layer.handlers import TokenStreamingHandler, DefaultTokenStreamingHandler
 from haystack.nodes.prompt.invocation_layer.hugging_face import HFLocalInvocationLayer
 from haystack.nodes.prompt.invocation_layer.hugging_face_inference import HFInferenceEndpointInvocationLayer
diff --git a/haystack/nodes/prompt/invocation_layer/azure_chatgpt.py b/haystack/nodes/prompt/invocation_layer/azure_chatgpt.py
new file mode 100644
--- /dev/null
+++ b/haystack/nodes/prompt/invocation_layer/azure_chatgpt.py
@@ -0,0 +1,47 @@
+from typing import Dict, Optional
+
+from haystack.nodes.prompt.invocation_layer.chatgpt import ChatGPTInvocationLayer
+
+
+class AzureChatGPTInvocationLayer(ChatGPTInvocationLayer):
+    """
+    Azure ChatGPT Invocation Layer
+
+    This layer is used to invoke the ChatGPT API on Azure. It is essentially the same as the ChatGPTInvocationLayer
+    with additional two parameters: `azure_base_url` and `azure_deployment_name`. The `azure_base_url` is the URL of the Azure OpenAI
+    endpoint and the `azure_deployment_name` is the name of the deployment.
+    """
+
+    def __init__(
+        self,
+        azure_base_url: str,
+        azure_deployment_name: str,
+        api_key: str,
+        api_version: str = "2023-03-15-preview",
+        model_name_or_path: str = "gpt-35-turbo",
+        max_length: Optional[int] = 800,
+        **kwargs,
+    ):
+        super().__init__(api_key, model_name_or_path, max_length, **kwargs)
+        self.azure_base_url = azure_base_url
+        self.azure_deployment_name = azure_deployment_name
+        self.api_version = api_version
+
+    @property
+    def url(self) -> str:
+        return f"{self.azure_base_url}/openai/deployments/{self.azure_deployment_name}/chat/completions?api-version={self.api_version}"
+
+    @property
+    def headers(self) -> Dict[str, str]:
+        return {"api-key": self.api_key, "Content-Type": "application/json"}
+
+    @classmethod
+    def supports(cls, model_name_or_path: str, **kwargs) -> bool:
+        """
+        Ensures Azure ChatGPT Invocation Layer is selected when `azure_base_url` and `azure_deployment_name` are provided in
+        addition to a list of supported models.
+        """
+        valid_model = any(m for m in ["gpt-35-turbo", "gpt-4", "gpt-4-32k"] if m in model_name_or_path)
+        return (
+            valid_model and kwargs.get("azure_base_url") is not None and kwargs.get("azure_deployment_name") is not None
+        )
diff --git a/haystack/nodes/prompt/prompt_model.py b/haystack/nodes/prompt/prompt_model.py
--- a/haystack/nodes/prompt/prompt_model.py
+++ b/haystack/nodes/prompt/prompt_model.py
@@ -11,7 +11,7 @@
 
 
 def instruction_following_models() -> List[str]:
-    return ["flan", "mt0", "bloomz", "davinci", "opt-iml", "gpt-3.5-turbo", "gpt-4"]
+    return ["flan", "mt0", "bloomz", "davinci", "opt-iml", "gpt-3.5-turbo", "gpt-4", "gpt-35-turbo", "gpt-4-32k"]
 
 
 class PromptModel(BaseComponent):


Test patch: