I am trying to repeat code from Medium (https://medium.com/@kartik11721/implementing-retrieval-augmented-generation-rag-with-azure-openai-and-langchain-e2a6689ea52e), but i get a very weird error
BadRequestError: Error code: 400 - {'error': {'code': 'OperationNotSupported', 'message': 'The embeddings operation does not work with the specified model, gpt-4. Please choose different model and try again. You can learn more about which models can be used with each operation here: https://go.microsoft.com/fwlink/?linkid=2197993.'}}
import os
from dotenv import load_dotenv
# Correct imports based on your update
from langchain_community.document_loaders import TextLoader
from langchain_community.vectorstores import FAISS
from langchain_openai import AzureOpenAIEmbeddings
from langchain_text_splitters import RecursiveCharacterTextSplitter
def create_vector_database(txt_path):
# Initialize TextLoader with the absolute path to the txt file
loader = TextLoader(txt_path)
# Load documents from the file
docs = loader.load()
# Split documents into chunks
documents = RecursiveCharacterTextSplitter(
chunk_size=1000, separators=["\n", "\n\n"], chunk_overlap=200
).split_documents(docs)
# Initialize embeddings with Azure OpenAI settings
embeddings = AzureOpenAIEmbeddings(
azure_deployment=os.environ.get("AZURE_OPENAI_DEPLOYMENT"),
openai_api_version=os.environ.get("AZURE_OPENAI_API_VERSION"),
)
# Create a FAISS index from the documents and embeddings
db = FAISS.from_documents(
documents=documents,
embedding=embeddings
)
# Save the FAISS database locally
db.save_local("./faiss-db")
if __name__ == "__main__":
# Ensure that the environment variables are loaded (if using a .env file)
load_dotenv()
# Define the absolute path to the txt file
txt_path = '/home/anna/Desktop/simple_rag/ozimpic.txt'
# Call the function with the absolute path
create_vector_database(txt_path)