vibe.llm_providers.mock¶
Mock LLM provider used for tests and local development.
ConfigurableMockProvider ¶
Easily configurable mock provider that emits tool calls based on simple configuration.
Uses a file-based configuration registry so configuration persists across process boundaries (important for Flask's live_server in tests).
Configure using configure_mock_provider() before starting tests.
This provider works natively with Message and Tool objects.
Features: - Message capture for test assertions (self.calls) - Text chunk emission - Tool call streaming with various argument types - Support for recovery scenarios (premature finalize, no follow-up)
convert_messages_to_provider_format ¶
convert_messages_to_provider_format(messages: list[Message], tools: list[Tool] | None = None) -> list[Message]
Convert internal messages to provider format.
For MockProvider, we don't need to convert anything - we work with typed messages natively. Just return as-is.
stream_generate ¶
stream_generate(messages: list[Message], sequence_number: int, *, session_id: str, assistant_name: str, endpoint_name: str, turn_id: str, previous_response_id: str | None = None, tool_outputs: list[ToolOutput] | None = None, unanswered_predefined_questions: list[dict[str, Any]] | None = None) -> Generator[StreamChunk, None, None]
Stream mock LLM responses for testing.
| Parameters: |
|
|---|
| Yields: |
|
|---|
Note
The mock provider ignores message content and generates responses based on configuration from configure_mock_provider().
get_usage_stats ¶
get_usage_stats() -> UsageStats | None
Return usage stats with actual token counts.
For chunked mode, each chunk counts as 1 token. For non-chunked mode, each text emission counts as 1 token.
get_capabilities ¶
get_capabilities() -> ProviderCapabilities
Return mock provider capabilities, respecting global config for streaming_tools.
configure_mock_provider ¶
configure_mock_provider(*responses: AssistantMessage, port: int = 0, validate_messages: bool = False, chunk_size: int = 0, chunk_delay: int = 0, tools: bool = True, streaming_tools: bool = True) -> None
Configure the mock provider for tests using a file-based approach.
This writes configuration to a port-specific temp file that both the test process and the live_server process can read. Using port-based file names ensures test isolation when running tests in parallel.
| Parameters: |
|
|---|
Examples:
Selenium/live_server test (cross-process, requires port for isolation):¶
configure_mock_provider( AssistantMessage(tool_calls=[ ToolCall("update_chat", {"content": "Hello!"}), ToolCall("ask_question", { "mode": "predefined", "question_id": "name", "answer_type": "text" }) ]), AssistantMessage(tool_calls=[ToolCall("finalize")]), port=live_server.port, )
Flask test client test (same process, port optional):¶
configure_mock_provider( AssistantMessage(tool_calls=[ToolCall("update_chat", {"message": "Hi"})]), tools=False, chunk_size=10 # Stream in 10-char chunks )
clear_mock_provider_config ¶
clear_mock_provider_config(port: int | None = None) -> None
Clear the mock provider configuration.
| Parameters: |
|
|---|