zilliztech / GPTCache

Semantic cache for LLMs. Fully integrated with LangChain and llama_index.
https://gptcache.readthedocs.io
MIT License
6.89k stars 480 forks source link

[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 6 months ago

gayathri7219 commented 6 months ago

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 toembeddings(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