mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
azure
This commit is contained in:
parent
438222e9db
commit
4259e235c6
@ -39,9 +39,6 @@ class OCR(baseocr):
|
|||||||
)
|
)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def createparam(self):
|
|
||||||
return None
|
|
||||||
|
|
||||||
def createheaders(self):
|
def createheaders(self):
|
||||||
return {"Authorization": "Bearer " + self.config["SECRET_KEY"]}
|
return {"Authorization": "Bearer " + self.config["SECRET_KEY"]}
|
||||||
|
|
||||||
@ -93,7 +90,6 @@ class OCR(baseocr):
|
|||||||
response = self.proxysession.post(
|
response = self.proxysession.post(
|
||||||
self.createurl(),
|
self.createurl(),
|
||||||
headers=self.createheaders(),
|
headers=self.createheaders(),
|
||||||
params=self.createparam(),
|
|
||||||
json=self.createdata(message),
|
json=self.createdata(message),
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
14
LunaTranslator/LunaTranslator/translator/azureopenai.py
Normal file
14
LunaTranslator/LunaTranslator/translator/azureopenai.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from translator.gptcommon import gptcommon
|
||||||
|
|
||||||
|
|
||||||
|
class TS(gptcommon):
|
||||||
|
def createurl(self):
|
||||||
|
return f'https://{self.config["endpoint"]}/openai/deployments/{self.config["deployment-id"]}/completions?api-version={self.config["api-version"]}'
|
||||||
|
|
||||||
|
def createheaders(self):
|
||||||
|
_ = super().createheaders()
|
||||||
|
_.update({"api-key": self.multiapikeycurrent["api-key"]})
|
||||||
|
|
||||||
|
def translate(self, query):
|
||||||
|
self.checkempty(["api-key", "api-version", "endpoint", "deployment-id"])
|
||||||
|
return super().translate(query)
|
@ -1,25 +0,0 @@
|
|||||||
from translator.gptcommon import gptcommon
|
|
||||||
|
|
||||||
|
|
||||||
class TS(gptcommon):
|
|
||||||
def createurl(self):
|
|
||||||
return self.config["OPENAI_API_BASE"] + self.config["Appedix"]
|
|
||||||
|
|
||||||
def createparam(self):
|
|
||||||
api_type = self.config["api_type"]
|
|
||||||
if api_type in [1, 2]:
|
|
||||||
api_version = "2023-05-15"
|
|
||||||
return {"api-version": api_version}
|
|
||||||
else:
|
|
||||||
return super().createparam()
|
|
||||||
|
|
||||||
def createheaders(self):
|
|
||||||
api_type = self.config["api_type"]
|
|
||||||
_ = super().createheaders()
|
|
||||||
if api_type == 1: # azure
|
|
||||||
_.update({"api-key": self.multiapikeycurrent["SECRET_KEY"]})
|
|
||||||
return _
|
|
||||||
|
|
||||||
def translate(self, query):
|
|
||||||
self.checkempty(["SECRET_KEY", "model"])
|
|
||||||
return super().translate(query)
|
|
@ -50,9 +50,6 @@ class gptcommon(basetrans):
|
|||||||
pass
|
pass
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def createparam(self):
|
|
||||||
return None
|
|
||||||
|
|
||||||
def createheaders(self):
|
def createheaders(self):
|
||||||
return {"Authorization": "Bearer " + self.multiapikeycurrent["SECRET_KEY"]}
|
return {"Authorization": "Bearer " + self.multiapikeycurrent["SECRET_KEY"]}
|
||||||
|
|
||||||
@ -158,7 +155,6 @@ class gptcommon(basetrans):
|
|||||||
response = self.proxysession.post(
|
response = self.proxysession.post(
|
||||||
self.createurl(),
|
self.createurl(),
|
||||||
headers=self.createheaders(),
|
headers=self.createheaders(),
|
||||||
params=self.createparam(),
|
|
||||||
json=self.createdata(message),
|
json=self.createdata(message),
|
||||||
stream=usingstream,
|
stream=usingstream,
|
||||||
)
|
)
|
||||||
|
@ -1561,6 +1561,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"fanyi": {
|
"fanyi": {
|
||||||
|
"chatgpt-3rd-party": {
|
||||||
|
"type": "api",
|
||||||
|
"use": false,
|
||||||
|
"color": "blue",
|
||||||
|
"name": "ChatGPT_兼容接口",
|
||||||
|
"is_gpt_like": true
|
||||||
|
},
|
||||||
"microsoft": {
|
"microsoft": {
|
||||||
"use": false,
|
"use": false,
|
||||||
"color": "gray",
|
"color": "gray",
|
||||||
@ -1932,11 +1939,11 @@
|
|||||||
"color": "blue",
|
"color": "blue",
|
||||||
"name": "有道api"
|
"name": "有道api"
|
||||||
},
|
},
|
||||||
"chatgpt": {
|
"azureopenai": {
|
||||||
"type": "api",
|
"type": "api",
|
||||||
"use": false,
|
"use": false,
|
||||||
"color": "blue",
|
"color": "blue",
|
||||||
"name": "ChatGPT",
|
"name": "Azure Openai",
|
||||||
"is_gpt_like": true
|
"is_gpt_like": true
|
||||||
},
|
},
|
||||||
"cohere": {
|
"cohere": {
|
||||||
@ -1953,13 +1960,6 @@
|
|||||||
"name": "claude",
|
"name": "claude",
|
||||||
"is_gpt_like": true
|
"is_gpt_like": true
|
||||||
},
|
},
|
||||||
"chatgpt-3rd-party": {
|
|
||||||
"type": "api",
|
|
||||||
"use": false,
|
|
||||||
"color": "blue",
|
|
||||||
"name": "ChatGPT_兼容接口",
|
|
||||||
"is_gpt_like": true
|
|
||||||
},
|
|
||||||
"hanshant": {
|
"hanshant": {
|
||||||
"type": "offline",
|
"type": "offline",
|
||||||
"use": false,
|
"use": false,
|
||||||
|
@ -209,20 +209,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"chatgpt": {
|
"azureopenai": {
|
||||||
"args": {
|
"args": {
|
||||||
"SECRET_KEY": "",
|
"api-key": "",
|
||||||
"Temperature": 0.3,
|
"Temperature": 0.3,
|
||||||
"top_p": 0.3,
|
"top_p": 0.3,
|
||||||
"max_tokens": 128,
|
"max_tokens": 128,
|
||||||
"frequency_penalty": 0,
|
"frequency_penalty": 0,
|
||||||
"model": "gpt-3.5-turbo",
|
"model": "gpt-3.5-turbo",
|
||||||
"附带上下文个数": 0,
|
"附带上下文个数": 0,
|
||||||
"OPENAI_API_BASE": "https://api.openai.com/v1",
|
"endpoint": "https://your-resource-name.openai.azure.com",
|
||||||
"Appedix": "/chat/completions",
|
"deployment-id":"",
|
||||||
|
"api-version":"2024-06-01",
|
||||||
"使用自定义promt": false,
|
"使用自定义promt": false,
|
||||||
"自定义promt": "",
|
"自定义promt": "",
|
||||||
"api_type": 0,
|
|
||||||
"流式输出": true,
|
"流式输出": true,
|
||||||
"user_user_prompt": "{sentence}",
|
"user_user_prompt": "{sentence}",
|
||||||
"use_user_user_prompt": false,
|
"use_user_user_prompt": false,
|
||||||
@ -245,12 +245,15 @@
|
|||||||
"type": "split",
|
"type": "split",
|
||||||
"rank": 2.5
|
"rank": 2.5
|
||||||
},
|
},
|
||||||
"OPENAI_API_BASE": {
|
"endpoint": {
|
||||||
"rank": 0
|
"rank": 0
|
||||||
},
|
},
|
||||||
"Appedix": {
|
"deployment-id": {
|
||||||
"rank": 1
|
"rank": 1
|
||||||
},
|
},
|
||||||
|
"api-version": {
|
||||||
|
"rank": 1.5
|
||||||
|
},
|
||||||
"model": {
|
"model": {
|
||||||
"rank": 2
|
"rank": 2
|
||||||
},
|
},
|
||||||
@ -282,16 +285,7 @@
|
|||||||
"type": "switch",
|
"type": "switch",
|
||||||
"rank": 3
|
"rank": 3
|
||||||
},
|
},
|
||||||
"api_type": {
|
"api-key": {
|
||||||
"type": "combo",
|
|
||||||
"rank": 1.5,
|
|
||||||
"list": [
|
|
||||||
"open_ai",
|
|
||||||
"azure",
|
|
||||||
"azure_ad"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"SECRET_KEY": {
|
|
||||||
"rank": 1.6
|
"rank": 1.6
|
||||||
},
|
},
|
||||||
"附带上下文个数": {
|
"附带上下文个数": {
|
||||||
|
@ -132,6 +132,10 @@
|
|||||||
|
|
||||||
**model** https://docs.cohere.com/docs/models
|
**model** https://docs.cohere.com/docs/models
|
||||||
|
|
||||||
|
### **Azure**
|
||||||
|
|
||||||
|
https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#completions
|
||||||
|
|
||||||
<!-- tabs:end -->
|
<!-- tabs:end -->
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user