Skip to content

Commit

Permalink
Merge pull request #418 from myronkharkover/feature/add-groq-support
Browse files Browse the repository at this point in the history
Feature/add groq support
  • Loading branch information
Byaidu authored Jan 6, 2025
2 parents 9d3c7e7 + 435d39a commit 592ec8a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/ADVANCED.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
3 changes: 2 additions & 1 deletion pdf2zh/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
XinferenceTranslator,
ArgosTranslator,
GorkTranslator,
GroqTranslator,
DeepseekTranslator,
OpenAIlikedTranslator,
)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions pdf2zh/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
XinferenceTranslator,
ZhipuTranslator,
GorkTranslator,
GroqTranslator,
DeepseekTranslator,
OpenAIlikedTranslator,
)
Expand All @@ -58,6 +59,7 @@
"AnythingLLM": AnythingLLMTranslator,
"Argos Translate": ArgosTranslator,
"Gork": GorkTranslator,
"Groq": GroqTranslator,
"DeepSeek": DeepseekTranslator,
"OpenAI-liked": OpenAIlikedTranslator,
}
Expand Down
18 changes: 18 additions & 0 deletions pdf2zh/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 592ec8a

Please sign in to comment.