54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
export const RUN_KEY = "__run";
|
|
/**
|
|
* Chunk of a single generation. Used for streaming.
|
|
*/
|
|
export class GenerationChunk {
|
|
constructor(fields) {
|
|
Object.defineProperty(this, "text", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
Object.defineProperty(this, "generationInfo", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
this.text = fields.text;
|
|
this.generationInfo = fields.generationInfo;
|
|
}
|
|
concat(chunk) {
|
|
return new GenerationChunk({
|
|
text: this.text + chunk.text,
|
|
generationInfo: {
|
|
...this.generationInfo,
|
|
...chunk.generationInfo,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
export class ChatGenerationChunk extends GenerationChunk {
|
|
constructor(fields) {
|
|
super(fields);
|
|
Object.defineProperty(this, "message", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
this.message = fields.message;
|
|
}
|
|
concat(chunk) {
|
|
return new ChatGenerationChunk({
|
|
text: this.text + chunk.text,
|
|
generationInfo: {
|
|
...this.generationInfo,
|
|
...chunk.generationInfo,
|
|
},
|
|
message: this.message.concat(chunk.message),
|
|
});
|
|
}
|
|
}
|