Merge pull request #206 from Webifi/main
Sticky tool drawer, try to track down streaming responses getting stuck
This commit is contained in:
		
						commit
						d120109924
					
				
							
								
								
									
										10
									
								
								src/app.scss
								
								
								
								
							
							
						
						
									
										10
									
								
								src/app.scss
								
								
								
								
							| 
						 | 
					@ -537,6 +537,12 @@ aside.menu.main-menu .menu-expanse {
 | 
				
			||||||
  min-width: 60px;
 | 
					  min-width: 60px;
 | 
				
			||||||
  min-height: 1.3em;
 | 
					  min-height: 1.3em;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					.button-pack {
 | 
				
			||||||
 | 
					  display: block;
 | 
				
			||||||
 | 
					  position: sticky;
 | 
				
			||||||
 | 
					  top: calc(var(--sectionPaddingTop) + 10px);
 | 
				
			||||||
 | 
					  padding-bottom: 0.1px;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
.button-pack .button {
 | 
					.button-pack .button {
 | 
				
			||||||
  display: block;
 | 
					  display: block;
 | 
				
			||||||
  margin: 4px;
 | 
					  margin: 4px;
 | 
				
			||||||
| 
						 | 
					@ -597,23 +603,27 @@ aside.menu.main-menu .menu-expanse {
 | 
				
			||||||
  width: var(--chatToolDrawerSize);
 | 
					  width: var(--chatToolDrawerSize);
 | 
				
			||||||
  visibility: visible;
 | 
					  visibility: visible;
 | 
				
			||||||
  max-height: 300%;
 | 
					  max-height: 300%;
 | 
				
			||||||
 | 
					  overflow: unset;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.user-message:hover .tool-drawer,
 | 
					.user-message:hover .tool-drawer,
 | 
				
			||||||
.user-message.editing .tool-drawer {
 | 
					.user-message.editing .tool-drawer {
 | 
				
			||||||
  width: var(--chatToolDrawerSize);
 | 
					  width: var(--chatToolDrawerSize);
 | 
				
			||||||
  visibility: visible;
 | 
					  visibility: visible;
 | 
				
			||||||
  max-height: 300%;
 | 
					  max-height: 300%;
 | 
				
			||||||
 | 
					  overflow: unset;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.assistant-message:hover .tool-drawer-mask,
 | 
					.assistant-message:hover .tool-drawer-mask,
 | 
				
			||||||
.assistant-message.editing .tool-drawer {
 | 
					.assistant-message.editing .tool-drawer {
 | 
				
			||||||
  width: var(--chatToolDrawerSize);
 | 
					  width: var(--chatToolDrawerSize);
 | 
				
			||||||
  visibility: visible;
 | 
					  visibility: visible;
 | 
				
			||||||
 | 
					  overflow: unset;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.user-message:hover .tool-drawer-mask,
 | 
					.user-message:hover .tool-drawer-mask,
 | 
				
			||||||
.user-message.editing .tool-drawer {
 | 
					.user-message.editing .tool-drawer {
 | 
				
			||||||
  width: var(--chatToolDrawerSize);
 | 
					  width: var(--chatToolDrawerSize);
 | 
				
			||||||
  visibility: visible;
 | 
					  visibility: visible;
 | 
				
			||||||
 | 
					  overflow: unset;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.assistant-message:hover, .assistant-message.editing {
 | 
					.assistant-message:hover, .assistant-message.editing {
 | 
				
			||||||
  border-top-right-radius: 0px !important;
 | 
					  border-top-right-radius: 0px !important;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -104,9 +104,9 @@ export class ChatCompletionResponse {
 | 
				
			||||||
          completion_tokens: 0,
 | 
					          completion_tokens: 0,
 | 
				
			||||||
          total_tokens: 0
 | 
					          total_tokens: 0
 | 
				
			||||||
        } as Usage
 | 
					        } as Usage
 | 
				
			||||||
        message.usage.completion_tokens += response.usage.completion_tokens
 | 
					        message.usage.completion_tokens += response?.usage?.completion_tokens || 0
 | 
				
			||||||
        message.usage.prompt_tokens = response.usage.prompt_tokens + (this.offsetTotals?.prompt_tokens || 0)
 | 
					        message.usage.prompt_tokens = (response?.usage?.prompt_tokens || 0) + (this.offsetTotals?.prompt_tokens || 0)
 | 
				
			||||||
        message.usage.total_tokens = response.usage.total_tokens + (this.offsetTotals?.total_tokens || 0)
 | 
					        message.usage.total_tokens = (response?.usage?.total_tokens || 0) + (this.offsetTotals?.total_tokens || 0)
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        message.content = choice.message.content
 | 
					        message.content = choice.message.content
 | 
				
			||||||
        message.usage = response.usage
 | 
					        message.usage = response.usage
 | 
				
			||||||
| 
						 | 
					@ -124,7 +124,7 @@ export class ChatCompletionResponse {
 | 
				
			||||||
  updateFromAsyncResponse (response: Response) {
 | 
					  updateFromAsyncResponse (response: Response) {
 | 
				
			||||||
    let completionTokenCount = 0
 | 
					    let completionTokenCount = 0
 | 
				
			||||||
    this.setModel(response.model)
 | 
					    this.setModel(response.model)
 | 
				
			||||||
    if (!response.choices) {
 | 
					    if (!response.choices || response?.error) {
 | 
				
			||||||
      return this.updateFromError(response?.error?.message || 'unexpected streaming response from API')
 | 
					      return this.updateFromError(response?.error?.message || 'unexpected streaming response from API')
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    response.choices?.forEach((choice, i) => {
 | 
					    response.choices?.forEach((choice, i) => {
 | 
				
			||||||
| 
						 | 
					@ -174,7 +174,11 @@ export class ChatCompletionResponse {
 | 
				
			||||||
    setTimeout(() => this.finish(), 250) // give others a chance to signal the finish first
 | 
					    setTimeout(() => this.finish(), 250) // give others a chance to signal the finish first
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  updateFromClose (): void {
 | 
					  updateFromClose (force: boolean = false): void {
 | 
				
			||||||
 | 
					    if (!this.finished && !this.error && !this.messages?.find(m => m.content)) {
 | 
				
			||||||
 | 
					      if (!force) return setTimeout(() => this.updateFromClose(true), 250) as any
 | 
				
			||||||
 | 
					      return this.updateFromError('Unexpected connection termination')
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    setTimeout(() => this.finish(), 250) // give others a chance to signal the finish first
 | 
					    setTimeout(() => this.finish(), 250) // give others a chance to signal the finish first
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -202,6 +202,8 @@ export class ChatRequest {
 | 
				
			||||||
          _this.controller = new AbortController()
 | 
					          _this.controller = new AbortController()
 | 
				
			||||||
          const signal = _this.controller.signal
 | 
					          const signal = _this.controller.signal
 | 
				
			||||||
          const abortListener = (e:Event) => {
 | 
					          const abortListener = (e:Event) => {
 | 
				
			||||||
 | 
					            _this.updating = false
 | 
				
			||||||
 | 
					            _this.updatingMessage = ''
 | 
				
			||||||
            chatResponse.updateFromError('User aborted request.')
 | 
					            chatResponse.updateFromError('User aborted request.')
 | 
				
			||||||
            signal.removeEventListener('abort', abortListener)
 | 
					            signal.removeEventListener('abort', abortListener)
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
| 
						 | 
					@ -245,6 +247,8 @@ export class ChatRequest {
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              onclose () {
 | 
					              onclose () {
 | 
				
			||||||
 | 
					                _this.updating = false
 | 
				
			||||||
 | 
					                _this.updatingMessage = ''
 | 
				
			||||||
                chatResponse.updateFromClose()
 | 
					                chatResponse.updateFromClose()
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              onerror (err) {
 | 
					              onerror (err) {
 | 
				
			||||||
| 
						 | 
					@ -260,6 +264,8 @@ export class ChatRequest {
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            }).catch(err => {
 | 
					            }).catch(err => {
 | 
				
			||||||
 | 
					              _this.updating = false
 | 
				
			||||||
 | 
					              _this.updatingMessage = ''
 | 
				
			||||||
              chatResponse.updateFromError(err.message)
 | 
					              chatResponse.updateFromError(err.message)
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -200,9 +200,9 @@
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      chat.usage[model] = total
 | 
					      chat.usage[model] = total
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    total.completion_tokens += usage.completion_tokens
 | 
					    total.completion_tokens += usage?.completion_tokens || 0
 | 
				
			||||||
    total.prompt_tokens += usage.prompt_tokens
 | 
					    total.prompt_tokens += usage?.prompt_tokens || 0
 | 
				
			||||||
    total.total_tokens += usage.total_tokens
 | 
					    total.total_tokens += usage?.total_tokens || 0
 | 
				
			||||||
    chatsStorage.set(chats)
 | 
					    chatsStorage.set(chats)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -218,9 +218,9 @@
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      chat.usage[model] = total
 | 
					      chat.usage[model] = total
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    total.completion_tokens -= usage.completion_tokens
 | 
					    total.completion_tokens -= usage?.completion_tokens || 0
 | 
				
			||||||
    total.prompt_tokens -= usage.prompt_tokens
 | 
					    total.prompt_tokens -= usage?.prompt_tokens || 0
 | 
				
			||||||
    total.total_tokens -= usage.total_tokens
 | 
					    total.total_tokens -= usage?.total_tokens || 0
 | 
				
			||||||
    chatsStorage.set(chats)
 | 
					    chatsStorage.set(chats)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue