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

[Bug]: Azure openai support Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.embedding.Embedding'> #591

Open
gayathri7219 opened this issue Dec 29, 2023 · 0 comments

Comments

@gayathri7219
Copy link

Current Behavior

In the Gptcache.core to work with the Azure Openai adapter the code is as shown below
`@staticmethod
def set_azure_openai_key():
import_openai()
import openai # pylint: disable=C0415

    openai.api_type = "azure"
    openai.api_key = os.getenv("OPENAI_API_KEY")
    openai.api_base = os.getenv("OPENAI_API_BASE")
    openai.api_version = os.getenv("OPENAI_API_VERSION")

cache = Cache()
`

Here the version of openai is 0.28 because in openai version 0.28 we set the endpoint as openai.api_base where as in openai version >=1.x we set endpoint as azure_endpoint
you can refer the below link where the format is defined.
https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?tabs=command-line%2Cpython-new&pivots=programming-language-python

So we can confirm that gptcache works with openai version 0.28
But the issuse is if we can see the gptcache.embeddings. openai the code is as below where we are calling openai to embed the text . Here we are providing parameter model=self.model to openai which should be changed to engine=self.model if we are working with openai version 0.28 and model =self.model if we work with version 1.x
`def to_embeddings(self, data, **_):
"""Generate embedding given text input

    :param data: text in string.
    :type data: str

    :return: a text embedding in shape of (dim,).
    """
    sentence_embeddings = openai.Embedding.create(model=self.model, input=data, api_base=self.api_base)
    return np.array(sentence_embeddings["data"][0]["embedding"]).astype("float32"`

you can refer to the microsoft documents for the syntax of embeddings for openai version 0.28 and >=1.x
https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/embeddings?tabs=python

Because of the above param prblm i faced with the below error
Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.embedding.Embedding'>

Solved the issue by changing the param model to engine in gptcache.embeddings.openai file

Expected Behavior

No response

Steps To Reproduce

No response

Environment

No response

Anything else?

https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/embeddings?tabs=python

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

1 participant