mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-11 19:06:11 +00:00
Put the three providers in a table, and test the request rather than the list
Reworked on top of master. The Groq request itself needed nothing beyond a key, a base URL and a model id, but two providers fit in an if and an else where three do not, and each one was written out four times: in transcribe_target(), in the key rows of the settings window, in save and in load. config.TRANSCRIBERS holds them now, one row each: the name the user sees and the three settings that keep its key, its endpoint and its model. The variable an empty key falls back to is the name of its setting, shouted. The provider box, save, load, `dikte models --provider` and `dikte test-key` all read that table, so a fourth provider is a row and a default rather than a branch in five files. The key field, its Test button and its answer line are built once and the three signals became one that carries which key was asked about. The tests moved into the files of the modules they cover and check what a provider actually changes: that the request goes to api.groq.com with the right model and fields, that the glossary now reaches everything except OpenRouter, that a Groq error says Groq, and that the settings window carries the key and the model there and back. GROQ_API_KEY is cleared for the test run like the other two, so a developer who has one does not send a test to the network. Co-authored-by: Muzaffer Emre <[email protected]>
This commit is contained in:
co-authored by
Muzaffer Emre
parent
22edd2f247
commit
d04efe235a
@@ -1,9 +1,9 @@
|
||||
"""OpenAI-compatible transcription and OpenRouter calls, stdlib only.
|
||||
"""OpenAI, Groq and OpenRouter calls, stdlib only.
|
||||
|
||||
Transcription runs on either provider: OpenRouter mirrors OpenAI's
|
||||
Transcription runs on any of the three: Groq and OpenRouter both mirror OpenAI's
|
||||
/audio/transcriptions endpoint field for field, so one multipart request serves
|
||||
both and only the key, the base URL and the model id change. Cleanup is always
|
||||
OpenRouter.
|
||||
all of them and only the key, the base URL and the model id change. Cleanup is
|
||||
always OpenRouter.
|
||||
"""
|
||||
|
||||
import collections
|
||||
@@ -19,8 +19,8 @@ from i18n import t
|
||||
APP_URL = "https://github.com/yusufipk/dikte"
|
||||
USER_AGENT = f"dikte/1.0 (+{APP_URL})"
|
||||
OPENAI_URL = "https://api.openai.com/v1"
|
||||
OPENROUTER_URL = "https://openrouter.ai/api/v1"
|
||||
GROQ_URL = "https://api.groq.com/openai/v1"
|
||||
OPENROUTER_URL = "https://openrouter.ai/api/v1"
|
||||
|
||||
# Where a transcription request goes; built by config.Config.transcribe_target().
|
||||
# `service` is the name the user sees in an error, `provider` the one the code
|
||||
@@ -29,7 +29,12 @@ Target = collections.namedtuple("Target", "provider service api_key base_url mod
|
||||
|
||||
|
||||
def timestamp_model(provider, selected=""):
|
||||
"""Return a timestamp-capable model id for the selected provider."""
|
||||
"""Which model answers with segment times.
|
||||
|
||||
OpenAI keeps them to whisper-1 and OpenRouter namespaces that id. Everything
|
||||
Groq transcribes with is a whisper, so the model already chosen does it and
|
||||
the fallback is only for a provider left on its default.
|
||||
"""
|
||||
if provider == "groq":
|
||||
return selected or "whisper-large-v3-turbo"
|
||||
return "openai/whisper-1" if provider == "openrouter" else "whisper-1"
|
||||
@@ -301,6 +306,11 @@ def openrouter_models(api_key="", transcription=False):
|
||||
|
||||
|
||||
def openai_models(api_key, base_url=OPENAI_URL, service="OpenAI"):
|
||||
"""The audio models of anything that speaks OpenAI's /models, Groq included.
|
||||
|
||||
`service` is only the name an error is written in, so a Groq key that is
|
||||
refused says Groq rather than OpenAI.
|
||||
"""
|
||||
if not api_key:
|
||||
raise ApiError(t("{service} API key is empty. Add it in Settings.",
|
||||
service=service))
|
||||
|
||||
Reference in New Issue
Block a user