Spaces:
Running on Zero
Running on Zero
Update model.py
Browse files
model.py
CHANGED
|
@@ -38,18 +38,19 @@ def load_model():
|
|
| 38 |
def run_inference(user_input, system_instruction, history):
|
| 39 |
global model, tokenizer
|
| 40 |
|
|
|
|
| 41 |
if history is None:
|
| 42 |
history = []
|
| 43 |
|
| 44 |
if model is None:
|
| 45 |
load_model()
|
| 46 |
if model is None:
|
| 47 |
-
# エラー時も辞書形式で
|
| 48 |
history.append({"role": "user", "content": user_input})
|
| 49 |
history.append({"role": "assistant", "content": "Error: Model failed to load."})
|
| 50 |
return history
|
| 51 |
|
| 52 |
-
# プロンプト
|
| 53 |
prompt = f"""### Instruction:
|
| 54 |
{system_instruction}
|
| 55 |
|
|
@@ -82,7 +83,7 @@ def run_inference(user_input, system_instruction, history):
|
|
| 82 |
else:
|
| 83 |
generated_response = full_output.replace(prompt, "").strip()
|
| 84 |
|
| 85 |
-
# 【重要】
|
| 86 |
history.append({"role": "user", "content": user_input})
|
| 87 |
history.append({"role": "assistant", "content": generated_response})
|
| 88 |
|
|
|
|
| 38 |
def run_inference(user_input, system_instruction, history):
|
| 39 |
global model, tokenizer
|
| 40 |
|
| 41 |
+
# historyがNoneなら空リストにする
|
| 42 |
if history is None:
|
| 43 |
history = []
|
| 44 |
|
| 45 |
if model is None:
|
| 46 |
load_model()
|
| 47 |
if model is None:
|
| 48 |
+
# エラー時も辞書形式で追加
|
| 49 |
history.append({"role": "user", "content": user_input})
|
| 50 |
history.append({"role": "assistant", "content": "Error: Model failed to load."})
|
| 51 |
return history
|
| 52 |
|
| 53 |
+
# Alpaca形式プロンプト
|
| 54 |
prompt = f"""### Instruction:
|
| 55 |
{system_instruction}
|
| 56 |
|
|
|
|
| 83 |
else:
|
| 84 |
generated_response = full_output.replace(prompt, "").strip()
|
| 85 |
|
| 86 |
+
# 【重要】エラーメッセージに従い、辞書形式 (Messages format) で返す
|
| 87 |
history.append({"role": "user", "content": user_input})
|
| 88 |
history.append({"role": "assistant", "content": generated_response})
|
| 89 |
|