Home / Function/ _get_joke_class() — langchain Function Reference

_get_joke_class() — langchain Function Reference

Architecture documentation for the _get_joke_class() function in test_chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  84987bc6_51d3_8515_89bb_a48a2a072b5b["_get_joke_class()"]
  ec975712_a998_0a1f_0930_22940fc39a1e["test_chat_models.py"]
  84987bc6_51d3_8515_89bb_a48a2a072b5b -->|defined in| ec975712_a998_0a1f_0930_22940fc39a1e
  62b43087_25ff_6b52_6afb_c79c5d38e699["test_structured_output_json_schema()"]
  62b43087_25ff_6b52_6afb_c79c5d38e699 -->|calls| 84987bc6_51d3_8515_89bb_a48a2a072b5b
  style 84987bc6_51d3_8515_89bb_a48a2a072b5b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/fireworks/tests/integration_tests/test_chat_models.py lines 125–155

def _get_joke_class(
    schema_type: Literal["pydantic", "typeddict", "json_schema"],
) -> Any:
    class Joke(BaseModel):
        """Joke to tell user."""

        setup: str = Field(description="question to set up a joke")
        punchline: str = Field(description="answer to resolve the joke")

    def validate_joke(result: Any) -> bool:
        return isinstance(result, Joke)

    class JokeDict(TypedDict):
        """Joke to tell user."""

        setup: Annotated[str, ..., "question to set up a joke"]
        punchline: Annotated[str, ..., "answer to resolve the joke"]

    def validate_joke_dict(result: Any) -> bool:
        return all(key in ["setup", "punchline"] for key in result)

    if schema_type == "pydantic":
        return Joke, validate_joke

    if schema_type == "typeddict":
        return JokeDict, validate_joke_dict

    if schema_type == "json_schema":
        return Joke.model_json_schema(), validate_joke_dict
    msg = "Invalid schema type"
    raise ValueError(msg)

Domain

Subdomains

Frequently Asked Questions

What does _get_joke_class() do?
_get_joke_class() is a function in the langchain codebase, defined in libs/partners/fireworks/tests/integration_tests/test_chat_models.py.
Where is _get_joke_class() defined?
_get_joke_class() is defined in libs/partners/fireworks/tests/integration_tests/test_chat_models.py at line 125.
What calls _get_joke_class()?
_get_joke_class() is called by 1 function(s): test_structured_output_json_schema.

Analyze Your Own Codebase

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

Try Supermodel Free