Interactive global-settings setup — only runs when settings are missing. Loops until the configured model passes its check or the user chooses to keep the current settings. On failure we offer a retry, but only when we can actually re-prompt for a different model — i.e. interactive and
(litellm_model_flag: str | None)
| 487 | |
| 488 | |
| 489 | def _setup_user_settings_interactive(litellm_model_flag: str | None) -> None: |
| 490 | """Interactive global-settings setup — only runs when settings are missing. |
| 491 | |
| 492 | Loops until the configured model passes its check or the user chooses to |
| 493 | keep the current settings. On failure we offer a retry, but only when we |
| 494 | can actually re-prompt for a different model — i.e. interactive and not |
| 495 | pinned by ``--litellm-model``; otherwise we just print the next steps. |
| 496 | """ |
| 497 | from .embedder_defaults import lookup_defaults |
| 498 | from .shared import is_sentence_transformers_installed |
| 499 | |
| 500 | st_installed = is_sentence_transformers_installed() |
| 501 | interactive = sys.stdin.isatty() |
| 502 | previous: EmbeddingSettings | None = None |
| 503 | |
| 504 | while True: |
| 505 | embedding = _resolve_embedding_choice( |
| 506 | litellm_model_flag=litellm_model_flag, |
| 507 | st_installed=st_installed, |
| 508 | tty=interactive, |
| 509 | previous=previous, |
| 510 | ) |
| 511 | previous = embedding # remembered as the defaults for a potential retry |
| 512 | |
| 513 | # Apply curated defaults if the model is in our table. |
| 514 | indexing_defaults, query_defaults = lookup_defaults(embedding.provider, embedding.model) |
| 515 | defaults_applied = indexing_defaults is not None or query_defaults is not None |
| 516 | if defaults_applied: |
| 517 | embedding.indexing_params = indexing_defaults or {} |
| 518 | embedding.query_params = query_defaults or {} |
| 519 | |
| 520 | path = save_initial_user_settings(embedding, defaults_applied=defaults_applied) |
| 521 | _typer.echo() |
| 522 | _typer.echo(f"Created user settings: {format_path_for_display(path)}") |
| 523 | |
| 524 | if defaults_applied: |
| 525 | _typer.echo() |
| 526 | _typer.echo(f"Applied recommended defaults for {embedding.model}:") |
| 527 | _typer.echo(f" indexing_params: {embedding.indexing_params}") |
| 528 | _typer.echo(f" query_params: {embedding.query_params}") |
| 529 | |
| 530 | _typer.echo() |
| 531 | _typer.echo(f"Testing embedding model: {embedding.provider} / {embedding.model}") |
| 532 | if _run_init_model_check(): |
| 533 | _typer.echo() |
| 534 | return |
| 535 | |
| 536 | # Model check failed. Retry only makes sense if we can re-prompt. |
| 537 | if interactive and litellm_model_flag is None: |
| 538 | import questionary |
| 539 | |
| 540 | _typer.echo() # separate the failure output from the prompt below |
| 541 | choice = questionary.select( |
| 542 | "The embedding model couldn't be loaded. What would you like to do?", |
| 543 | choices=[ |
| 544 | questionary.Choice(title="Try a different provider/model", value="retry"), |
| 545 | questionary.Choice( |
| 546 | title="Keep these settings and finish — I'll edit the file myself", |
no test coverage detected