os.environ["OPENAI_API_KEY"] = args.openai_key os.environ["OPENAI_API_BASE"] = args.openai_host openai.api_type = "azure" openai.api_version = "2023-03-15" openai.api_base = os.getenv('OPENAI_API_BASE') openai.api_key = os.getenv("OPENAI_API_KEY")
openai.error.InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.embedding.Embedding'>
llm = AzureOpenAI(temperature=0, model_name=args.model_name, deployment_name=args.model_name)
index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context)
0.6.9
but it doesn't work still.openai.error.InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.embedding.Embedding'>
index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context)
def create_service_context(): # define LLM if openai.api_type == "azure": # Use Azure OpenAI API logging.info("Using Azure OpenAI.") #llm = AzureOpenAI(temperature=0, model_name=args.model_name, deployment_name=args.model_name) llm = AzureOpenAI( deployment_name=args.model_name, temperature=0, model_kwargs={ "api_key": openai.api_key, "api_base": openai.api_base, "api_type": openai.api_type, "api_version": openai.api_version, } ) else: # Using OpenAI API if args.model_name == "gpt-3.5-turbo": logging.info("Using ChatOpenAI.") llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo") else: logging.info("Using OpenAI.") llm = OpenAI(temperature=0, model_name=args.model_name) # Define LLMPredictor llm_predictor = LLMPredictor(llm=llm) # Define Embedding Model embedding_llm = LangchainEmbedding( OpenAIEmbeddings( model="text-embedding-ada-002", deployment="text-embedding-ada-002", openai_api_key=openai.api_key, openai_api_base=openai.api_base, openai_api_type=openai.api_type, openai_api_version=openai.api_version, ), embed_batch_size=1, ) # define prompt helper # set maximum input size max_input_size = 4096 # set number of output tokens num_output = 256 # set maximum chunk overlap max_chunk_overlap = 20 prompt_helper = PromptHelper(max_input_size, num_output, max_chunk_overlap) return ServiceContext.from_defaults( llm_predictor=llm_predictor, prompt_helper=prompt_helper, embed_model=embedding_llm )
from llama_index import ServiceContext, GPTVectorStoreIndex, LLMPredictor, LangchainEmbedding, SimpleDirectoryReader from langchain.chat_models import AzureChatOpenAI from langchain.embeddings import OpenAIEmbeddings API_KEY = "<my key>" API_BASE = "https://<resource name>.openai.azure.com/" files_path = "/Users/abissell/az/files/" embed_deployment_name = "" chat_deployment_name = "" embedding = OpenAIEmbeddings( deployment=embed_deployment_name, openai_api_key=API_KEY, openai_api_base=API_BASE, openai_api_type="azure", openai_api_version="2022-12-01", ) embedding_llm = LangchainEmbedding(embedding, embed_batch_size=1) llm = AzureChatOpenAI( deployment_name=chat_deployment_name, openai_api_key=API_KEY, openai_api_base=API_BASE, openai_api_type="azure", openai_api_version="2023-03-15-preview", ) llm_predictor = LLMPredictor(llm=llm) service_context = ServiceContext.from_defaults( llm_predictor=llm_predictor, embed_model=embedding_llm, ) documents = SimpleDirectoryReader(files_path).load_data() index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context) query_engine = index.as_query_engine() print(query_engine.query("sample"))