Update app.py
Browse files
app.py
CHANGED
@@ -35,6 +35,8 @@ DEFAULT_SYSTEM_PROMPT = "You are a helpful AI assistant built by MediaTek Resear
|
|
35 |
|
36 |
API_URL = os.environ.get("API_URL")
|
37 |
TOKEN = os.environ.get("TOKEN")
|
|
|
|
|
38 |
|
39 |
HEADERS = {
|
40 |
"Authorization": f"Bearer {TOKEN}",
|
@@ -42,34 +44,10 @@ HEADERS = {
|
|
42 |
"accept": "application/json"
|
43 |
}
|
44 |
|
45 |
-
|
46 |
MAX_SEC = 30
|
47 |
MAX_INPUT_LENGTH = 5000
|
48 |
|
49 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
50 |
-
|
51 |
-
def insert_to_db(prompt, response, temperature, top_p):
|
52 |
-
try:
|
53 |
-
#Establishing the connection
|
54 |
-
conn = psycopg2.connect(
|
55 |
-
database=os.environ.get("DB"), user=os.environ.get("USER"), password=os.environ.get("DB_PASS"), host=os.environ.get("DB_HOST"), port= '5432'
|
56 |
-
)
|
57 |
-
#Setting auto commit false
|
58 |
-
conn.autocommit = True
|
59 |
-
|
60 |
-
#Creating a cursor object using the cursor() method
|
61 |
-
cursor = conn.cursor()
|
62 |
-
|
63 |
-
# Preparing SQL queries to INSERT a record into the database.
|
64 |
-
cursor.execute(f"INSERT INTO breezedata(prompt, response, temperature, top_p) VALUES ('{prompt}', '{response}', {temperature}, {top_p})")
|
65 |
-
|
66 |
-
# Commit your changes in the database
|
67 |
-
conn.commit()
|
68 |
-
|
69 |
-
# Closing the connection
|
70 |
-
conn.close()
|
71 |
-
except:
|
72 |
-
pass
|
73 |
|
74 |
|
75 |
def refusal_condition(query):
|
@@ -145,9 +123,6 @@ with gr.Blocks() as demo:
|
|
145 |
|
146 |
saved_input = gr.State()
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
def user(user_message, history):
|
152 |
return "", history + [[user_message, None]]
|
153 |
|
@@ -207,7 +182,7 @@ with gr.Blocks() as demo:
|
|
207 |
yield history
|
208 |
else:
|
209 |
data = {
|
210 |
-
"model_type":
|
211 |
"prompt": str(message),
|
212 |
"parameters": {
|
213 |
"temperature": float(temperature),
|
@@ -232,7 +207,7 @@ with gr.Blocks() as demo:
|
|
232 |
response = history[-1][1]
|
233 |
|
234 |
if refusal_condition(history[-1][1]):
|
235 |
-
history[-1][1] = history[-1][1] + '\n\n**[免責聲明:
|
236 |
yield history
|
237 |
else:
|
238 |
del history[-1]
|
|
|
35 |
|
36 |
API_URL = os.environ.get("API_URL")
|
37 |
TOKEN = os.environ.get("TOKEN")
|
38 |
+
TOKENIZER_REPO = "MediaTek-Research/Breexe-8x7B-Instruct-v0_1"
|
39 |
+
API_MODEL_TYPE = "breexe-8x7b-instruct-v01"
|
40 |
|
41 |
HEADERS = {
|
42 |
"Authorization": f"Bearer {TOKEN}",
|
|
|
44 |
"accept": "application/json"
|
45 |
}
|
46 |
|
|
|
47 |
MAX_SEC = 30
|
48 |
MAX_INPUT_LENGTH = 5000
|
49 |
|
50 |
+
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_REPO, use_auth_token=os.environ.get("HF_TOKEN"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
|
53 |
def refusal_condition(query):
|
|
|
123 |
|
124 |
saved_input = gr.State()
|
125 |
|
|
|
|
|
|
|
126 |
def user(user_message, history):
|
127 |
return "", history + [[user_message, None]]
|
128 |
|
|
|
182 |
yield history
|
183 |
else:
|
184 |
data = {
|
185 |
+
"model_type": API_MODEL_TYPE,
|
186 |
"prompt": str(message),
|
187 |
"parameters": {
|
188 |
"temperature": float(temperature),
|
|
|
207 |
response = history[-1][1]
|
208 |
|
209 |
if refusal_condition(history[-1][1]):
|
210 |
+
history[-1][1] = history[-1][1] + '\n\n**[免責聲明: 此模型並未針對問答進行安全保護,因此語言模型的任何回應不代表 MediaTek Research 立場。]**'
|
211 |
yield history
|
212 |
else:
|
213 |
del history[-1]
|