page_type: sample languages:
This sample uses Azure's new Prompty tool, Langchain, and Pinecone to build a large language model (LLM) search agent capable of answering user questions based on the provided data. It leverages Retrieval-Augmented Generation (RAG) to enhance the agent's response capabilities.
By the end of deploying this template, you should be able to:
This project framework provides the following features:
agent.py
file that serves as a chat agent. This agent is designed to receive users' questions, generate queries, perform searches within the data index using Elasticsearch, and refine the search outputs for user presentation.data
folder that stores local data. A new index is created during initialization, enabling efficient search capabilities.IMPORTANT: In order to deploy and run this example, you'll need:
Microsoft.Authorization/roleAssignments/write
permissions, such as Role Based Access Control Administrator, User Access Administrator, or Owner. If you don't have subscription-level permissions, you must be granted RBAC for an existing resource group and deploy to that existing group.Microsoft.Resources/deployments/write
permissions on the subscription level.Once you have an Azure account you have two options for setting up this project. The easiest way to get started is GitHub Codespaces, since it will setup all the tools for you, but you can also set it up [locally]() if desired.
Go to Pinecone and create your account if you don't have one. For this quickstart template, please create a index in your Pinecone account named langchain-test-index
. Keep your Pinecone API key in a safe place and you will need to pass it for this template.
The Elastic Search tool does not support Microsoft Managed Identity now. It is recommended to use Azure Key Vault to secure your API keys.
You have a few options for setting up this project. The easiest way to get started is GitHub Codespaces, since it will setup all the tools for you, but you can also set it up locally if desired.
You can run this repo virtually by using GitHub Codespaces, which will open a web-based VS Code in your browser:
Once the codespace opens (this may take several minutes), open a terminal window.
A related option is VS Code Dev Containers, which will open the project in your local VS Code using the Dev Containers extension:
winget install microsoft.azd
curl -fsSL https://aka.ms/install-azd.sh | bash
brew tap azure/azd && brew install azd
gpt-3.5-turbo
and OpenAI text to speech models which may not be available in all Azure regions. Check for up-to-date region availability and select a region during deployment accordinglyswedencentral
for Azure OpenAI and eastus
for the speech to text services azd init -t agent-openai-python-prompty-langchain-pinecone
Enter a name to create a new environment. The name is also used for the resource group. This will create a new folder in the .azure folder, and set it as the active environment for any calls to azd going forward.
Note that this command will initialize a git repository, so you do not need to clone this repository.
azd auth login
azd env set PINECONE_API_KEY <key>
azd up
azd pipeline config
validate_deployment.ipynb
notebook.Cognitive Services User
role to the corresponding Azure AI services.src\prompty-langchain-agent\packages\openai-functions-agent\openai_functions_agent\agent.py
. By default it is called langchain-test-index
src\prompty-langchain-agent\packages\openai-functions-agent\openai_functions_agent\data
folder and change the data file name in agent.py
(change the local_load
settings as well)src\prompty-langchain-agent
folder and do followings:poetry install --no-interaction --no-ansi
Go to packages\openai-functions-agent
and run:
poetry install --no-interaction --no-ansi
AZURE_OPENAI_ENDPOINT= <your aoai endpoint>
OPENAI_API_VERSION= <your aoai api version>
AZURE_OPENAI_DEPLOYMENT= <your aoai deployment name for chat>
AZURE_OPENAI_EMBEDDING_DEPLOYMENT= <your aoai deployment name for embedding>
PINECONE_API_KEY= <Your PINECONE API>
Now try to run it on your local
langchian serve
you can go to http://localhost:8000/openai-functions-agent/playground/ to test.
you can mention your index in input
to tell agent to use search tool.
To clean up all the resources created by this sample:
azd down
y
y
The resource group and all the resources will be deleted.
You can estimate the cost of this project's architecture with Azure's pricing calculator
We recommend using keyless authentication for this project. Read more about why you should use managed identities on our blog.
We do support Langsmith and you can follow their doc make it work.