fabricatio_mock.utils
Utility module for generating code and generic blocks.
Provides functions to generate fenced code blocks and generic content blocks.
Functions
|
Generate a code block. |
|
Generate a generic block. |
|
Configure the singleton router with dummy responses for testing. |
|
Configure the singleton router with dummy responses for testing. |
|
Create a list of Role objects from a list of names. |
|
Create a list of Role objects with a given number of names. |
|
Configure the singleton router with dummy embeddings for testing. |
|
Context manager that configures dummy embeddings for testing. |
|
Configure the singleton router with dummy reranker rankings for testing. |
|
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.
- 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.
- 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.