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