human.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { BaseMessage, BaseMessageChunk, mergeContent, _mergeDicts, } from "./base.js";
  2. /**
  3. * Represents a human message in a conversation.
  4. */
  5. export class HumanMessage extends BaseMessage {
  6. static lc_name() {
  7. return "HumanMessage";
  8. }
  9. _getType() {
  10. return "human";
  11. }
  12. constructor(fields,
  13. /** @deprecated */
  14. kwargs) {
  15. super(fields, kwargs);
  16. }
  17. }
  18. /**
  19. * Represents a chunk of a human message, which can be concatenated with
  20. * other human message chunks.
  21. */
  22. export class HumanMessageChunk extends BaseMessageChunk {
  23. static lc_name() {
  24. return "HumanMessageChunk";
  25. }
  26. _getType() {
  27. return "human";
  28. }
  29. constructor(fields,
  30. /** @deprecated */
  31. kwargs) {
  32. super(fields, kwargs);
  33. }
  34. concat(chunk) {
  35. return new HumanMessageChunk({
  36. content: mergeContent(this.content, chunk.content),
  37. additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
  38. response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
  39. id: this.id ?? chunk.id,
  40. });
  41. }
  42. }
  43. export function isHumanMessage(x) {
  44. return x.getType() === "human";
  45. }
  46. export function isHumanMessageChunk(x) {
  47. return x.getType() === "human";
  48. }