fabricatio_mock.models.mock_router

Module mock_router.

This module provides utility functions for creating asynchronous mock objects that simulate the behavior of a LiteLLM Router. It is primarily intended for use in testing scenarios where actual network requests to language models are not desirable or necessary.

Classes

Value

Value class for mocking responses.

Functions

pad_responses(→ list[str])

Build a padded response list for DummyModel.

return_router_usage(→ list[str])

Build padded response strings for install_router_usage.

return_generic_router_usage(→ list[str])

Build generic-block-formatted responses for install_router_usage.

return_code_router_usage(→ list[str])

Build code-block-formatted responses for install_router_usage.

return_python_router_usage(→ list[str])

Build Python-code-block responses for install_router_usage.

return_json_router_usage(→ list[str])

Build JSON-code-block responses for install_router_usage.

return_json_obj_router_usage(→ list[str])

Build serialized-JSON responses for install_router_usage.

return_model_json_router_usage(→ list[str])

Build serialized-Pydantic-model responses for install_router_usage.

return_mixed_router_usage(→ list[str])

Build mixed-type responses for install_router_usage.

pad_embeddings(→ list[list[float]])

Build a padded embeddings list for DummyModel.

pad_rankings(→ list[tuple[int, float]])

Build a padded rankings list for DummyModel.

Module Contents

class fabricatio_mock.models.mock_router.Value[M: pydantic.BaseModel | str][source]

Value class for mocking responses.

source: M

The source data to be used for mocking. Can be a BaseModel instance

type: Literal['model', 'json', 'python', 'raw', 'generic']

Specifies the type of the source data, which determines how the data will be processed when converted to a string representation.

convertor: Callable[[M], str] | None = None
to_string() str[source]

Converts the source data to a string representation based on its type.

Returns:

The processed string representation of the source data.

Return type:

str

Raises:

ValueError – If the type is invalid or unsupported.

fabricatio_mock.models.mock_router.pad_responses(*value: str, default: str | None = None, padding: int = 10) list[str][source]

Build a padded response list for DummyModel.

DummyModel errors when its queue is exhausted. Pad with extra copies of the default value to cover retries (max_validations) and batch calls.

Parameters:
  • *value (str) – Response strings.

  • default (Optional[str]) – Value used for padding. Defaults to the last value.

  • padding (int) – Number of extra copies appended. Defaults to 10.

Returns:

value followed by padding copies of the default.

Return type:

list[str]

fabricatio_mock.models.mock_router.return_router_usage(*value: str, default: str | None = None, padding: int = 10) list[str][source]

Build padded response strings for install_router_usage.

Like return_string but returns a list of pre-formatted strings for use with install_router_usage(). DummyModel handles the LIFO→FIFO reversal inside setup_dummy_responses.

Parameters:
  • *value (str) – Response strings to return sequentially.

  • default (Optional[str]) – Default value when responses exhausted.

  • padding (int) – Number of extra copies appended. Defaults to 10.

Returns:

Padded response strings ready for install_router_usage.

Return type:

list[str]

fabricatio_mock.models.mock_router.return_generic_router_usage(*strings: str, lang: str = 'string', default: str | None = None, padding: int = 10) list[str][source]

Build generic-block-formatted responses for install_router_usage.

Parameters:
  • *strings (str) – Content strings to wrap in generic blocks.

  • lang (str) – Block type identifier.

  • default (Optional[str]) – Default value when exhausted.

  • padding (int) – Number of extra copies appended. Defaults to 10.

Returns:

Formatted and padded response strings.

Return type:

list[str]

fabricatio_mock.models.mock_router.return_code_router_usage(*codes: str, lang: str, default: str | None = None, padding: int = 10) list[str][source]

Build code-block-formatted responses for install_router_usage.

Parameters:
  • *codes (str) – Source code strings to wrap in code blocks.

  • lang (str) – Programming language identifier.

  • default (Optional[str]) – Default value when exhausted.

  • padding (int) – Number of extra copies appended. Defaults to 10.

Returns:

Formatted and padded response strings.

Return type:

list[str]

fabricatio_mock.models.mock_router.return_python_router_usage(*codes: str, default: str | None = None, padding: int = 10) list[str][source]

Build Python-code-block responses for install_router_usage.

Parameters:
  • *codes (str) – Python code strings.

  • default (Optional[str]) – Default value when exhausted.

  • padding (int) – Number of extra copies appended. Defaults to 10.

Returns:

Formatted and padded response strings.

Return type:

list[str]

fabricatio_mock.models.mock_router.return_json_router_usage(*jsons: str, default: str | None = None, padding: int = 10) list[str][source]

Build JSON-code-block responses for install_router_usage.

Parameters:
  • *jsons (str) – JSON content strings.

  • default (Optional[str]) – Default value when exhausted.

  • padding (int) – Number of extra copies appended. Defaults to 10.

Returns:

Formatted and padded response strings.

Return type:

list[str]

fabricatio_mock.models.mock_router.return_json_obj_router_usage(*objs: pydantic.JsonValue, default: str | None = None, padding: int = 10) list[str][source]

Build serialized-JSON responses for install_router_usage.

Parameters:
  • *objs (JsonValue) – Objects to serialize as JSON.

  • default (Optional[str]) – Default value when exhausted.

  • padding (int) – Number of extra copies appended. Defaults to 10.

Returns:

Formatted and padded response strings.

Return type:

list[str]

fabricatio_mock.models.mock_router.return_model_json_router_usage(*models: pydantic.BaseModel, default: str | None = None, padding: int = 10) list[str][source]

Build serialized-Pydantic-model responses for install_router_usage.

Parameters:
  • *models (BaseModel) – Pydantic models to serialize.

  • default (Optional[str]) – Default value when exhausted.

  • padding (int) – Number of extra copies appended. Defaults to 10.

Returns:

Formatted and padded response strings.

Return type:

list[str]

fabricatio_mock.models.mock_router.return_mixed_router_usage(*values: Value, default: str | None = None, padding: int = 10) list[str][source]

Build mixed-type responses for install_router_usage.

Parameters:
  • *values (Value) – Values to process and return as strings.

  • default (Optional[str]) – Default value when exhausted.

  • padding (int) – Number of extra copies appended. Defaults to 10.

Returns:

Formatted and padded response strings.

Return type:

list[str]

fabricatio_mock.models.mock_router.pad_embeddings(*embeddings: list[float], default: list[float] | None = None, padding: int = 10) list[list[float]][source]

Build a padded embeddings list for DummyModel.

DummyModel errors when its queue is exhausted. Pad with extra copies of the default value to cover retries and batch calls.

Parameters:
  • *embeddings – Embedding vectors.

  • default – Value used for padding. Defaults to the last embedding.

  • padding – Number of extra copies appended. Defaults to 10.

Returns:

embeddings followed by padding copies of default.

Return type:

list[list[float]]

fabricatio_mock.models.mock_router.pad_rankings(*rankings: tuple[int, float], default: tuple[int, float] | None = None, padding: int = 10) list[tuple[int, float]][source]

Build a padded rankings list for DummyModel.

DummyModel errors when its queue is exhausted. Pad with extra copies of the default value to cover retries and batch calls.

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

  • default – Value used for padding. Defaults to the last ranking.

  • padding – Number of extra copies appended. Defaults to 10.

Returns:

rankings followed by padding copies of default.

Return type:

list[tuple[int, float]]