From 6dbaee90abfafd17e85fcb702ba8aff88140ee30 Mon Sep 17 00:00:00 2001 From: Myron Kharkover Date: Mon, 6 Jan 2025 08:43:59 -0500 Subject: [PATCH 1/2] feat: add Groq translation support via llama-3-3-70b-versatile --- pdf2zh/translator.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pdf2zh/translator.py b/pdf2zh/translator.py index bb6d0013..3a94fc69 100644 --- a/pdf2zh/translator.py +++ b/pdf2zh/translator.py @@ -723,6 +723,24 @@ def __init__(self, lang_in, lang_out, model, envs=None, prompt=None): if prompt: self.add_cache_impact_parameters("prompt", prompt.template) +class GroqTranslator(OpenAITranslator): + name = "groq" + envs = { + "GROQ_API_KEY": None, + "GROQ_MODEL": "llama-3-3-70b-versatile", + } + CustomPrompt = True + + def __init__(self, lang_in, lang_out, model, envs=None, prompt=None): + self.set_envs(envs) + base_url = "https://api.groq.com/openai/v1" + api_key = self.envs["GROQ_API_KEY"] + if not model: + model = self.envs["GROQ_MODEL"] + super().__init__(lang_in, lang_out, model, base_url=base_url, api_key=api_key) + self.prompttext = prompt + if prompt: + self.add_cache_impact_parameters("prompt", prompt.template) class DeepseekTranslator(OpenAITranslator): name = "deepseek" From 435d39a0781c79114d66345e713620af5e434cf5 Mon Sep 17 00:00:00 2001 From: Myron Kharkover Date: Mon, 6 Jan 2025 08:52:22 -0500 Subject: [PATCH 2/2] feat: add Groq translation support via llama-3-3-70b-versatile, and updated translation service documentation --- docs/ADVANCED.md | 1 + pdf2zh/converter.py | 3 ++- pdf2zh/gui.py | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/ADVANCED.md b/docs/ADVANCED.md index 27b0ff39..b5e8c3b9 100644 --- a/docs/ADVANCED.md +++ b/docs/ADVANCED.md @@ -67,6 +67,7 @@ We've provided a detailed table on the required [environment variables](https:// | **AnythingLLM** | `anythingllm` | `AnythingLLM_URL`, `AnythingLLM_APIKEY` | `[Your AnythingLLM URL]`, `[Your Key]` | See [anything-llm](https://github.com/Mintplex-Labs/anything-llm) | |**Argos Translate**|`argos`| | |See [argos-translate](https://github.com/argosopentech/argos-translate)| |**Grok**|`grok`| `GORK_API_KEY`, `GORK_MODEL` | `[Your GORK_API_KEY]`, `grok-2-1212` |See [Grok](https://docs.x.ai/docs/overview)| +|**Groq**|`groq`| `GROQ_API_KEY`, `GROQ_MODEL` | `[Your GROQ_API_KEY]`, `llama-3-3-70b-versatile` |See [Groq](https://console.groq.com/docs/models)| |**DeepSeek**|`deepseek`| `DEEPSEEK_API_KEY`, `DEEPSEEK_MODEL` | `[Your DEEPSEEK_API_KEY]`, `deepseek-chat` |See [DeepSeek](https://www.deepseek.com/)| |**OpenAI-Liked**|`openai-liked`| `OPENAILIKE_BASE_URL`, `OPENAILIKE_API_KEY`, `OPENAILIKE_MODEL` | `url`, `[Your Key]`, `model name` | None | diff --git a/pdf2zh/converter.py b/pdf2zh/converter.py index e5aa7347..8e4138b7 100644 --- a/pdf2zh/converter.py +++ b/pdf2zh/converter.py @@ -37,6 +37,7 @@ XinferenceTranslator, ArgosTranslator, GorkTranslator, + GroqTranslator, DeepseekTranslator, OpenAIlikedTranslator, ) @@ -158,7 +159,7 @@ def __init__( if not prompt: prompt = [] for translator in [GoogleTranslator, BingTranslator, DeepLTranslator, DeepLXTranslator, OllamaTranslator, XinferenceTranslator, AzureOpenAITranslator, - OpenAITranslator, ZhipuTranslator, ModelScopeTranslator, SiliconTranslator, GeminiTranslator, AzureTranslator, TencentTranslator, DifyTranslator, AnythingLLMTranslator, ArgosTranslator, GorkTranslator, DeepseekTranslator, OpenAIlikedTranslator,]: + OpenAITranslator, ZhipuTranslator, ModelScopeTranslator, SiliconTranslator, GeminiTranslator, AzureTranslator, TencentTranslator, DifyTranslator, AnythingLLMTranslator, ArgosTranslator, GorkTranslator, GroqTranslator, DeepseekTranslator, OpenAIlikedTranslator,]: if service_name == translator.name: self.translator = translator(lang_in, lang_out, service_model, envs=envs, prompt=prompt) if not self.translator: diff --git a/pdf2zh/gui.py b/pdf2zh/gui.py index 4825766c..c867d117 100644 --- a/pdf2zh/gui.py +++ b/pdf2zh/gui.py @@ -34,6 +34,7 @@ XinferenceTranslator, ZhipuTranslator, GorkTranslator, + GroqTranslator, DeepseekTranslator, OpenAIlikedTranslator, ) @@ -58,6 +59,7 @@ "AnythingLLM": AnythingLLMTranslator, "Argos Translate": ArgosTranslator, "Gork": GorkTranslator, + "Groq": GroqTranslator, "DeepSeek": DeepseekTranslator, "OpenAI-liked": OpenAIlikedTranslator, }