outputs.cjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ChatGenerationChunk = exports.GenerationChunk = exports.RUN_KEY = void 0;
  4. exports.RUN_KEY = "__run";
  5. /**
  6. * Chunk of a single generation. Used for streaming.
  7. */
  8. class GenerationChunk {
  9. constructor(fields) {
  10. Object.defineProperty(this, "text", {
  11. enumerable: true,
  12. configurable: true,
  13. writable: true,
  14. value: void 0
  15. });
  16. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  17. Object.defineProperty(this, "generationInfo", {
  18. enumerable: true,
  19. configurable: true,
  20. writable: true,
  21. value: void 0
  22. });
  23. this.text = fields.text;
  24. this.generationInfo = fields.generationInfo;
  25. }
  26. concat(chunk) {
  27. return new GenerationChunk({
  28. text: this.text + chunk.text,
  29. generationInfo: {
  30. ...this.generationInfo,
  31. ...chunk.generationInfo,
  32. },
  33. });
  34. }
  35. }
  36. exports.GenerationChunk = GenerationChunk;
  37. class ChatGenerationChunk extends GenerationChunk {
  38. constructor(fields) {
  39. super(fields);
  40. Object.defineProperty(this, "message", {
  41. enumerable: true,
  42. configurable: true,
  43. writable: true,
  44. value: void 0
  45. });
  46. this.message = fields.message;
  47. }
  48. concat(chunk) {
  49. return new ChatGenerationChunk({
  50. text: this.text + chunk.text,
  51. generationInfo: {
  52. ...this.generationInfo,
  53. ...chunk.generationInfo,
  54. },
  55. message: this.message.concat(chunk.message),
  56. });
  57. }
  58. }
  59. exports.ChatGenerationChunk = ChatGenerationChunk;