Home / Class/ MockOpenAIResponse Class — langchain Architecture

MockOpenAIResponse Class — langchain Architecture

Architecture documentation for the MockOpenAIResponse class in test_chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  8afadf8a_966d_777a_66f4_b8046564ec85["MockOpenAIResponse"]
  5ea44688_e61e_5f0e_f4f7_57f0ea8b7bb6["test_chat_models.py"]
  8afadf8a_966d_777a_66f4_b8046564ec85 -->|defined in| 5ea44688_e61e_5f0e_f4f7_57f0ea8b7bb6
  a7102bfb_0dde_e515_c898_bbf34538d582["model_dump()"]
  8afadf8a_966d_777a_66f4_b8046564ec85 -->|method| a7102bfb_0dde_e515_c898_bbf34538d582

Relationship Graph

Source Code

libs/partners/deepseek/tests/unit_tests/test_chat_models.py lines 20–63

class MockOpenAIResponse(BaseModel):
    """Mock OpenAI response model."""

    choices: list
    error: None = None

    def model_dump(  # type: ignore[override]
        self,
        *,
        mode: Literal["json", "python"] | str = "python",  # noqa: PYI051
        include: Any = None,
        exclude: Any = None,
        by_alias: bool = False,
        exclude_unset: bool = False,
        exclude_defaults: bool = False,
        exclude_none: bool = False,
        round_trip: bool = False,
        warnings: Literal["none", "warn", "error"] | bool = True,
        context: dict[str, Any] | None = None,
        serialize_as_any: bool = False,
    ) -> dict[str, Any]:
        """Convert to dictionary, ensuring `reasoning_content` is included."""
        choices_list = []
        for choice in self.choices:
            if isinstance(choice.message, ChatCompletionMessage):
                message_dict = choice.message.model_dump()
                # Ensure model_extra fields are at top level
                if "model_extra" in message_dict:
                    message_dict.update(message_dict["model_extra"])
            else:
                message_dict = {
                    "role": "assistant",
                    "content": choice.message.content,
                }
                # Add reasoning_content if present
                if hasattr(choice.message, "reasoning_content"):
                    message_dict["reasoning_content"] = choice.message.reasoning_content
                # Add model_extra fields at the top level if present
                if hasattr(choice.message, "model_extra"):
                    message_dict.update(choice.message.model_extra)
                    message_dict["model_extra"] = choice.message.model_extra
            choices_list.append({"message": message_dict})

        return {"choices": choices_list, "error": self.error}

Frequently Asked Questions

What is the MockOpenAIResponse class?
MockOpenAIResponse is a class in the langchain codebase, defined in libs/partners/deepseek/tests/unit_tests/test_chat_models.py.
Where is MockOpenAIResponse defined?
MockOpenAIResponse is defined in libs/partners/deepseek/tests/unit_tests/test_chat_models.py at line 20.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free