Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
from volcengine.maas.v2 import MaasService
|
3 |
from volcengine.maas import MaasException, ChatRole
|
4 |
import json
|
5 |
-
|
6 |
|
7 |
def maas_chat(input):
|
8 |
query = input.split('\n')
|
@@ -10,9 +10,12 @@ def maas_chat(input):
|
|
10 |
query = json.dumps(query, ensure_ascii=False)
|
11 |
maas = MaasService('maas-api.ml-platform-cn-beijing.volces.com', 'cn-beijing')
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
|
17 |
# chat
|
18 |
req = {
|
@@ -35,7 +38,8 @@ def maas_chat(input):
|
|
35 |
]
|
36 |
}
|
37 |
|
38 |
-
|
|
|
39 |
resp = maas.chat(endpoint_id, req)
|
40 |
output = resp.choices[0].message['content']
|
41 |
#去除output'符号
|
|
|
2 |
from volcengine.maas.v2 import MaasService
|
3 |
from volcengine.maas import MaasException, ChatRole
|
4 |
import json
|
5 |
+
import os
|
6 |
|
7 |
def maas_chat(input):
|
8 |
query = input.split('\n')
|
|
|
10 |
query = json.dumps(query, ensure_ascii=False)
|
11 |
maas = MaasService('maas-api.ml-platform-cn-beijing.volces.com', 'cn-beijing')
|
12 |
|
13 |
+
|
14 |
+
# 使用 os 模块来访问变量和秘密值
|
15 |
+
ak = os.getenv('AK')
|
16 |
+
sk = os.getenv('SK')
|
17 |
+
maas.set_ak(ak)
|
18 |
+
maas.set_sk(sk)
|
19 |
|
20 |
# chat
|
21 |
req = {
|
|
|
38 |
]
|
39 |
}
|
40 |
|
41 |
+
ID = os.getenv('ID')
|
42 |
+
endpoint_id = ID
|
43 |
resp = maas.chat(endpoint_id, req)
|
44 |
output = resp.choices[0].message['content']
|
45 |
#去除output'符号
|