diff --git a/dspy/adapters/chat_adapter.py b/dspy/adapters/chat_adapter.py index 3242e95be..6683a0b9a 100644 --- a/dspy/adapters/chat_adapter.py +++ b/dspy/adapters/chat_adapter.py @@ -177,7 +177,22 @@ def parse_value(value, annotation): return TypeAdapter(annotation).validate_python(parsed_value) -def format_turn(signature: SignatureMeta, values: Dict[str, Any], role, incomplete=False): +def format_turn(signature: SignatureMeta, values: Dict[str, Any], role, incomplete=False) -> Dict[str, str]: + """ + Constructs a new message ("turn") to append to a chat thread. The message is carefully formatted + so that it can instruct an LLM to generate responses conforming to the specified DSPy signature. + + Args: + signature: The DSPy signature to which future LLM responses should conform. + values: A dictionary of field names (from the DSPy signature) to corresponding values that + should be included in the message. + role: The role of the message, which can be either "user" or "assistant". + incomplete: If True, indicates that output field values are present in the set of specified + ``values``. If False, indicates that ``values`` only contains input field values. + Returns: + A chat message that can be appended to a chat thread. The message contains two string fields: + ``role`` ("user" or "assistant") and ``content`` (containing the message itself). + """ content = [] if role == "user":