GettextTranslator.Util.Parser (gettext_translator v0.9.3)

Copy Markdown View Source

Parse files in the gettext root folder

Summary

Functions

Returns the provider the dashboard should preselect in the LLM override form, along with the instance settings that back it.

The provider slugs the dashboard override form offers, which are also the only accepted values of :default_provider.

Returns a summary of the configured LLM provider for display in the dashboard.

Human-readable label for a provider slug, or nil if it is not a known one.

Turns the dashboard override form's params into the provider override map the translation chain consumes.

Functions

instance_default()

@spec instance_default() :: %{
  provider: String.t() | nil,
  model: String.t() | nil,
  adapter: module() | nil,
  endpoint_config: map()
}

Returns the provider the dashboard should preselect in the LLM override form, along with the instance settings that back it.

An instance that already configures a provider — a self-hosted vLLM gateway whose endpoint and API key come from the release's own environment, say — should not make an operator retype those into a dashboard form. Set :default_provider and the override form opens with that adapter selected and the configured model filled in, and treats blank credential fields as "use whatever the instance is already configured with":

config :gettext_translator, GettextTranslator,
  endpoint: MyApp.LLM.ChatVLLM,
  endpoint_model: System.get_env("GETTEXT_TRANSLATOR_MODEL", "gemma-4-26b-a4b-it"),
  default_provider: :vllm

The value may be an atom or a string naming one of the adapters the form offers (:openai, :anthropic, :ollama, :google_ai, :vllm).

:provider is nil when :default_provider is unset, which leaves the override form behaving exactly as it did before this option existed.

known_providers()

@spec known_providers() :: [String.t()]

The provider slugs the dashboard override form offers, which are also the only accepted values of :default_provider.

parse_provider()

provider_info()

@spec provider_info() ::
  %{configured: boolean(), adapter_name: String.t(), model: String.t()}
  | %{configured: false}

Returns a summary of the configured LLM provider for display in the dashboard.

Returns %{configured: true, adapter_name: "ChatOpenAI", model: "gpt-4"} when configured, or %{configured: false} otherwise.

provider_label(provider)

@spec provider_label(String.t() | nil) :: String.t() | nil

Human-readable label for a provider slug, or nil if it is not a known one.

"google_ai" is not what anyone wants to read in a form label.

resolve_override(params, defaults)

@spec resolve_override(map(), map()) :: %{
  adapter: module(),
  adapter_name: String.t(),
  model: String.t(),
  config: map()
}

Turns the dashboard override form's params into the provider override map the translation chain consumes.

Lives here rather than in the page because it is provider/config resolution rather than view logic, and because the two decisions it makes are worth testing directly:

  • Which adapter module. Choosing the provider the instance is configured for uses that instance's own :endpoint module, not the generic LangChain one. For a self-hosted gateway that is the whole point: a module like MyApp.LLM.ChatVLLM resolves its endpoint and bearer token from the release environment, where ChatOpenAI would need the full completions URL typed into the form.

  • Which credentials. Blank fields inherit the instance's :endpoint_config, but only when the submitted adapter is the configured one — picking a different provider must not send it another provider's key. Anything actually typed always wins.

scan(gettext_root_path)