In this sample, we utilize the new Prompty tool, Langchain, and Elasticsearch to build a large language model (LLM) search agent. This agent with Retrieval-Augmented Generation (RAG) technology is capable of answering user questions based on the provided data by integrating real-time information retrieval with generative responses.
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 Elasticsearch and create your account if you don't have one. For this quickstart template, please create a index in your Elasticsearch account named langchain-test-index
. Keep your Elasticsearch encoded 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 Clone the repository and intialize the project:
azd init agent-python-openai-prompty-langchain
Note that this command will initialize a git repository, so you do not need to clone this repository.
Login to your Azure account:
azd auth login
Set following environment variables:
ELASTICSEARCH_ENDPOINT
and ELASTICSEARCH_API_KEY
Create a new azd environment:
azd env new
Enter a name that will be 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.
Provision and deploy the project to Azure: azd up
Set up CI/CD with azd pipeline config
Talk to your agent:
please take the validate_deployment.ipynb
as reference.
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>
ELASTICSEARCH_ENDPOINT = <your ELASTICSEARCH ENDPOINT>
ELASTICSEARCH_API_KEY= <Your encoded ELASTICSEARCH API key>
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.