langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
92.47k stars 14.79k forks source link

DALLEAPIWrapper to support Azure OpenAI #14625

Closed mingqxu7 closed 6 months ago

mingqxu7 commented 9 months ago

Feature request

Azure OpenAI now previews the DALLE-3 model. Today, DALLEAPIWrapper only supports the openai API.

Motivation

My customers are using Azure OpenAI and would like to use DALL-E-3 in their solutions.

Your contribution

PR may not be possible but I'd like to help anyway I can.

dosubot[bot] commented 9 months ago

🤖

Hey @mingqxu7! Nice to see you again, hope you're doing well. Your contribution to the LangChain repo has always been truly valuable. Let's dive into this issue.

Thank you for your feature request, mingqxu7. It's indeed possible to extend the DALLEAPIWrapper in the LangChain framework to support Azure OpenAI's DALL-E-3 model.

The LangChain framework already has a class AzureOpenAI which is used for Azure-specific OpenAI large language models. This class can be extended or modified to support the DALL-E-3 model.

Here is a simple example of how you might extend the AzureOpenAI class to support DALL-E-3:

class AzureDALLE3(AzureOpenAI):
    """Azure-specific OpenAI DALL-E-3 model.

    To use, you should have the ``openai`` python package installed, and the
    environment variable ``OPENAI_API_KEY`` set with your API key.

    Any parameters that are valid to be passed to the openai.create call can be passed
    in, even if not explicitly saved on this class.

    Example:
        .. code-block:: python

            from langchain.llms import AzureDALLE3
            dalle3 = AzureDALLE3(model_name="dalle-3")
    """

    model_name: str = "dalle-3"
    """Model name to use."""

In this example, we create a new class AzureDALLE3 that inherits from AzureOpenAI. We then override the model_name attribute to be "dalle-3", which is the name of the DALL-E-3 model.

Please note that this is a simplified example and you may need to add more code to handle specific features or requirements of the DALL-E-3 model. You can refer to the source code for more details.

As for your offer to contribute, while I can't create PRs, I can certainly help guide you through the process. If you have any questions or need further clarification, feel free to ask.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

mingqxu7 commented 9 months ago

The DALL-E 3 model indeed presents a distinct approach compared to Azure OpenAI. While your suggestion is certainly valid, my preference for LangChain is primarily due to its ability to abstract away the low-level details, streamlining the workflow significantly. This advantage is not just limited to my use case but extends to many others who integrate Azure OpenAI with LangChain. This integration effectively bridges the gap between high-level functionality and user accessibility, making it a preferred choice for those seeking efficiency and ease of use in their AI-powered applications.