fabricatio_mock.utils

Utility module for generating code and generic blocks.

Provides functions to generate fenced code blocks and generic content blocks.

Functions

code_block(→ str)

Generate a code block.

generic_block(→ str)

Generate a generic block.

setup_dummy_responses(→ None)

Configure the singleton router with dummy responses for testing.

install_router_usage(→ Generator[None, None, None])

Configure the singleton router with dummy responses for testing.

make_roles(→ List[fabricatio_core.Role])

Create a list of Role objects from a list of names.

make_n_roles(→ List[fabricatio_core.Role])

Create a list of Role objects with a given number of names.

setup_dummy_embeddings(→ None)

Configure the singleton router with dummy embeddings for testing.

install_dummy_embeddings(→ Generator[None, None, None])

Context manager that configures dummy embeddings for testing.

setup_dummy_reranks(→ None)

Configure the singleton router with dummy reranker rankings for testing.

install_dummy_reranks(→ Generator[None, None, None])

Context manager that configures dummy reranker rankings for testing.

Module Contents

fabricatio_mock.utils.code_block(content: str, lang: str = 'json') str[source]

Generate a code block.

fabricatio_mock.utils.generic_block(content: str, lang: str = 'String') str[source]

Generate a generic block.

fabricatio_mock.utils.setup_dummy_responses(*responses: str, group: str = DUMMY_LLM_GROUP) None[source]

Configure the singleton router with dummy responses for testing.

Mutates the singleton ROUTER in-place. The DummyModel uses LIFO (Vec::pop), so responses are reversed to preserve FIFO semantics.

Parameters:
  • *responses – Pre-formatted response strings (e.g. code_block, generic_block).

  • group – Route group name. Defaults to match LLMTestRole.llm_send_to.

fabricatio_mock.utils.install_router_usage(*responses: str, group: str = DUMMY_LLM_GROUP) Generator[None, None, None][source]

Configure the singleton router with dummy responses for testing.

Mutates the singleton ROUTER in-place. The DummyModel uses LIFO (Vec::pop), so responses are reversed to preserve FIFO semantics.

Parameters:
  • *responses – Pre-formatted response strings (e.g. code_block, generic_block).

  • group – Route group name. Defaults to match LLMTestRole.llm_send_to.

fabricatio_mock.utils.make_roles(names: List[str], role_cls: Type[fabricatio_core.Role] = Role) List[fabricatio_core.Role][source]

Create a list of Role objects from a list of names.

Parameters:
  • names (List[str]) – A list of names for the roles.

  • role_cls (Type[Role]) – The Role class to instantiate.

Returns:

A list of Role objects with the given names.

Return type:

List[Role]

fabricatio_mock.utils.make_n_roles(n: int, role_cls: Type[fabricatio_core.Role] = Role) List[fabricatio_core.Role][source]

Create a list of Role objects with a given number of names.

Parameters:
  • n (int) – The number of names.

  • role_cls (Type[Role]) – The Role class to instantiate.

Returns:

A list of Role objects with the given number of names.

Return type:

List[Role]

fabricatio_mock.utils.setup_dummy_embeddings(*embeddings: list[float], group: str = DUMMY_EMBEDDING_GROUP, model_id: str = 'dummy/test-embedding-model') None[source]

Configure the singleton router with dummy embeddings for testing.

Mutates the singleton ROUTER in-place. The DummyModel uses LIFO (Vec::pop), so embeddings are reversed to preserve FIFO semantics.

Parameters:
  • *embeddings – Embedding vectors (each a list of floats).

  • group – Route group name. Defaults to DUMMY_EMBEDDING_GROUP.

  • model_id – Model identifier string.

fabricatio_mock.utils.install_dummy_embeddings(*embeddings: list[float], group: str = DUMMY_EMBEDDING_GROUP, model_id: str = 'dummy/test-embedding-model') Generator[None, None, None][source]

Context manager that configures dummy embeddings for testing.

Parameters:
  • *embeddings – Embedding vectors (each a list of floats).

  • group – Route group name. Defaults to DUMMY_EMBEDDING_GROUP.

  • model_id – Model identifier string.

fabricatio_mock.utils.setup_dummy_reranks(*rankings: tuple[int, float], group: str = DUMMY_RERANKER_GROUP, model_id: str = 'dummy/test-reranker-model') None[source]

Configure the singleton router with dummy reranker rankings for testing.

Mutates the singleton ROUTER in-place. The DummyModel uses LIFO (Vec::pop), so rankings are reversed to preserve FIFO semantics.

Parameters:
  • *rankings – Ranking tuples of (index, score).

  • group – Route group name. Defaults to DUMMY_RERANKER_GROUP.

  • model_id – Model identifier string.

fabricatio_mock.utils.install_dummy_reranks(*rankings: tuple[int, float], group: str = DUMMY_RERANKER_GROUP, model_id: str = 'dummy/test-reranker-model') Generator[None, None, None][source]

Context manager that configures dummy reranker rankings for testing.

Parameters:
  • *rankings – Ranking tuples of (index, score).

  • group – Route group name. Defaults to DUMMY_RERANKER_GROUP.

  • model_id – Model identifier string.