移除不存在的備用端點

變更內容:
- 從 llama_chat.py 移除備用端點配置
- 從 llama_full_api.py 移除備用端點配置
- 簡化端點測試邏輯
- 更新所有文檔移除備用端點說明
- 專注於實際存在的三個端點:
  * https://llama.theaken.com/v1
  * https://llama.theaken.com/v1/gpt-oss-120b
  * https://llama.theaken.com/v1/deepseek-r1-671b

程式結構更清晰,移除虛假的備用選項。
This commit is contained in:
2025-09-19 22:09:15 +08:00
parent 3c0fba5fc8
commit 390a8cc7f7
4 changed files with 25 additions and 80 deletions

View File

@@ -4,10 +4,10 @@
## 🌟 主要功能 ## 🌟 主要功能
-**支援內網和外網連接** - 自動偵測可用的 API 端點 -**支援多端點連接** - 自動偵測可用的 API 端點
- 💬 **互動式對話介面** - 像聊天一樣與 AI 對話 - 💬 **互動式對話介面** - 像聊天一樣與 AI 對話
- 🤖 **多模型支援** - GPT-OSS、DeepSeek、Qwen 等多種模型 - 🤖 **多模型支援** - GPT-OSS、DeepSeek、Qwen 等多種模型
- 🔄 **自動重試機制** - 連接失敗時自動切換端點 - 🔄 **自動端點選擇** - 自動測試並選擇可用端點
- 🧹 **智慧清理回應** - 自動移除 AI 思考過程的標記 - 🧹 **智慧清理回應** - 自動移除 AI 思考過程的標記
- 📝 **對話歷史管理** - 保持上下文連貫的對話 - 📝 **對話歷史管理** - 保持上下文連貫的對話
@@ -93,7 +93,7 @@ AI: 1+1等於2。
## 🌐 可用的 API 端點 ## 🌐 可用的 API 端點
### 主要端點 ### 可用端點
| 端點 | 地址 | 支援模型 | | 端點 | 地址 | 支援模型 |
|-----|------|---------| |-----|------|---------|
@@ -101,13 +101,6 @@ AI: 1+1等於2。
| GPT-OSS 專用 | `https://llama.theaken.com/v1/gpt-oss-120b` | GPT-OSS-120B | | 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 | | 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 模型 ## 🤖 支援的 AI 模型
1. **GPT-OSS-120B** - 開源 GPT 模型1200 億參數 1. **GPT-OSS-120B** - 開源 GPT 模型1200 億參數
@@ -122,7 +115,7 @@ AI: 1+1等於2。
1. 檢查網路連接是否正常 1. 檢查網路連接是否正常
2. 確認可以訪問外部網站 (https://llama.theaken.com) 2. 確認可以訪問外部網站 (https://llama.theaken.com)
3. 嘗試執行 `python quick_test.py` 測試連接 3. 嘗試執行 `python quick_test.py` 測試連接
4. 如果主要端點無法使用,程式會自動嘗試備用端點 4. 程式會自動測試所有端點並選擇可用的
### 問題AI 回應包含奇怪的標記 ### 問題AI 回應包含奇怪的標記
@@ -174,7 +167,7 @@ API_KEY = "你的新金鑰"
`llama_full_api.py` 中的 `ENDPOINTS` 加入新端點: `llama_full_api.py` 中的 `ENDPOINTS` 加入新端點:
```python ```python
"主要": [ ENDPOINTS = [
{ {
"name": "新端點", "name": "新端點",
"url": "https://新的地址/v1", "url": "https://新的地址/v1",
@@ -195,8 +188,8 @@ https://gitea.theaken.com/aken1023/pj_llama/issues
## 📊 測試狀態 ## 📊 測試狀態
最後測試時間2025-09-19 最後測試時間2025-09-19
- 📡 主要端點:正在測試中 - 📡 API 端點:正在測試中
- 🔄 備用端點:當主要端點無法使用時自動切換 - 🔄 自動選擇:程式會自動選擇可用的端點
--- ---

View File

@@ -33,19 +33,7 @@ ENDPOINTS = [
} }
] ]
# 備用外網端點(如果主要端點無法使用 # 外網 API 端點配置(僅包含實際存在的端點
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"]
}
]
def clean_response(text): def clean_response(text):
"""清理 AI 回應中的特殊標記""" """清理 AI 回應中的特殊標記"""
@@ -112,21 +100,13 @@ def test_endpoint(endpoint_info, timeout=10):
def find_working_endpoint(): def find_working_endpoint():
"""尋找可用的端點""" """尋找可用的端點"""
print("\n正在測試外網端點...") print("\n正在測試可用端點...")
print("-" * 50) print("-" * 50)
# 先測試主要端點
print("主要端點:")
for endpoint in ENDPOINTS: for endpoint in ENDPOINTS:
if test_endpoint(endpoint): if test_endpoint(endpoint):
return endpoint return endpoint
# 如果主要端點都不可用,測試備用端點
print("\n備用端點:")
for endpoint in BACKUP_ENDPOINTS:
if test_endpoint(endpoint):
return endpoint
return None return None
def chat_session(endpoint_info): def chat_session(endpoint_info):
@@ -239,16 +219,16 @@ def main():
if not working_endpoint: if not working_endpoint:
print("\n" + "="*60) print("\n" + "="*60)
print("錯誤:無法連接到任何外網端點") print("錯誤:無法連接到任何 API 端點")
print("="*60) print("="*60)
print("\n可能的原因:") print("\n可能的原因:")
print("1. 外網 API 伺服器暫時離線") print("1. API 伺服器暫時離線")
print("2. 網路連接問題") print("2. 網路連接問題")
print("3. 防火牆或代理設定") print("3. 防火牆或代理設定")
print("\n建議:") print("\n建議:")
print("1. 稍後再試10-30分鐘後") print("1. 稍後再試10-30分鐘後")
print("2. 檢查網路連接") print("2. 檢查網路連接")
print("3. 聯繫 API 管理員") print("3. 確認可以訪問 https://llama.theaken.com")
sys.exit(1) sys.exit(1)
print("\n" + "="*60) print("\n" + "="*60)

View File

@@ -33,18 +33,6 @@ ENDPOINTS = {
"models": ["deepseek-r1-671b"] "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): def clean_response(text):
@@ -116,8 +104,8 @@ def test_all_endpoints():
available_endpoints = [] available_endpoints = []
# 測試主要端點 # 測試所有端點
print("\n[主要端點測試]") print("\n[端點測試]")
for endpoint in ENDPOINTS["主要"]: for endpoint in ENDPOINTS["主要"]:
print(f" 測試 {endpoint['name']}...", end="", flush=True) print(f" 測試 {endpoint['name']}...", end="", flush=True)
if test_endpoint(endpoint): if test_endpoint(endpoint):
@@ -126,16 +114,6 @@ def test_all_endpoints():
else: else:
print(" [FAIL]") 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 return available_endpoints
def chat_session(endpoint_info): def chat_session(endpoint_info):

View File

@@ -9,18 +9,12 @@ paVrIT+XU1NhwCAOb0X4aYi75QKogK5YNMGvQF1dCyo=
### 可用端點 ### 可用端點
#### 主要外網端點 #### 可用的外網端點
| 端點名稱 | URL | 狀態 | 支援模型 | | 端點名稱 | URL | 支援模型 |
|---------|-----|------|---------| |---------|-----|---------|
| 通用端點 | https://llama.theaken.com/v1 | 🌐 主要 | gpt-oss-120b, deepseek-r1-671b, qwen3-embedding-8b | | 通用端點 | 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 | | 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 | | 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 | 🔄 備用 | 所有模型 |
## 二、快速開始 ## 二、快速開始
@@ -96,7 +90,7 @@ python quick_test.py
### 問題 1502 Bad Gateway ### 問題 1502 Bad Gateway
**原因**API 伺服器暫時離線 **原因**API 伺服器暫時離線
**解決**:稍後再試或使用備用端點 **解決**:稍後再試,程式會自動測試所有端點
### 問題 2Connection Error ### 問題 2Connection Error
**原因**:網路連接問題 **原因**:網路連接問題
@@ -123,15 +117,15 @@ python quick_test.py
## 七、測試結果摘要 ## 七、測試結果摘要
### 測試狀態 ### 測試狀態
📡 外網端點連接測試中 📡 API 端點連接測試中
✅ 支援 OpenAI SDK 標準格式 ✅ 支援 OpenAI SDK 標準格式
✅ 自動端點切換機制 ✅ 自動端點選擇機制
### 支援功能 ### 支援功能
- 多端點自動切換 - 自動端點選擇
- 智慧超時控制 - 智慧超時控制
- 完整錯誤處理 - 完整錯誤處理
- DeepSeekQwen 模型支援 - 多模型支援GPT-OSS、DeepSeekQwen
## 八、技術細節 ## 八、技術細節