mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-27 15:44:12 +08:00
rm
This commit is contained in:
parent
bfcc112ddd
commit
08d231ad71
@ -1,6 +1,6 @@
|
||||
|
||||
set(VERSION_MAJOR 5)
|
||||
set(VERSION_MINOR 56)
|
||||
set(VERSION_PATCH 2)
|
||||
set(VERSION_PATCH 3)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/version/generate_product_version.cmake)
|
@ -12,8 +12,7 @@
|
||||
<img src="https://image.lunatranslator.org/zh/damoxing/extraapi3.png">
|
||||
</details>
|
||||
|
||||
>**model** can be selected from the drop-down list, and if it's not in the list, you can manually enter/modify it according to the official documentation of the interface.<br>
|
||||
>Some interfaces can dynamically obtain the model list based on **API Interface Address** and **API Key**. After filling in these two items, click the refresh button next to **model** to get the list of available models.
|
||||
>**model** can be selected from a dropdown list, and some interfaces can dynamically fetch the model list based on the **API Interface Address** and **API Key**. After filling in these two fields, click the refresh button next to **model** to obtain the available model list. If the platform does not support the model retrieval interface and the default list does not include the required model, please refer to the official API documentation to manually enter the model.
|
||||
|
||||
### ChatGPT-Compatible Interfaces
|
||||
|
||||
@ -165,6 +164,18 @@ Replace `{endpoint}` and `{deployName}` with your endpoint and deployName.
|
||||
|
||||
**model** https://cloud.tencent.com/document/product/1729/97731
|
||||
|
||||
### **Baidu Qianfan Large Model**
|
||||
|
||||
**API Interface Address** `https://qianfan.baidubce.com/v2`
|
||||
|
||||
**API Key** https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Um2wxbaps
|
||||
|
||||
**model** https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Fm2vrveyu
|
||||
|
||||
!> For the **API Key**, please use the Access Key and Secret Key from Baidu AI Cloud IAM to generate a Bearer Token, which should then be entered as the **API Key**, or directly enter both in the format `{Access Key}:{Secret Key}` in the **API Key** field. Note that this is different from the API Key and Secret Key for the old v1 version of Qianfan ModelBuilder; they are not interchangeable.
|
||||
|
||||
!> Please note, do not enter the API Key and Secret Key for the old v1 version of Qianfan ModelBuilder. The v1 version interface requires using the old **Baidu Qianfan Large Model** dedicated interface, which is hidden by default. To use it, rename _baiduqianfan.py to baiduqianfan.py under LunaTranslator/translator.
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
### Dedicated Interfaces for Specific Platforms
|
||||
@ -197,14 +208,4 @@ Replace `{endpoint}` and `{deployName}` with your endpoint and deployName.
|
||||
|
||||
**model** https://docs.cohere.com/docs/models
|
||||
|
||||
### **Baidu Qianfan Large Model**
|
||||
|
||||
!> This model seems to only support Chinese-English translation and does not support Japanese.
|
||||
|
||||
**model** Should fill in the tail of the **Request Address** in the Baidu interface documentation, for example:
|
||||
|
||||
![img](https://image.lunatranslator.org/zh/damoxing/qianfan1.png)
|
||||
|
||||
![img](https://image.lunatranslator.org/zh/damoxing/qianfan2.png)
|
||||
|
||||
<!-- tabs:end -->
|
@ -12,8 +12,7 @@
|
||||
<img src="https://image.lunatranslator.org/zh/damoxing/extraapi3.png">
|
||||
</details>
|
||||
|
||||
>**model** можно выбрать из выпадающего списка, если его нет в списке, можно ввести/изменить вручную, следуя официальной документации интерфейса.<br>
|
||||
>Некоторые интерфейсы могут динамически получать список моделей на основе **адреса API** и **API Key**. После заполнения этих двух пунктов нажмите кнопку обновления рядом с **model**, чтобы получить список доступных моделей.
|
||||
>**model** можно выбрать из выпадающего списка, и некоторые интерфейсы могут динамически получать список моделей на основе **Адрес API** и **API Key**. После заполнения этих двух полей нажмите кнопку обновления рядом с **model**, чтобы получить доступный список моделей. Если платформа не поддерживает интерфейс для получения модели, а стандартный список не включает нужную модель, пожалуйста, ознакомьтесь с официальной документацией API, чтобы вручную ввести модель.
|
||||
|
||||
### Совместимый с ChatGPT интерфейс
|
||||
|
||||
@ -165,6 +164,18 @@
|
||||
|
||||
**model** https://cloud.tencent.com/document/product/1729/97731
|
||||
|
||||
### **Baidu Qianfan Large Model**
|
||||
|
||||
**Адрес API** `https://qianfan.baidubce.com/v2`
|
||||
|
||||
**API Key** https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Um2wxbaps
|
||||
|
||||
**model** https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Fm2vrveyu
|
||||
|
||||
!> Для **API Key** используйте Access Key и Secret Key из Baidu AI Cloud IAM для генерации Bearer токена, который затем следует ввести как **API Key**, или напрямую введите оба в формате `{Access Key}:{Secret Key}` в поле **API Key**. Обратите внимание, что это отличается от API ключа и Secret Key старой версии v1 Qianfan ModelBuilder; они не взаимозаменяемы.
|
||||
|
||||
!> Обратите внимание, не вводите API ключ и Secret Key старой версии v1 Qianfan ModelBuilder. Интерфейс версии v1 требует использования старого интерфейса **Baidu Qianfan Large Model**, который по умолчанию скрыт. Чтобы использовать его, переименуйте файл _baiduqianfan.py в baiduqianfan.py в папке LunaTranslator/translator.
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
### Специальные интерфейсы для определенных платформ
|
||||
@ -197,14 +208,4 @@
|
||||
|
||||
**model** https://docs.cohere.com/docs/models
|
||||
|
||||
### **Baidu Qianfan Large Model**
|
||||
|
||||
!> Похоже, эта модель поддерживает только перевод с китайского на английский, не поддерживает японский
|
||||
|
||||
**model** следует заполнить хвостовой частью **адреса запроса** в документации Baidu, например:
|
||||
|
||||
![img](https://image.lunatranslator.org/zh/damoxing/qianfan1.png)
|
||||
|
||||
![img](https://image.lunatranslator.org/zh/damoxing/qianfan2.png)
|
||||
|
||||
<!-- tabs:end -->
|
@ -13,9 +13,7 @@
|
||||
<img src="https://image.lunatranslator.org/zh/damoxing/extraapi3.png">
|
||||
</details>
|
||||
|
||||
>**model**可以在下拉列表中选取,如果列表中没有也可以参照接口官方文档手动填写/修改。<br>
|
||||
>部分接口可以根据**API接口地址**和**API Key**动态获取模型列表,填好这两项后点击**model**旁的刷新按钮即可获取可用的模型列表。
|
||||
|
||||
>**model**可以在下拉列表中选取,且部分接口可以根据**API接口地址**和**API Key**动态获取模型列表,填好这两项后点击**model**旁的刷新按钮即可获取可用的模型列表。如果平台不支持拉取模型的接口,且默认列表中没有要用的模型,那么请参照接口官方文档手动填写模型。
|
||||
|
||||
### ChatGPT兼容接口
|
||||
|
||||
@ -170,6 +168,18 @@
|
||||
|
||||
**model** https://cloud.tencent.com/document/product/1729/97731
|
||||
|
||||
### **百度千帆大模型**
|
||||
|
||||
**API接口地址** `https://qianfan.baidubce.com/v2`
|
||||
|
||||
**API Key** https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Um2wxbaps
|
||||
|
||||
**model** https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Fm2vrveyu
|
||||
|
||||
!> **API Key**请使用百度智能云IAM的Access Key、Secret Key来生成接口的BearerToken后作为**API Key**填入,或者按照`{Access Key}:{Secret Key}`的格式直接将两者一起填入**API Key**中。注意,而非千帆ModelBuilder的旧版v1版本接口的API Key、Secret Key,两者不能通用。
|
||||
|
||||
!> 注意,请不要填入千帆ModelBuilder的旧版v1版本接口的API Key、Secret Key,v1版本接口需要使用旧版的**百度千帆大模型**专用接口,该接口已默认隐藏,将LunaTranslator/translator下的_baiduqianfan.py改名为baiduqianfan.py即可使用。
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
### 特定平台的专用接口
|
||||
@ -204,14 +214,4 @@
|
||||
|
||||
**model** https://docs.cohere.com/docs/models
|
||||
|
||||
### **百度千帆大模型**
|
||||
|
||||
!> 这个模型好像只支持中英翻译,不支持日文
|
||||
|
||||
**model** 应填写百度接口文档中的**请求地址**的尾部,例如:
|
||||
|
||||
![img](https://image.lunatranslator.org/zh/damoxing/qianfan1.png)
|
||||
|
||||
![img](https://image.lunatranslator.org/zh/damoxing/qianfan2.png)
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
@ -1,5 +1,6 @@
|
||||
from translator.basetranslator import basetrans
|
||||
import json, requests
|
||||
import json, requests, time, hmac, hashlib
|
||||
from datetime import datetime, timezone
|
||||
from myutils.utils import createurl, createenglishlangmap, urlpathjoin
|
||||
from myutils.proxy import getproxy
|
||||
|
||||
@ -21,6 +22,36 @@ def list_models(typename, regist):
|
||||
raise Exception(resp.maybejson)
|
||||
|
||||
|
||||
class qianfanIAM:
|
||||
|
||||
@staticmethod
|
||||
def sign(access_key_id, secret_access_key):
|
||||
now = datetime.now(timezone.utc)
|
||||
canonical_time = now.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
sign_key_info = f"bce-auth-v1/{access_key_id}/{canonical_time}/8640000"
|
||||
sign_key = hmac.new(
|
||||
secret_access_key.encode(), sign_key_info.encode(), hashlib.sha256
|
||||
).hexdigest()
|
||||
string_to_sign = "GET\n/v1/BCE-BEARER/token\nexpireInSeconds=8640000\nhost:iam.bj.baidubce.com"
|
||||
sign_result = hmac.new(
|
||||
sign_key.encode(), string_to_sign.encode(), hashlib.sha256
|
||||
).hexdigest()
|
||||
return f"{sign_key_info}/host/{sign_result}"
|
||||
|
||||
@staticmethod
|
||||
def getkey(ak, sk, proxy):
|
||||
headers = {
|
||||
"Host": "iam.bj.baidubce.com",
|
||||
"Authorization": qianfanIAM.sign(ak, sk),
|
||||
}
|
||||
return requests.get(
|
||||
"https://iam.bj.baidubce.com/v1/BCE-BEARER/token",
|
||||
params={"expireInSeconds": 8640000},
|
||||
headers=headers,
|
||||
proxies=proxy,
|
||||
).json()["token"]
|
||||
|
||||
|
||||
class gptcommon(basetrans):
|
||||
@property
|
||||
def apiurl(self):
|
||||
@ -33,6 +64,7 @@ class gptcommon(basetrans):
|
||||
|
||||
def __init__(self, typename):
|
||||
self.context = []
|
||||
self.maybeuse = {}
|
||||
super().__init__(typename)
|
||||
|
||||
def createdata(self, message):
|
||||
@ -60,13 +92,18 @@ class gptcommon(basetrans):
|
||||
|
||||
def createheaders(self):
|
||||
_ = {}
|
||||
if self.multiapikeycurrent["SECRET_KEY"]:
|
||||
curkey = self.multiapikeycurrent["SECRET_KEY"]
|
||||
if curkey:
|
||||
# 部分白嫖接口可以不填,填了反而报错
|
||||
_.update(
|
||||
{"Authorization": "Bearer " + self.multiapikeycurrent["SECRET_KEY"]}
|
||||
)
|
||||
_.update({"Authorization": "Bearer " + curkey})
|
||||
if "openai.azure.com/openai/deployments/" in self.apiurl:
|
||||
_.update({"api-key": self.multiapikeycurrent["SECRET_KEY"]})
|
||||
_.update({"api-key": curkey})
|
||||
elif ("qianfan.baidubce.com/v2" in self.apiurl) and (":" in curkey):
|
||||
if not self.maybeuse.get(curkey):
|
||||
Access_Key, Secret_Key = curkey.split(":")
|
||||
key = qianfanIAM.getkey(Access_Key, Secret_Key, self.proxy)
|
||||
self.maybeuse[curkey] = key
|
||||
_.update({"Authorization": "Bearer " + self.maybeuse[curkey]})
|
||||
return _
|
||||
|
||||
def commonparseresponse(self, query, response: requests.ResponseBase, usingstream):
|
||||
|
@ -1997,6 +1997,13 @@
|
||||
"color": "blue",
|
||||
"name": "百度千帆大模型",
|
||||
"is_gpt_like": true
|
||||
},
|
||||
"txhunyuan": {
|
||||
"type": "api",
|
||||
"use": false,
|
||||
"color": "blue",
|
||||
"name": "腾讯混元大模型",
|
||||
"is_gpt_like": true
|
||||
}
|
||||
},
|
||||
"ZoomFactor": 1,
|
||||
|
@ -535,10 +535,12 @@
|
||||
"rank": 2.5
|
||||
},
|
||||
"API_KEY": {
|
||||
"rank": 0
|
||||
"rank": 0,
|
||||
"name": "API Key"
|
||||
},
|
||||
"SECRET_KEY": {
|
||||
"rank": 1
|
||||
"rank": 1,
|
||||
"name": "Secret Key"
|
||||
},
|
||||
"model": {
|
||||
"rank": 2,
|
||||
|
Loading…
x
Reference in New Issue
Block a user