Defines data models for LLM responses, including streaming chunks and outcome tracking, for use in LLM integration.
# Source: https://github.com/HKUDS/DeepTutor | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""Shared LLM response data models."""
from collections.abc import AsyncGenerator
from dataclasses import dataclass, field
import logging
from pydantic import BaseModel, Field
logger = logging.getLogger(__name__)
#: Terminal reasons that mean "the provider stopped because output hit a cap",
#: i.e. the response is incomplete rather than finished. One table: the agent
#: loop, the research pipeline and the streaming callers all read this.
TRUNCATED_FINISH_REASONS = frozenset({"length", "max_tokens", "max_output_tokens"})
def finish_was_truncated(reason: str | None) -> bool:
"""Retu
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key