A message from a human user.
| 160 | cache: bool = Field(default=False, description="Whether to cache this message. This is only applicable when using Anthropic models.") # type: ignore |
| 161 | |
| 162 | class HumanMessage(Message): |
| 163 | """A message from a human user.""" |
| 164 | role: Literal['user'] = Field(default='user', description="The role of the messages author, in this case `user`.") # type: ignore |
| 165 | content: Union[str, List[Union[ |
| 166 | ContentPartText, |
| 167 | ContentPartImage, |
| 168 | ContentPartAudio, |
| 169 | ContentPartVideo, |
| 170 | ContentPartPdf, |
| 171 | ]]] = Field(description="The contents of the user message.") |
| 172 | name: Optional[str] = Field(default=None, description="An optional name for the participant. Provides the model information to differentiate between participants of the same role.") # type: ignore |
| 173 | |
| 174 | @property |
| 175 | def text(self) -> str: |
| 176 | """ |
| 177 | Automatically parse the text inside content, whether it's a string or a list of content parts. |
| 178 | """ |
| 179 | if isinstance(self.content, str): |
| 180 | return self.content |
| 181 | elif isinstance(self.content, list): |
| 182 | return '\n'.join([str(part) for part in self.content]) |
| 183 | else: |
| 184 | return '' |
| 185 | |
| 186 | def __str__(self) -> str: |
| 187 | return f'HumanMessage(content={self.text})' |
| 188 | |
| 189 | def __repr__(self) -> str: |
| 190 | return f'HumanMessage(content={repr(self.text)})' |
| 191 | |
| 192 | |
| 193 | class SystemMessage(Message): |
no outgoing calls