diff --git a/README.md b/README.md index 5e6482c..fb3d39a 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ ## 🌟 主要功能 -- ✅ **支援內網和外網連接** - 自動偵測可用的 API 端點 +- ✅ **支援多端點連接** - 自動偵測可用的 API 端點 - 💬 **互動式對話介面** - 像聊天一樣與 AI 對話 - 🤖 **多模型支援** - GPT-OSS、DeepSeek、Qwen 等多種模型 -- 🔄 **自動重試機制** - 連接失敗時自動切換端點 +- 🔄 **自動端點選擇** - 自動測試並選擇可用端點 - 🧹 **智慧清理回應** - 自動移除 AI 思考過程的標記 - 📝 **對話歷史管理** - 保持上下文連貫的對話 @@ -93,7 +93,7 @@ AI: 1+1等於2。 ## 🌐 可用的 API 端點 -### 主要端點 +### 可用端點 | 端點 | 地址 | 支援模型 | |-----|------|---------| @@ -101,13 +101,6 @@ AI: 1+1等於2。 | GPT-OSS 專用 | `https://llama.theaken.com/v1/gpt-oss-120b` | GPT-OSS-120B | | DeepSeek 專用 | `https://llama.theaken.com/v1/deepseek-r1-671b` | DeepSeek-R1-671B | -### 備用端點 - -| 端點 | 地址 | 支援模型 | -|-----|------|---------| -| 備用 API 1 | `https://api.llama.theaken.com/v1` | 所有模型 | -| 備用 API 2 | `https://llama-api.theaken.com/v1` | 所有模型 | - ## 🤖 支援的 AI 模型 1. **GPT-OSS-120B** - 開源 GPT 模型,1200 億參數 @@ -122,7 +115,7 @@ AI: 1+1等於2。 1. 檢查網路連接是否正常 2. 確認可以訪問外部網站 (https://llama.theaken.com) 3. 嘗試執行 `python quick_test.py` 測試連接 -4. 如果主要端點無法使用,程式會自動嘗試備用端點 +4. 程式會自動測試所有端點並選擇可用的 ### 問題:AI 回應包含奇怪的標記 @@ -174,7 +167,7 @@ API_KEY = "你的新金鑰" 在 `llama_full_api.py` 中的 `ENDPOINTS` 加入新端點: ```python -"主要": [ +ENDPOINTS = [ { "name": "新端點", "url": "https://新的地址/v1", @@ -195,8 +188,8 @@ https://gitea.theaken.com/aken1023/pj_llama/issues ## 📊 測試狀態 最後測試時間:2025-09-19 -- 📡 主要端點:正在測試中 -- 🔄 備用端點:當主要端點無法使用時自動切換 +- 📡 API 端點:正在測試中 +- 🔄 自動選擇:程式會自動選擇可用的端點 --- diff --git a/llama_chat.py b/llama_chat.py index e3f34b2..ac93cc0 100644 --- a/llama_chat.py +++ b/llama_chat.py @@ -33,19 +33,7 @@ ENDPOINTS = [ } ] -# 備用外網端點(如果主要端點無法使用) -BACKUP_ENDPOINTS = [ - { - "name": "備用端點 1", - "url": "https://api.llama.theaken.com/v1", - "models": ["gpt-oss-120b", "deepseek-r1-671b", "qwen3-embedding-8b"] - }, - { - "name": "備用端點 2", - "url": "https://llama-api.theaken.com/v1", - "models": ["gpt-oss-120b", "deepseek-r1-671b", "qwen3-embedding-8b"] - } -] +# 外網 API 端點配置(僅包含實際存在的端點) def clean_response(text): """清理 AI 回應中的特殊標記""" @@ -112,21 +100,13 @@ def test_endpoint(endpoint_info, timeout=10): def find_working_endpoint(): """尋找可用的端點""" - print("\n正在測試外網端點...") + print("\n正在測試可用端點...") print("-" * 50) - # 先測試主要端點 - print("主要端點:") for endpoint in ENDPOINTS: if test_endpoint(endpoint): return endpoint - # 如果主要端點都不可用,測試備用端點 - print("\n備用端點:") - for endpoint in BACKUP_ENDPOINTS: - if test_endpoint(endpoint): - return endpoint - return None def chat_session(endpoint_info): @@ -239,16 +219,16 @@ def main(): if not working_endpoint: print("\n" + "="*60) - print("錯誤:無法連接到任何外網端點") + print("錯誤:無法連接到任何 API 端點") print("="*60) print("\n可能的原因:") - print("1. 外網 API 伺服器暫時離線") + print("1. API 伺服器暫時離線") print("2. 網路連接問題") print("3. 防火牆或代理設定") print("\n建議:") print("1. 稍後再試(10-30分鐘後)") print("2. 檢查網路連接") - print("3. 聯繫 API 管理員") + print("3. 確認可以訪問 https://llama.theaken.com") sys.exit(1) print("\n" + "="*60) diff --git a/llama_full_api.py b/llama_full_api.py index 962bf3f..dc7a169 100644 --- a/llama_full_api.py +++ b/llama_full_api.py @@ -33,18 +33,6 @@ ENDPOINTS = { "models": ["deepseek-r1-671b"] } ], - "備用": [ - { - "name": "備用 API 端點 1", - "url": "https://api.llama.theaken.com/v1", - "models": ["gpt-oss-120b", "deepseek-r1-671b", "qwen3-embedding-8b"] - }, - { - "name": "備用 API 端點 2", - "url": "https://llama-api.theaken.com/v1", - "models": ["gpt-oss-120b", "deepseek-r1-671b", "qwen3-embedding-8b"] - } - ] } def clean_response(text): @@ -116,8 +104,8 @@ def test_all_endpoints(): available_endpoints = [] - # 測試主要端點 - print("\n[主要端點測試]") + # 測試所有端點 + print("\n[端點測試]") for endpoint in ENDPOINTS["主要"]: print(f" 測試 {endpoint['name']}...", end="", flush=True) if test_endpoint(endpoint): @@ -126,16 +114,6 @@ def test_all_endpoints(): else: print(" [FAIL]") - # 測試備用端點 - print("\n[備用端點測試]") - for endpoint in ENDPOINTS["備用"]: - print(f" 測試 {endpoint['name']}...", end="", flush=True) - if test_endpoint(endpoint): - print(" [OK]") - available_endpoints.append(("備用", endpoint)) - else: - print(" [FAIL]") - return available_endpoints def chat_session(endpoint_info): diff --git a/操作指南.md b/操作指南.md index 5740008..530969f 100644 --- a/操作指南.md +++ b/操作指南.md @@ -9,18 +9,12 @@ paVrIT+XU1NhwCAOb0X4aYi75QKogK5YNMGvQF1dCyo= ### 可用端點 -#### 主要外網端點 -| 端點名稱 | URL | 狀態 | 支援模型 | -|---------|-----|------|---------| -| 通用端點 | https://llama.theaken.com/v1 | 🌐 主要 | gpt-oss-120b, deepseek-r1-671b, qwen3-embedding-8b | -| GPT-OSS 專用 | https://llama.theaken.com/v1/gpt-oss-120b | 🌐 主要 | gpt-oss-120b | -| DeepSeek 專用 | https://llama.theaken.com/v1/deepseek-r1-671b | 🌐 主要 | deepseek-r1-671b | - -#### 備用外網端點 -| 端點名稱 | URL | 狀態 | 支援模型 | -|---------|-----|------|---------| -| 備用 API 1 | https://api.llama.theaken.com/v1 | 🔄 備用 | 所有模型 | -| 備用 API 2 | https://llama-api.theaken.com/v1 | 🔄 備用 | 所有模型 | +#### 可用的外網端點 +| 端點名稱 | URL | 支援模型 | +|---------|-----|---------| +| 通用端點 | https://llama.theaken.com/v1 | gpt-oss-120b, deepseek-r1-671b, qwen3-embedding-8b | +| GPT-OSS 專用 | https://llama.theaken.com/v1/gpt-oss-120b | gpt-oss-120b | +| DeepSeek 專用 | https://llama.theaken.com/v1/deepseek-r1-671b | deepseek-r1-671b | ## 二、快速開始 @@ -96,7 +90,7 @@ python quick_test.py ### 問題 1:502 Bad Gateway **原因**:API 伺服器暫時離線 -**解決**:稍後再試或使用備用端點 +**解決**:稍後再試,程式會自動測試所有端點 ### 問題 2:Connection Error **原因**:網路連接問題 @@ -123,15 +117,15 @@ python quick_test.py ## 七、測試結果摘要 ### 測試狀態 -📡 外網端點連接測試中 +📡 API 端點連接測試中 ✅ 支援 OpenAI SDK 標準格式 -✅ 自動端點切換機制 +✅ 自動端點選擇機制 ### 支援功能 -- 多端點自動切換 +- 自動端點選擇 - 智慧超時控制 - 完整錯誤處理 -- DeepSeek 和 Qwen 模型支援 +- 多模型支援(GPT-OSS、DeepSeek、Qwen) ## 八、技術細節