This repo contains a sample RAG based solution in promptflow using the SDK.
- Python 3.9 or Python 3.10
- promptflow sdk
- OpenAI API Key or Azure OpenAI APIP Key
- Azure Cognitive Search
To install the dependencies, run the following command:
pip install -r requirements.txtYou wll also need to create a .env file. To do so, copy the .env.sample file and rename it to .env. Then, fill in the values for the following variables:
AZURE_SEARCH_ENDPOINT[Required]: The Azure Cognitive Search EndpointAZURE_SEARCH_ADMIN_KEY[Required]: The Azure Cognitive Search Admin KeyINDEX_NAME[Required]: The name of the index in Azure Cognitive SearchOPENAI_API_TYPE[Required]: The OpenAI Type (either azure or openai)OPENAI_API_BASE[Optional]: The OpenAI base urlOPENAI_API_KEY[Required]: The OpenAI API KeyOPENAI_API_VERSION[Default=2023-05-15]: The version of OpenAI API
Connection are ways for promptflow to interact with services in a secure way. Since this sample interfaces with Azure Cognitive Search and OpenAI, we need to establish safe and secure ways to use the services.
To create the Azure Cognitive Search connection run the following:
pf connection create --file src/connections/cognitive_search.yaml --set api_key="<your-api-key>" --set api_base="<your-search-endpoint>"To create the Azure OpenAI connection run the following:
pf connection create --file src/connections/azure_openai.yaml --set api_key="<your-api-key>" --set api_base="<your-aoai-endpoint>"NOTE: The process to create a OpenAI connection is very similar, but you will need to create a openai connection and reference it in the flow.dag.yaml file.
To create the index and populate the data in cognitive search, run the script with the following command:
python -m src.scripts.chunk_and_uploadThis script will both create the index (based on the index file name in your .env file) and will upload the chunked data from the langchain introduction file.
To test the flow, run the following command:
pf flow test --flow src/flows/standard/promptflow-rag --inputs text="What is Langchain?"To run the flow, run the following command:
pf run create --flow --flow src/flows/standard/promptflow-rag --data src/flows/standard/promptflow-rag/data.jsonl