Add ux profiles and advanced config block
This commit is contained in:
parent
c8739b6804
commit
77ae21d0f6
4 changed files with 68 additions and 3 deletions
|
|
@ -69,6 +69,7 @@ class LlamaProcessor:
|
|||
lang: str = "en",
|
||||
*,
|
||||
dictionary_context: str = "",
|
||||
profile: str = "default",
|
||||
) -> str:
|
||||
request_payload: dict[str, Any] = {
|
||||
"language": lang,
|
||||
|
|
@ -87,6 +88,7 @@ class LlamaProcessor:
|
|||
}
|
||||
if _supports_response_format(self.client.create_chat_completion):
|
||||
kwargs["response_format"] = {"type": "json_object"}
|
||||
kwargs.update(_profile_generation_kwargs(self.client.create_chat_completion, profile))
|
||||
|
||||
response = self.client.create_chat_completion(**kwargs)
|
||||
return _extract_cleaned_text(response)
|
||||
|
|
@ -205,11 +207,25 @@ def _extract_cleaned_text(payload: Any) -> str:
|
|||
|
||||
|
||||
def _supports_response_format(chat_completion: Callable[..., Any]) -> bool:
|
||||
return _supports_parameter(chat_completion, "response_format")
|
||||
|
||||
|
||||
def _supports_parameter(callable_obj: Callable[..., Any], parameter: str) -> bool:
|
||||
try:
|
||||
signature = inspect.signature(chat_completion)
|
||||
signature = inspect.signature(callable_obj)
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
return "response_format" in signature.parameters
|
||||
return parameter in signature.parameters
|
||||
|
||||
|
||||
def _profile_generation_kwargs(chat_completion: Callable[..., Any], profile: str) -> dict[str, Any]:
|
||||
normalized = (profile or "default").strip().lower()
|
||||
if normalized != "fast":
|
||||
return {}
|
||||
if not _supports_parameter(chat_completion, "max_tokens"):
|
||||
return {}
|
||||
# Faster profile trades completion depth for lower latency.
|
||||
return {"max_tokens": 192}
|
||||
|
||||
|
||||
def _llama_log_callback_factory(verbose: bool) -> Callable:
|
||||
|
|
|
|||
|
|
@ -233,6 +233,7 @@ class Daemon:
|
|||
text,
|
||||
lang=STT_LANGUAGE,
|
||||
dictionary_context=self.vocabulary.build_ai_dictionary_context(),
|
||||
profile=self.cfg.ux.profile,
|
||||
)
|
||||
if ai_text and ai_text.strip():
|
||||
text = ai_text.strip()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue