SimpleChatTC: twins wrt streamed response handling
As there could be failure wrt getting the response from the ai server some where in between a long response spread over multiple parts, the logic uses the latestResponse to cache the response as it is being received. However once the full response is got, one needs to transfer it to a new instance of AssistantResponse class, so that latestResponse can be cleared, while the new instance can be used in other locations in the flow as needed. Achieve the same now.
This commit is contained in:
parent
53f85d09be
commit
383c19c99b
|
|
@ -39,8 +39,16 @@ class ApiEP {
|
|||
|
||||
class AssistantResponse {
|
||||
|
||||
constructor() {
|
||||
this.response = { content: "", toolname: "", toolargs: "", trimmedContent: "" };
|
||||
constructor(content="", toolname="", toolargs="", trimmedContent="") {
|
||||
this.response = { content: content, toolname: toolname, toolargs: toolargs, trimmedContent: trimmedContent };
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance from an existing instance
|
||||
* @param {AssistantResponse} old
|
||||
*/
|
||||
static newFrom(old) {
|
||||
return new AssistantResponse(old.response.content, old.response.toolname, old.response.toolargs, old.response.trimmedContent)
|
||||
}
|
||||
|
||||
clear() {
|
||||
|
|
@ -466,7 +474,7 @@ class SimpleChat {
|
|||
}
|
||||
}
|
||||
console.debug("DBUG:SC:PART:Full:", this.latestResponse.content_equiv());
|
||||
return this.latestResponse;
|
||||
return AssistantResponse.newFrom(this.latestResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue