SimpleChatTC: Avoid null content, Fix oversight wrt finish_reason
I was wrongly checking for finish_reason to be non null, before trying to extract the genai content/toolcalls, have fixed this oversight with the new flow in progress. I had added few debug logs to identify the above issue, need to remove them later. Note: given that debug logs are disabled by replacing the debug function during this program's initialisation, which I had forgotten about, I didnt get the debug messages and had to scratch my head a bit, before realising this and the other issue ;) Also either when I had originally implemented simplechat 1+ years back, or later due to changes on the server end, the streaming flow sends a initial null wrt the content, where it only sets the role. This was not handled in my flow on the client side, so a null was getting prepended to the chat messages/responses from the server. This has been fixed now in the new generic flow.
This commit is contained in:
parent
63430dc9f7
commit
e73bc4550b
|
|
@ -155,6 +155,10 @@ class SimpleChat {
|
|||
* @param {{key: string, value: string}} resp
|
||||
*/
|
||||
append_response(resp) {
|
||||
if (resp.value == null) {
|
||||
return
|
||||
}
|
||||
console.debug(resp.key, resp.value)
|
||||
this.latestResponse[resp.key] += resp.value;
|
||||
}
|
||||
|
||||
|
|
@ -311,10 +315,11 @@ class SimpleChat {
|
|||
* @param {string} apiEP
|
||||
*/
|
||||
response_extract_stream(respBody, apiEP) {
|
||||
console.debug(respBody, apiEP)
|
||||
let key = "content"
|
||||
let assistant = "";
|
||||
if (apiEP == ApiEP.Type.Chat) {
|
||||
if (respBody["choices"][0]["finish_reason"] !== null) {
|
||||
if (respBody["choices"][0]["finish_reason"] === null) {
|
||||
if (respBody["choices"][0]["delta"]["content"] !== undefined) {
|
||||
assistant = respBody["choices"][0]["delta"]["content"];
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue