Skip to content

Commit 3f1d0b8

Browse files
committed
Add tongyi-langchain solution with PAI-EAS and Qwen model
1 parent f8b3dd5 commit 3f1d0b8

File tree

4 files changed

+260
-0
lines changed

4 files changed

+260
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Introduction
2+
3+
<!-- DOCS_DESCRIPTION_CN -->
4+
本示例用于实现解决方案[通义千问和 LangChain 搭建对话服务](https://www.aliyun.com/solution/tech-solution/tongyi-langchain), 涉及到PAI-EAS实例(PAI-EAS)、专有网络(VPC)、交换机(VSwitch)、文件存储(NAS)等资源的创建。
5+
<!-- DOCS_DESCRIPTION_CN -->
6+
7+
<!-- DOCS_DESCRIPTION_EN -->
8+
This example is used to implement solution [Building a conversation service with Qwen and LangChain](https://www.aliyun.com/solution/tech-solution/tongyi-langchain), which involves the creation and deployment of resources such as PAI-EAS,Virtual Private Cloud (VPC), VSwitch, File Storage NAS(NAS).
9+
<!-- DOCS_DESCRIPTION_EN -->
10+
## Providers
11+
12+
| Name | Version |
13+
|------|---------|
14+
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |
15+
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
16+
17+
## Modules
18+
19+
No modules.
20+
21+
## Resources
22+
23+
| Name | Type |
24+
|------|------|
25+
| [alicloud_nas_access_group.nas_access_group](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/nas_access_group) | resource |
26+
| [alicloud_nas_access_rule.nas_access_rule](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/nas_access_rule) | resource |
27+
| [alicloud_nas_file_system.nas_file_system](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/nas_file_system) | resource |
28+
| [alicloud_nas_mount_target.nas_mount_target](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/nas_mount_target) | resource |
29+
| [alicloud_pai_service.pai_eas](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/pai_service) | resource |
30+
| [alicloud_security_group.security_group](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group) | resource |
31+
| [alicloud_security_group_rule.allow_http](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group_rule) | resource |
32+
| [alicloud_security_group_rule.allow_https](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group_rule) | resource |
33+
| [alicloud_security_group_rule.allow_rdp](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group_rule) | resource |
34+
| [alicloud_vpc.vpc](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
35+
| [alicloud_vswitch.vswitch](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
36+
| [random_string.random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
37+
| [alicloud_regions.current](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/regions) | data source |
38+
39+
## Inputs
40+
41+
| Name | Description | Type | Default | Required |
42+
|------|-------------|------|---------|:--------:|
43+
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | PAI-EAS实例规格 | `string` | `"ml.gu7i.c8m30.1-gu30"` | no |
44+
| <a name="input_region"></a> [region](#input\_region) | 地域,例如:cn-hangzhou。所有地域及可用区请参见文档:https://help.aliyun.com/document_detail/40654.html#09f1dc16b0uke | `string` | `"cn-hangzhou"` | no |
45+
| <a name="input_zone_id"></a> [zone\_id](#input\_zone\_id) | 可用区ID | `string` | `"cn-hangzhou-f"` | no |
46+
<!-- END_TF_DOCS -->
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
provider "alicloud" {
2+
region = var.region
3+
}
4+
5+
# 生成随机字符串
6+
resource "random_string" "random_string" {
7+
length = 8
8+
special = false
9+
upper = false
10+
numeric = true
11+
lower = true
12+
}
13+
14+
# VPC
15+
resource "alicloud_vpc" "vpc" {
16+
cidr_block = "192.168.0.0/16"
17+
vpc_name = "vpc_qwen_demo"
18+
}
19+
20+
# VSwitch
21+
resource "alicloud_vswitch" "vswitch" {
22+
zone_id = var.zone_id
23+
vpc_id = alicloud_vpc.vpc.id
24+
cidr_block = "192.168.0.0/24"
25+
vswitch_name = "vswitch_qwen_demo"
26+
}
27+
28+
# 安全组
29+
resource "alicloud_security_group" "security_group" {
30+
vpc_id = alicloud_vpc.vpc.id
31+
security_group_name = "sg_qwen_demo"
32+
security_group_type = "normal"
33+
}
34+
35+
# 安全组入站规则 - 80端口
36+
resource "alicloud_security_group_rule" "allow_http" {
37+
type = "ingress"
38+
ip_protocol = "tcp"
39+
nic_type = "intranet"
40+
policy = "accept"
41+
port_range = "80/80"
42+
priority = 1
43+
security_group_id = alicloud_security_group.security_group.id
44+
cidr_ip = "0.0.0.0/0"
45+
}
46+
47+
# 安全组入站规则 - 443端口
48+
resource "alicloud_security_group_rule" "allow_https" {
49+
type = "ingress"
50+
ip_protocol = "tcp"
51+
nic_type = "intranet"
52+
policy = "accept"
53+
port_range = "443/443"
54+
priority = 1
55+
security_group_id = alicloud_security_group.security_group.id
56+
cidr_ip = "0.0.0.0/0"
57+
}
58+
59+
# 安全组入站规则 - 3389端口
60+
resource "alicloud_security_group_rule" "allow_rdp" {
61+
type = "ingress"
62+
ip_protocol = "tcp"
63+
nic_type = "intranet"
64+
policy = "accept"
65+
port_range = "3389/3389"
66+
priority = 1
67+
security_group_id = alicloud_security_group.security_group.id
68+
cidr_ip = "0.0.0.0/0"
69+
}
70+
71+
# NAS文件系统
72+
resource "alicloud_nas_file_system" "nas_file_system" {
73+
protocol_type = "NFS"
74+
file_system_type = "standard"
75+
storage_type = "Performance"
76+
zone_id = var.zone_id
77+
vpc_id = alicloud_vpc.vpc.id
78+
vswitch_id = alicloud_vswitch.vswitch.id
79+
description = "NAS文件系统用于Qwen和LangChain对话模型"
80+
}
81+
82+
# NAS访问组
83+
resource "alicloud_nas_access_group" "nas_access_group" {
84+
access_group_type = "Vpc"
85+
access_group_name = "nas-access-group-qwen-demo"
86+
}
87+
88+
# NAS挂载点
89+
resource "alicloud_nas_mount_target" "nas_mount_target" {
90+
vpc_id = alicloud_vpc.vpc.id
91+
vswitch_id = alicloud_vswitch.vswitch.id
92+
network_type = "Vpc"
93+
access_group_name = alicloud_nas_access_group.nas_access_group.access_group_name
94+
file_system_id = alicloud_nas_file_system.nas_file_system.id
95+
96+
depends_on = [alicloud_nas_access_rule.nas_access_rule]
97+
}
98+
99+
# NAS访问规则
100+
resource "alicloud_nas_access_rule" "nas_access_rule" {
101+
source_cidr_ip = "0.0.0.0/0"
102+
access_group_name = alicloud_nas_access_group.nas_access_group.access_group_name
103+
}
104+
105+
# PAI-EAS服务
106+
resource "alicloud_pai_service" "pai_eas" {
107+
service_config = jsonencode({
108+
metadata = {
109+
name = "qwen_demo_${random_string.random_string.result}"
110+
instance = 1
111+
enable_webservice = "true"
112+
}
113+
cloud = {
114+
computing = {
115+
instance_type = var.instance_type
116+
}
117+
}
118+
containers = [
119+
{
120+
image = "eas-registry-vpc.${data.alicloud_regions.current.regions.0.id}.cr.aliyuncs.com/pai-eas/chat-llm-webui:2.1"
121+
script = "python webui/webui_server.py --port=8000 --model-path=Qwen/Qwen-7B-Chat"
122+
port = 8000
123+
}
124+
]
125+
})
126+
127+
timeouts {
128+
create = "20m"
129+
}
130+
}
131+
132+
# 获取当前区域信息
133+
data "alicloud_regions" "current" {
134+
current = true
135+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
output "vpc_id" {
2+
description = "VPC ID"
3+
value = alicloud_vpc.vpc.id
4+
}
5+
6+
output "vswitch_id" {
7+
description = "VSwitch ID"
8+
value = alicloud_vswitch.vswitch.id
9+
}
10+
11+
output "security_group_id" {
12+
description = "安全组ID"
13+
value = alicloud_security_group.security_group.id
14+
}
15+
16+
output "nas_file_system_id" {
17+
description = "NAS文件系统ID"
18+
value = alicloud_nas_file_system.nas_file_system.id
19+
}
20+
21+
output "nas_mount_target_domain" {
22+
description = "NAS挂载点域名"
23+
value = alicloud_nas_mount_target.nas_mount_target.mount_target_domain
24+
}
25+
26+
output "pai_service_id" {
27+
description = "PAI-EAS服务ID"
28+
value = alicloud_pai_service.pai_eas.id
29+
}
30+
31+
output "service_name" {
32+
description = "PAI-EAS服务名称"
33+
value = "qwen_demo_${random_string.random_string.result}"
34+
}
35+
36+
output "service_status" {
37+
description = "PAI-EAS服务状态"
38+
value = alicloud_pai_service.pai_eas.status
39+
}
40+
41+
output "create_time" {
42+
description = "PAI-EAS服务创建时间"
43+
value = alicloud_pai_service.pai_eas.create_time
44+
}
45+
46+
output "region_id" {
47+
description = "部署区域ID"
48+
value = data.alicloud_regions.current.regions.0.id
49+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
variable "region" {
2+
type = string
3+
default = "cn-hangzhou"
4+
description = "地域,例如:cn-hangzhou。所有地域及可用区请参见文档:https://help.aliyun.com/document_detail/40654.html#09f1dc16b0uke"
5+
}
6+
7+
variable "zone_id" {
8+
type = string
9+
description = "可用区ID"
10+
default = "cn-hangzhou-f"
11+
}
12+
13+
variable "instance_type" {
14+
type = string
15+
description = "PAI-EAS实例规格"
16+
default = "ml.gu7i.c8m30.1-gu30"
17+
18+
validation {
19+
condition = contains([
20+
"ml.gu7i.c8m30.1-gu30",
21+
"ecs.gn6e-c12g1.3xlarge",
22+
"ecs.gn7i-c8g1.2xlarge",
23+
"ecs.gn6i-c16g1.4xlarge",
24+
"ecs.gn7i-c16g1.4xlarge",
25+
"ecs.gn6i-c8g1.2xlarge",
26+
"ecs.gn6i-c4g1.xlarge"
27+
], var.instance_type)
28+
error_message = "实例类型必须是以下之一:ml.gu7i.c8m30.1-gu30, ecs.gn6e-c12g1.3xlarge, ecs.gn7i-c8g1.2xlarge, ecs.gn6i-c16g1.4xlarge, ecs.gn6i-c8g1.2xlarge, ecs.gn6i-c4g1.xlarge"
29+
}
30+
}

0 commit comments

Comments
 (0)