11import { loadEdgeGPTConfig } from "../config" ;
2- import { EdgeGPTConfig } from "../types" ;
3-
2+ import { EdgeGPTConfig , EdgeGPTResponseThrottling } from "../types" ;
3+ import chalk from "chalk" ;
44import prompts , { Choice } from "prompts" ;
55import { ChatBot } from "../ChatBot" ;
66import ora from "ora" ;
@@ -9,6 +9,15 @@ import { marked } from "marked";
99// @ts -expect-error
1010import TerminalRenderer from "marked-terminal" ;
1111
12+ function createOrUpdateSpinnerPrefix ( throttling ?: EdgeGPTResponseThrottling ) {
13+ if ( throttling ) {
14+ return chalk . bold (
15+ `Bing(${ throttling . numUserMessagesInConversation } /${ throttling . maxNumUserMessagesInConversation } ): `
16+ ) ;
17+ }
18+ return chalk . bold ( "Bing: " ) ;
19+ }
20+
1221export const run = async ( options : Partial < EdgeGPTConfig > ) => {
1322 const config = await loadEdgeGPTConfig ( {
1423 cookies : options . cookies ,
@@ -22,6 +31,7 @@ export const run = async (options: Partial<EdgeGPTConfig>) => {
2231 renderer : new TerminalRenderer ( ) ,
2332 } ) ;
2433
34+ let spinnerPrefix = createOrUpdateSpinnerPrefix ( ) ;
2535 while ( true ) {
2636 const cmd = await prompts ( [
2737 {
@@ -52,36 +62,47 @@ export const run = async (options: Partial<EdgeGPTConfig>) => {
5262 } else if ( cmd . prompt . startsWith ( "!options" ) ) {
5363 const [ _c , optstr ] = cmd . prompt . split ( " " ) ;
5464 config . requestOptions = optstr . split ( "," ) . map ( ( v : string ) => v . trim ( ) ) ;
55- console . log ( `Update conversation request options to: ${ config . requestOptions } ` ) ;
65+ console . log (
66+ `Update conversation request options to: ${ config . requestOptions } `
67+ ) ;
5668 continue ;
5769 }
5870 if ( cmd . prompt ) {
5971 if ( ! chatBot . chatHub ) {
6072 await chatBot . reset ( ) ;
6173 }
6274 let response : any ;
63- const spinnerPrefix = "Bing is typing..." ;
75+
6476 const spinner = ora ( spinnerPrefix ) ;
6577 spinner . start ( ) ;
6678 if ( config . stream ) {
6779 response = await chatBot . ask ( cmd . prompt , ( msg ) => {
68- spinner . text = `${ spinnerPrefix } \n ${ marked ( msg ) } ` ;
80+ spinner . text = `${ spinnerPrefix } ${ marked ( msg ?? "" ) } ` ;
6981 } ) ;
7082 spinner . stop ( ) ;
83+ spinnerPrefix = createOrUpdateSpinnerPrefix (
84+ response [ "item" ] [ "throttling" ]
85+ ) ;
7186 console . log (
72- marked (
73- response [ "item" ] ?. [ "messages" ] ?. [ 1 ] ?. [ "adaptiveCards" ] ?. [ 0 ] ?. [
74- "body"
75- ] ?. [ 0 ] ?. [ "text" ] ?. trim ( )
76- )
87+ chalk . green ( "! " ) +
88+ spinnerPrefix +
89+ marked (
90+ response [ "item" ] ?. [ "messages" ] ?. [ 1 ] ?. [ "adaptiveCards" ] ?. [ 0 ] ?. [
91+ "body"
92+ ] ?. [ 0 ] ?. [ "text" ] ?. trim ( ) ?? ""
93+ )
7794 ) ;
7895 } else {
7996 const msg = await chatBot . askAsync ( cmd . prompt , ( res ) => {
8097 spinner . stop ( ) ;
8198 response = res ;
99+ spinnerPrefix = createOrUpdateSpinnerPrefix (
100+ response [ "item" ] [ "throttling" ]
101+ ) ;
82102 } ) ;
83-
84- console . log ( marked ( msg ?. trim ( ) ) ) ;
103+ console . log (
104+ chalk . green ( "? " ) + spinnerPrefix + marked ( msg ?. trim ( ) ?? "" )
105+ ) ;
85106 }
86107 try {
87108 choices = response [ "item" ] [ "messages" ] [ 1 ] [ "suggestedResponses" ]
0 commit comments