Message from a human. HumanMessages are messages that are passed in from a human to the model. Example: .. code-block:: python from langchain_core.messages import HumanMessage, SystemMessage messages = [ SystemMessage(
| 4 | |
| 5 | |
| 6 | class HumanMessage(BaseMessage): |
| 7 | """Message from a human. |
| 8 | |
| 9 | HumanMessages are messages that are passed in from a human to the model. |
| 10 | |
| 11 | Example: |
| 12 | |
| 13 | .. code-block:: python |
| 14 | |
| 15 | from langchain_core.messages import HumanMessage, SystemMessage |
| 16 | |
| 17 | messages = [ |
| 18 | SystemMessage( |
| 19 | content="You are a helpful assistant! Your name is Bob." |
| 20 | ), |
| 21 | HumanMessage( |
| 22 | content="What is your name?" |
| 23 | ) |
| 24 | ] |
| 25 | |
| 26 | # Instantiate a chat model and invoke it with the messages |
| 27 | model = ... |
| 28 | print(model.invoke(messages)) |
| 29 | """ |
| 30 | |
| 31 | example: bool = False |
| 32 | """Use to denote that a message is part of an example conversation. |
| 33 | |
| 34 | At the moment, this is ignored by most models. Usage is discouraged. |
| 35 | """ |
| 36 | |
| 37 | type: Literal["human"] = "human" |
| 38 | |
| 39 | @classmethod |
| 40 | def get_lc_namespace(cls) -> List[str]: |
| 41 | """Get the namespace of the langchain object.""" |
| 42 | return ["langchain", "schema", "messages"] |
| 43 | |
| 44 | def __init__( |
| 45 | self, content: Union[str, List[Union[str, Dict]]], **kwargs: Any |
| 46 | ) -> None: |
| 47 | """Pass in content as positional arg.""" |
| 48 | super().__init__(content=content, **kwargs) |
| 49 | |
| 50 | |
| 51 | HumanMessage.update_forward_refs() |
no outgoing calls