Terraform模板使用Redis Enterprise作為矢量數據庫自動化Azure OpenAI應用程序的端到端部署。

在一個部署的單個Terraform腳本中:
text-davinci-003和text-embedding-ada-002型號./docs文件夾此存儲庫中使用的示例應用程序使您可以使用ChatGpt分析組織以前未知的文檔和/或您組織內部的文檔。
應用程序中有兩個數據流。首先 - 從文檔上下文中生成嵌入的批處理。這些嵌入存儲在Azure Redis Enterprise中。其次 - 使用這些嵌入來生成上下文感知的提示,以便基於內部文檔的上下文回答問題。
您可以嘗試的問題:
雪佛蘭科羅拉多州可用的三種發動機類型之間的主要區別是什麼?將響應格式化為具有模型作為第一列的表格
有哪些顏色選項可用?格式為列表
應用信用-https://github.com/redisventures/llm-document-chat
將Azure CLI身份驗證到您的Azure帳戶:
az login
部署Terraform配置:
terraform init
terraform apply
您可以將自己的文檔添加到./docs文件夾(PDF或純文本)中,因此可以在部署期間將其上傳到存儲桶。
提供所有必需的基礎設施可能需要20分鐘。
最後,Terraform腳本將輸出一堆變量。
app-url = "redis-openai-83903-webapp.azurewebsites.net"
openai-endpoint = "https://redis-openai-83903.openai.azure.com/"
openai-key = <sensitive>
redis-endpoint = "redis-openai-83903-redisenterprise.southcentralus.redisenterprise.cache.azure.net"
redis-password = <sensitive>
redis-port = 10000
storage-account = "redisopenai83903bucket"
storage-account-connection-string = <sensitive>
storage-container = "data"
App-url可用於立即訪問該應用程序。
使用terraform.tfvars或terraform apply -var="name_prefix=my-deployment"來覆蓋默認資源名稱前綴和容器映像以與WebApp部署。
要更改應用程序,請在terraform.tfvars中部署為Azure Web應用程序 - 更改app_docker_image和app_docker_tag值。默認應用程序的源代碼在./app文件夾下的此存儲庫中包含。
Azure帳戶,Azure CLI,Terraform CLI本地安裝。
Azure Open AI當前(2023年5月)在私人預覽中。您需要向Microsoft提交請求,以啟用您的帳戶。
Azure OpenAI嵌入API當前對請求頻率有嚴格的限制,這可能使其對於散裝嵌入生成不可行。考慮使用局部嵌入,例如:
from langchain.embeddings import HuggingFaceEmbeddings
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
儘管無法在本地部署Azure OpenAI和Azure Redis Enterprise,但您可以使用本地計算機來測試應用程序本身。
運行terraform apply後,您可以使用生成的Azure服務在本地測試您的應用程序代碼。使用.env.template作為示例,並用實際的鍵和URL填充它。
docker build -t llm-chat .
docker run -it -p 80:80 --env-file=.env llm-chat
構建/推動乘數圖像(可用於MAC/ARM上的本地開發):
docker buildx build --platform linux/amd64,linux/arm64 -t antonum/llmchat:latest --push .
azurerm_cognitive_account.openai陷入了creating階段。在撰寫本文時(2023年5月)Azure偶爾會遇到部署OpenAI服務的問題。嘗試將堆棧部署在另一個區域。例如,設置azure_region = "southcentralus"而不是eastus 。
SpecialFeatureOrQuotaIdRequired: The subscription does not have QuotaId/Feature required by SKU 'S0' from kind 'OpenAI'您的Azure帳戶不啟用Azure OpenAI。在撰寫本文時(2023年5月)Azure Openai是私人預覽。您需要向Microsoft提交請求,以啟用其訂閱。
破壞所有部署的資源運行:
terraform destroy