主要功能更新: - 崗位描述保存功能:保存後資料寫入資料庫 - 崗位清單自動刷新:切換模組時自動載入最新資料 - 崗位清單檢視功能:點擊「檢視」按鈕載入對應描述 - 管理者頁面擴充:新增崗位資料管理與匯出功能 - CSV 批次匯入:支援崗位與職務資料批次匯入 後端 API 新增: - Position Description CRUD APIs - Position List Query & Export APIs - CSV Template Download & Import APIs 文件更新: - SDD.md 更新至版本 2.1 - README.md 更新功能說明與版本歷史 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
100 lines
3.0 KiB
Python
100 lines
3.0 KiB
Python
with open('index.html', 'r', encoding='utf-8') as f:
|
||
lines = f.readlines()
|
||
|
||
# 找到函數的起始行
|
||
start_line = None
|
||
for i, line in enumerate(lines):
|
||
if 'async function callClaudeAPI' in line:
|
||
start_line = i
|
||
break
|
||
|
||
if start_line is None:
|
||
print("ERROR: Could not find callClaudeAPI function")
|
||
exit(1)
|
||
|
||
# 找到函數的結束行
|
||
end_line = None
|
||
brace_count = 0
|
||
for i in range(start_line, len(lines)):
|
||
for char in lines[i]:
|
||
if char == '{':
|
||
brace_count += 1
|
||
elif char == '}':
|
||
brace_count -= 1
|
||
if brace_count == 0:
|
||
end_line = i
|
||
break
|
||
if end_line:
|
||
break
|
||
|
||
if end_line is None:
|
||
print("ERROR: Could not find end of function")
|
||
exit(1)
|
||
|
||
print(f"Found function from line {start_line+1} to {end_line+1}")
|
||
|
||
# 新函數
|
||
new_function = ''' async function callClaudeAPI(prompt, api = 'gemini') {
|
||
try {
|
||
// 調用後端 Flask API,避免 CORS 錯誤
|
||
const response = await fetch("/api/llm/generate", {
|
||
method: "POST",
|
||
headers: {
|
||
"Content-Type": "application/json",
|
||
},
|
||
body: JSON.stringify({
|
||
api: api,
|
||
prompt: prompt,
|
||
max_tokens: 2000
|
||
})
|
||
});
|
||
|
||
if (!response.ok) {
|
||
const errorData = await response.json();
|
||
throw new Error(errorData.error || `API 請求失敗: ${response.status}`);
|
||
}
|
||
|
||
const data = await response.json();
|
||
|
||
if (!data.success) {
|
||
throw new Error(data.error || 'API 調用失敗');
|
||
}
|
||
|
||
let responseText = data.text;
|
||
responseText = responseText.replace(/```json\\n?/g, "").replace(/```\\n?/g, "").trim();
|
||
return JSON.parse(responseText);
|
||
} catch (error) {
|
||
console.error("Error calling LLM API:", error);
|
||
alert(`AI 生成錯誤: ${error.message}\\n\\n請確保:\\n1. Flask 後端已啟動 (python app_updated.py)\\n2. 已在 .env 文件中配置 LLM API Key\\n3. 網路連線正常`);
|
||
throw error;
|
||
}
|
||
}
|
||
'''
|
||
|
||
# 替換
|
||
new_lines = lines[:start_line] + [new_function] + lines[end_line+1:]
|
||
|
||
# 寫回
|
||
with open('index.html', 'w', encoding='utf-8') as f:
|
||
f.writelines(new_lines)
|
||
|
||
print("SUCCESS: Function completely replaced")
|
||
print("\nVerifying...")
|
||
|
||
# 驗證
|
||
with open('index.html', 'r', encoding='utf-8') as f:
|
||
content = f.read()
|
||
|
||
if 'api.anthropic.com' in content:
|
||
print("WARNING: Still contains references to api.anthropic.com")
|
||
else:
|
||
print("VERIFIED: No more direct API calls")
|
||
|
||
if '/api/llm/generate' in content:
|
||
print("VERIFIED: Now using Flask backend")
|
||
|
||
print("\nDone! Please:")
|
||
print("1. Restart Flask: python app_updated.py")
|
||
print("2. Reload browser: Ctrl+F5")
|
||
print("3. Test AI generation")
|