Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to connect with Azure OpenAI #1

Closed
chowdary1209 opened this issue Jul 12, 2023 · 3 comments
Closed

Not able to connect with Azure OpenAI #1

chowdary1209 opened this issue Jul 12, 2023 · 3 comments

Comments

@chowdary1209
Copy link

I am trying to utilize this library using Azure OpenAI. Here I am not directly connecting to OpenAI; here I have created a deployment in Azure, and with the help of that, I am connecting to OpenAI. Whenever i am connecting through Azure, I need to provide details like "openai.api_key", "openai.api_base", "openai.api_type," and engine/deployment_id, which were created in Azure Openai, to be passed to the "openai.ChatCompletion.create() method.

"Conversation" model asking for "model_id", Here I am trying to pass Azure "deployment_id" or "engine" but it's not working. I have passed "model_name" as well, but still it's showing me an error as "InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a ." I have attached the error screenshot.
image

Could you please make it work for the Azure OpenAI engine as well?

@rizerphe
Copy link
Owner

Sorry for making you wait. I do not have access to the Azure OpenAI service, still tried to implement a fix, though. Can you confirm whether updating the package and passing in the engine parameter (your deployment ID) into Conversation or nlp solves the issue?

@zwx00
Copy link

zwx00 commented Sep 27, 2023

Hey I was able to get this to work but with one catch.

openai.api_type = "azure"
openai.api_key = "..."
openai.api_base = "https://blabla.openai.azure.com"
openai.api_version = "2023-07-01-preview"
engine = "blabla"

conversation = openai_functions.Conversation(model="gpt-4", engine=engine)

There was an issue with Azure OpenAI implementation not returning the content field in messages. I had to make the below modification. Let me know if I'm using it wrong or should I open a PR for this.

# openai_types.py
class Message:
    # more stuff
    def __init__(
        self,
        message: MessageType | str,
        role: Literal["system", "user", "assistant"] = "user",
    ):
        if isinstance(message, str):
            if role == "assistant":  # We have to split this up because of mypy
                self.message: MessageType = {"role": role, "content": message}
            else:
                self.message = {
                    "role": role,
                    "content": message,
                }
        else:
            # NEW CODE 
            if "content" not in message:
                message["content"] = None
            # END NEW CODE

            self.message = message

Sorry for sharing code in this barbaric manner I'm super busy at the moment.

@rizerphe
Copy link
Owner

Thanks a lot for your time! I've just published this fix, it should be working out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants