Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -8,8 +8,9 @@ DEFAULT_MODEL = os.getenv("LLM_MODEL", "Qwen/Qwen2.5-Coder-7B-Instruct-AWQ")
|
|
| 8 |
|
| 9 |
client = OpenAI(base_url=BASE_URL, api_key=API_KEY or "missing-key", timeout=120)
|
| 10 |
|
| 11 |
-
def predict(message, history
|
| 12 |
-
|
|
|
|
| 13 |
for human, assistant in history:
|
| 14 |
messages.append({"role": "user", "content": human})
|
| 15 |
messages.append({"role": "assistant", "content": assistant})
|
|
@@ -17,10 +18,10 @@ def predict(message, history, model, system_prompt, max_tokens, temperature):
|
|
| 17 |
|
| 18 |
try:
|
| 19 |
response = client.chat.completions.create(
|
| 20 |
-
model=
|
| 21 |
messages=messages,
|
| 22 |
-
max_tokens=
|
| 23 |
-
temperature=
|
| 24 |
stream=True
|
| 25 |
)
|
| 26 |
partial_message = ""
|
|
@@ -33,20 +34,6 @@ def predict(message, history, model, system_prompt, max_tokens, temperature):
|
|
| 33 |
|
| 34 |
demo = gr.ChatInterface(
|
| 35 |
fn=predict,
|
| 36 |
-
additional_inputs=[
|
| 37 |
-
gr.Dropdown(
|
| 38 |
-
choices=["Qwen/Qwen2.5-Coder-7B-Instruct-AWQ", "gemma-3-taide-12b-chat", "gemma-3-4b-it"],
|
| 39 |
-
value=DEFAULT_MODEL,
|
| 40 |
-
label="模型"
|
| 41 |
-
),
|
| 42 |
-
gr.Textbox(
|
| 43 |
-
label="系統提示詞",
|
| 44 |
-
value="你是一位樂於助人的程式設計助理。請一律使用繁體中文回答。",
|
| 45 |
-
lines=2
|
| 46 |
-
),
|
| 47 |
-
gr.Slider(minimum=32, maximum=2048, value=512, step=1, label="最大輸出 token 數"),
|
| 48 |
-
gr.Slider(minimum=0.0, maximum=1.5, value=0.2, step=0.05, label="溫度")
|
| 49 |
-
],
|
| 50 |
title="程式設計小幫手"
|
| 51 |
)
|
| 52 |
|
|
|
|
| 8 |
|
| 9 |
client = OpenAI(base_url=BASE_URL, api_key=API_KEY or "missing-key", timeout=120)
|
| 10 |
|
| 11 |
+
def predict(message, history):
|
| 12 |
+
# 將歷史訊息轉換為 OpenAI API 格式
|
| 13 |
+
messages = [{"role": "system", "content": "你是一位樂於助人的程式設計助理。請一律使用繁體中文回答。"}]
|
| 14 |
for human, assistant in history:
|
| 15 |
messages.append({"role": "user", "content": human})
|
| 16 |
messages.append({"role": "assistant", "content": assistant})
|
|
|
|
| 18 |
|
| 19 |
try:
|
| 20 |
response = client.chat.completions.create(
|
| 21 |
+
model=DEFAULT_MODEL,
|
| 22 |
messages=messages,
|
| 23 |
+
max_tokens=512,
|
| 24 |
+
temperature=0.2,
|
| 25 |
stream=True
|
| 26 |
)
|
| 27 |
partial_message = ""
|
|
|
|
| 34 |
|
| 35 |
demo = gr.ChatInterface(
|
| 36 |
fn=predict,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
title="程式設計小幫手"
|
| 38 |
)
|
| 39 |
|