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
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="zh-TW">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Ollama 提示語推薦與查詢</title>
|
| 6 |
+
<style>
|
| 7 |
+
body { font-family: sans-serif; max-width: 600px; margin: 20px auto; }
|
| 8 |
+
.suggestion {
|
| 9 |
+
cursor: pointer;
|
| 10 |
+
padding: 8px;
|
| 11 |
+
border: 1px solid #ccc;
|
| 12 |
+
margin: 5px 0;
|
| 13 |
+
border-radius: 4px;
|
| 14 |
+
}
|
| 15 |
+
.suggestion:hover {
|
| 16 |
+
background-color: #eef;
|
| 17 |
+
}
|
| 18 |
+
textarea {
|
| 19 |
+
width: 100%;
|
| 20 |
+
height: 100px;
|
| 21 |
+
margin-top: 10px;
|
| 22 |
+
font-family: inherit;
|
| 23 |
+
padding: 8px;
|
| 24 |
+
}
|
| 25 |
+
button {
|
| 26 |
+
margin-top: 10px;
|
| 27 |
+
padding: 8px 16px;
|
| 28 |
+
}
|
| 29 |
+
pre {
|
| 30 |
+
background: #f9f9f9;
|
| 31 |
+
padding: 10px;
|
| 32 |
+
white-space: pre-wrap;
|
| 33 |
+
}
|
| 34 |
+
</style>
|
| 35 |
+
</head>
|
| 36 |
+
<body>
|
| 37 |
+
<h1>選擇模型並獲得建議提示</h1>
|
| 38 |
+
|
| 39 |
+
<label for="modelSelect">選擇模型:</label>
|
| 40 |
+
<select id="modelSelect">
|
| 41 |
+
<option value="">請選擇模型</option>
|
| 42 |
+
</select>
|
| 43 |
+
<button id="getSuggestions">取得建議提示</button>
|
| 44 |
+
|
| 45 |
+
<h3>建議提示:</h3>
|
| 46 |
+
<div id="suggestionList">(尚未載入)</div>
|
| 47 |
+
|
| 48 |
+
<h3>選擇的提示:</h3>
|
| 49 |
+
<textarea id="customPrompt" placeholder="請從上方建議中點選,或自行輸入 prompt..."></textarea>
|
| 50 |
+
|
| 51 |
+
<h3>選擇操作:</h3>
|
| 52 |
+
<select id="actionSelect">
|
| 53 |
+
<option value="create">創作</option>
|
| 54 |
+
<option value="explain">解釋</option>
|
| 55 |
+
</select>
|
| 56 |
+
|
| 57 |
+
<button id="generate">產生</button>
|
| 58 |
+
|
| 59 |
+
<h3>模型回應:</h3>
|
| 60 |
+
<pre id="responseOutput">(尚未查詢)</pre>
|
| 61 |
+
|
| 62 |
+
<script>
|
| 63 |
+
async function loadModels() {
|
| 64 |
+
try {
|
| 65 |
+
const res = await fetch('http://127.0.0.1:11434/api/tags');
|
| 66 |
+
const data = await res.json();
|
| 67 |
+
const select = document.getElementById('modelSelect');
|
| 68 |
+
data.models.forEach(model => {
|
| 69 |
+
const opt = document.createElement('option');
|
| 70 |
+
opt.value = model.name;
|
| 71 |
+
opt.textContent = model.name;
|
| 72 |
+
select.appendChild(opt);
|
| 73 |
+
});
|
| 74 |
+
} catch (err) {
|
| 75 |
+
console.error(err);
|
| 76 |
+
alert('無法載入模型,請確認 Ollama 是否已啟動');
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
async function getPromptSuggestions() {
|
| 81 |
+
const model = document.getElementById('modelSelect').value;
|
| 82 |
+
const container = document.getElementById('suggestionList');
|
| 83 |
+
if (!model) {
|
| 84 |
+
alert('請先選擇模型');
|
| 85 |
+
return;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
container.innerHTML = '載入中...';
|
| 89 |
+
|
| 90 |
+
const prompt = `你是 ${model} 模型,請列出 3~5 個你擅長的提示語,每個換行顯示,不需要額外說明。`;
|
| 91 |
+
|
| 92 |
+
try {
|
| 93 |
+
const res = await fetch('http://127.0.0.1:11434/api/generate', {
|
| 94 |
+
method: 'POST',
|
| 95 |
+
headers: { 'Content-Type': 'application/json' },
|
| 96 |
+
body: JSON.stringify({ model, prompt, stream: false })
|
| 97 |
+
});
|
| 98 |
+
const data = await res.json();
|
| 99 |
+
const lines = data.response.split('\n').filter(l => l.trim());
|
| 100 |
+
|
| 101 |
+
container.innerHTML = '';
|
| 102 |
+
lines.forEach(line => {
|
| 103 |
+
const div = document.createElement('div');
|
| 104 |
+
div.className = 'suggestion';
|
| 105 |
+
div.textContent = line;
|
| 106 |
+
div.addEventListener('click', () => {
|
| 107 |
+
document.getElementById('customPrompt').value = line;
|
| 108 |
+
});
|
| 109 |
+
container.appendChild(div);
|
| 110 |
+
});
|
| 111 |
+
} catch (err) {
|
| 112 |
+
console.error(err);
|
| 113 |
+
container.innerHTML = '取得建議失敗';
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
async function generateResponse() {
|
| 118 |
+
const model = document.getElementById('modelSelect').value;
|
| 119 |
+
const prompt = document.getElementById('customPrompt').value.trim();
|
| 120 |
+
const action = document.getElementById('actionSelect').value;
|
| 121 |
+
const output = document.getElementById('responseOutput');
|
| 122 |
+
|
| 123 |
+
if (!model || !prompt) {
|
| 124 |
+
alert('請選擇模型並輸入 prompt');
|
| 125 |
+
return;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
// 根據選擇的操作調整提示語
|
| 129 |
+
let finalPrompt = prompt;
|
| 130 |
+
if (action === 'create') {
|
| 131 |
+
finalPrompt = `您是該領域專家,請創作:${prompt}`; // 若選擇創作,前置"創作:"提示
|
| 132 |
+
} else if (action === 'explain') {
|
| 133 |
+
finalPrompt = `您是該領域專家,請解釋:${prompt}`; // 若選擇解釋,前置"解釋:"提示
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
output.textContent = '產生中...';
|
| 137 |
+
|
| 138 |
+
try {
|
| 139 |
+
const res = await fetch('http://127.0.0.1:11434/api/generate', {
|
| 140 |
+
method: 'POST',
|
| 141 |
+
headers: { 'Content-Type': 'application/json' },
|
| 142 |
+
body: JSON.stringify({ model, prompt: finalPrompt, stream: false })
|
| 143 |
+
});
|
| 144 |
+
const data = await res.json();
|
| 145 |
+
output.textContent = data.response || '未收到回應';
|
| 146 |
+
} catch (err) {
|
| 147 |
+
console.error(err);
|
| 148 |
+
output.textContent = '產生失敗';
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
document.getElementById('getSuggestions').addEventListener('click', getPromptSuggestions);
|
| 153 |
+
document.getElementById('generate').addEventListener('click', generateResponse);
|
| 154 |
+
window.onload = loadModels;
|
| 155 |
+
</script>
|
| 156 |
+
</body>
|
| 157 |
+
</html>
|