llama_index icon indicating copy to clipboard operation
llama_index copied to clipboard

Bug: GPTSimpleVectorIndex() does not work with Azure

Open siddhant01 opened this issue 2 years ago • 1 comments

the below code does not work

llm = AzureOpenAI(deployment_name="deployment_name", model_kwargs={
    "api_key": "api_key",
    "api_base": "api_base",
    "api_type": "azure",
    "api_version": "2022-12-01",
})
llm_predictor = LLMPredictor(llm=llm)

embedding_llm = LangchainEmbedding(OpenAIEmbeddings(
    document_model_name="document_model_name",
    query_model_name="text-embedding-ada-002"
))

documents = SimpleDirectoryReader('data/').load_data()

prompt_helper = PromptHelper(500, 48, 20)
index = GPTSimpleVectorIndex(documents, embed_model=embedding_llm, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
print(index.query('what is the boy name'))

the above gives the error

openai.error.AuthenticationError: Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.

but the same code with GPTListIndex works

llm = AzureOpenAI(deployment_name="deployment_name", model_kwargs={
    "api_key": "api_key",
    "api_base": "api_base",
    "api_type": "azure",
    "api_version": "2022-12-01",
})
llm_predictor = LLMPredictor(llm=llm)

embedding_llm = LangchainEmbedding(OpenAIEmbeddings(
    document_model_name="document_model_name",
    query_model_name="text-embedding-ada-002"
))

documents = SimpleDirectoryReader('data/').load_data()

prompt_helper = PromptHelper(500, 48, 20)
index = GPTListIndex(documents, embed_model=embedding_llm, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
print(index.query('what is the boy name'))

Note: the credentials were same for both of them

siddhant01 avatar Mar 03 '23 04:03 siddhant01

hey @siddhant01, it may be because you're using the openai embedding api in the first approach (not the azure one). have you tried setting openai_api_key to see if it works?

jerryjliu avatar Mar 06 '23 21:03 jerryjliu

Closing since the thread is stale, and most likely a configuration problem.

Disiok avatar Mar 25 '23 02:03 Disiok

did you solve your error? i am having same issue.

from llama_index import LLMPredictor
from langchain.llms import AzureOpenAI
from llama_index import LangchainEmbedding
from langchain.embeddings import OpenAIEmbeddings

from llama_index.indices.query.query_transform import HyDEQueryTransform
from llama_index.query_engine.transform_query_engine import TransformQueryEngine


# define LLM
llm_predictor = LLMPredictor(llm=AzureOpenAI(temperature=0, model_name="gpt-3.5-turbo", engine="GPT35turbooooo"))

embedding_llm = LangchainEmbedding(
    OpenAIEmbeddings(
        model="text-embedding-ada-002",
        deployment="ada002",
    ),
    embed_batch_size=1,
)

from llama_index import set_global_service_context


# configure service context
service_context = ServiceContext.from_defaults(
    llm_predictor=llm_predictor, 
    embed_model=embedding_llm, 
    chunk_size=1000, 
    chunk_overlap=200
)
set_global_service_context(service_context)

# build index
index = GPTVectorStoreIndex(
    nodes
)

Error: AuthenticationError: Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.

sid8491 avatar Jul 10 '23 07:07 sid8491