8000 Update for openrouter by MusicTsai · Pull Request #107 · coseeing/WordBridge · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update for openrouter #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"model": {
"model_name": "deepseek-chat",
"provider": "DeepSeek",
"llm_access_method": "personal_api_key",
"require_secret_key": true,
"template_name": "Standard_v1.json",
"optional_guidance_enable": {
"keep_non_chinese_char": false,
"no_explanation": true
}
},
"typo_corrector": {
"typo_correction_mode": "Standard Mode"
}
}
11 changes: 6 additions & 5 deletions addon/globalPlugins/WordBridge/lib/typo_corrector.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def _(s):

API_URLS = {
"openai": "https://api.openai.com/v1/chat/completions",
"openrouter": "https://openrouter.ai/api/v1/chat/completions",
"baidu": "https://qianfan.baidubce.com/v2/chat/completions",
"deepseek": "https://api.deepseek.com/chat/completions",
"ollama": "http://localhost:11434/api/chat",
Expand Down Expand Up @@ -81,7 +82,7 @@ def __init__(
"no_explanation": False,
"keep_non_chinese_char": True,
}
elif self.provider == "baidu" or self.provider == "deepseek":
elif self.provider in ["baidu", "deepseek", "openrouter"]:
self.optional_guidance_enable = {
"no_explanation": True,
"keep_non_chinese_char": False,
Expand Down Expand Up @@ -122,7 +123,7 @@ def correct_text(self, text: str, batch_mode: bool = True, fake_corrected_text:
if fake_corrected_text is not None:
return fake_corrected_text, strings_diff(text, fake_corrected_text)

if self.provider in ["openai", "baidu", "deepseek"]:
if self.provider in ["openai", "baidu", "deepseek", "openrouter"]:
parse = urlparse(API_URLS[self.provider])
base_url = f"{parse.scheme}://{parse.netloc}"
self._try_internet_connection(base_url)
Expand Down Expand Up @@ -388,7 +389,7 @@ def _get_request_data(self, messages, input_info):
"messages": messages,
**setting,
}
elif self.provider in ["ollama", "deepseek"]:
elif self.provider in ["ollama", "deepseek", "openrouter"]:
data = {
"model": self.model,
"messages": messages,
Expand All @@ -404,7 +405,7 @@ def _get_request_data(self, messages, input_info):

def _get_headers(self):
headers = {'Content-Type': 'application/json'}
if self.provider in ["openai", "baidu", "deepseek"]:
if self.provider in ["openai", "baidu", "deepseek", "openrouter"]:
headers = {"Authorization": f"Bearer {self.credential['api_key']}"}
elif self.provider not in API_URLS.keys():
raise NotImplementedError("Subclass must implement this method")
Expand Down Expand Up @@ -510,7 +511,7 @@ def _handle_baidu_errors(self, response_json):
raise Exception(_("An error occurred, error code = ") + response_json["error_msg"])

def _parse_response(self, response: str) -> str:
if self.provider in ["openai", "baidu", "deepseek"]:
if self.provider in ["openai", "baidu", "deepseek", "openrouter"]:
sentence = response["choices"][0]["message"]["content"]
elif self.provider == "ollama":
sentence = response["message"]["content"]
Expand Down
6 changes: 6 additions & 0 deletions addon/globalPlugins/WordBridge/llm_setting/openrouter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"max_tokens": 4096,
"temperature": 0.0,
"top_p": 0.0,
"stop": [ " =>" ]
}
0