Repository: Pythagora-io/gpt-pilot
File: core/cli/main.py (Python)

Code before:
        await ui.send_message(f"Stopping Pythagora due to error:\n\n{stack_trace}", source=pythagora_source)

    await telemetry.send()
    return success


async def llm_api_check(ui: UIBase) -> bool:
    """
    Check whether the configured LLMs are reachable.

    :param ui: UI we'll use to report any issues
    :return: True if all the LLMs are reachable.
    """

    config = get_config()

    async def handler(*args, **kwargs):
        pass

    success = True
    checked_llms: set[LLMProvider] = set()
    for llm_config in config.all_llms():
        if llm_config.provider in checked_llms:
            continue

        client_class = BaseLLMClient.for_provider(llm_config.provider)
        llm_client = client_class(llm_config, stream_handler=handler, error_handler=handler)
        try:
            resp = await llm_client.api_check()
            if not resp:
                success = False
                log.warning(f"API check for {llm_config.provider.value} failed.")
            else:
                log.info(f"API check for {llm_config.provider.value} succeeded.")
        except APIError as err:
            await ui.send_message(f"API check for {llm_config.provider.value} failed with: {err}")
            log.warning(f"API check for {llm_config.provider.value} failed with: {err}")
            success = False

    if not success:
        telemetry.set("end_result", "failure:api-error")

    return success


async def start_new_project(sm: StateManager, ui: UIBase) -> bool:
    """
    Start a new project.

    :param sm: State manager.
    :param ui: User interface.

Review comment (suggestion):
Unrelated to this particular PR, but since stream_handler is optional in llm's `__call__`, we should make sure that these don't actually need to be set (for example stream_handler is optional, but error_handler is always executed even if not set). So I'd suggest there's an `if self.error_handler` in __call__.


Code after:

    await telemetry.send()
    return success


async def llm_api_check(ui: UIBase) -> bool:
    """
    Check whether the configured LLMs are reachable.

    :param ui: UI we'll use to report any issues
    :return: True if all the LLMs are reachable.
    """

    config = get_config()

    async def handler(*args, **kwargs):
        pass

    success = True
    checked_llms: set[LLMProvider] = set()
    for llm_config in config.all_llms():
        if llm_config.provider in checked_llms:
            continue

        client_class = BaseLLMClient.for_provider(llm_config.provider)
        llm_client = client_class(llm_config, stream_handler=handler, error_handler=handler)
        try:
            resp = await llm_client.api_check()
            if not resp:
                success = False
                log.warning(f"API check for {llm_config.provider.value} failed.")
            else:
                log.info(f"API check for {llm_config.provider.value} succeeded.")
        except APIError as err:
            await ui.send_message(f"API check for {llm_config.provider.value} failed with: {err}")
            log.warning(f"API check for {llm_config.provider.value} failed with: {err}")
            success = False

    if not success:
        telemetry.set("end_result", "failure:api-error")

    return success


async def start_new_project(sm: StateManager, ui: UIBase) -> bool:
    """
    Start a new project.

    :param sm: State manager.
    :param ui: User interface.
    :return: True if the project was created successfully, False otherwise.