@plteam/chat-ui
Version:
CUI Kit is a free and open-source library for creating AI assistant chat interfaces, built with React, Material UI, and TypeScript
67 lines (66 loc) • 2.41 kB
JavaScript
import { ObservableReactValue } from '../utils/observers';
export var ReasoningViewType;
(function (ReasoningViewType) {
// The text is not divided into segments. it's a continuous stream of thought
ReasoningViewType["STREAM"] = "stream";
// The text is divided into segments (headings), similar to ChatGPT.
ReasoningViewType["SHORT_BLOCKS"] = "shortBlocks";
ReasoningViewType["HEADERS_STREAM"] = "headersStream";
})(ReasoningViewType || (ReasoningViewType = {}));
export class MessageReasoningModel {
_reasoningTimeStart = 0;
title = new ObservableReactValue('');
text = new ObservableReactValue('');
timeSec = new ObservableReactValue(0);
viewType = new ObservableReactValue(ReasoningViewType.HEADERS_STREAM);
lockedOptions = [];
setUserHeader = (value) => {
if (!this.lockedOptions.includes('headers')) {
this.lockedOptions.push('headers');
this.setUserViewType('stream');
}
this.title.value = value;
};
setUserTimeSec = (value) => {
if (!this.lockedOptions.includes('time')) {
this.lockedOptions.push('time');
}
this.timeSec.value = Math.round(value);
};
setUserViewType = (value) => {
if (!this.lockedOptions.includes('viewType')) {
this.lockedOptions.push('viewType');
}
if (this.viewType.value !== value) {
this.viewType.value = value;
}
};
unlockAutoManagment = (values) => {
if (values) {
this.lockedOptions = this.lockedOptions.filter(v => !values.includes(v));
}
else {
this.lockedOptions = [];
}
};
setHeader = (value) => {
if (!this.lockedOptions.includes('headers')) {
this.title.value = value;
}
};
pushChunk = (chunk) => {
if (!this._reasoningTimeStart)
this._reasoningTimeStart = performance.now();
this.text.value += chunk;
};
setText = (reasoning) => {
this.text.value = reasoning;
};
updateTimeSec = () => {
if (!this.lockedOptions.includes('time')) {
if (this._reasoningTimeStart && !this.timeSec.value) {
this.timeSec.value = Math.round((performance.now() - this._reasoningTimeStart) / 1000);
}
}
};
}