1
1
import { loadEdgeGPTConfig } from "../config" ;
2
- import { EdgeGPTConfig } from "../types" ;
3
-
2
+ import { EdgeGPTConfig , EdgeGPTResponseThrottling } from "../types" ;
3
+ import chalk from "chalk" ;
4
4
import prompts , { Choice } from "prompts" ;
5
5
import { ChatBot } from "../ChatBot" ;
6
6
import ora from "ora" ;
@@ -9,6 +9,15 @@ import { marked } from "marked";
9
9
// @ts -expect-error
10
10
import TerminalRenderer from "marked-terminal" ;
11
11
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
+
12
21
export const run = async ( options : Partial < EdgeGPTConfig > ) => {
13
22
const config = await loadEdgeGPTConfig ( {
14
23
cookies : options . cookies ,
@@ -22,6 +31,7 @@ export const run = async (options: Partial<EdgeGPTConfig>) => {
22
31
renderer : new TerminalRenderer ( ) ,
23
32
} ) ;
24
33
34
+ let spinnerPrefix = createOrUpdateSpinnerPrefix ( ) ;
25
35
while ( true ) {
26
36
const cmd = await prompts ( [
27
37
{
@@ -52,36 +62,47 @@ export const run = async (options: Partial<EdgeGPTConfig>) => {
52
62
} else if ( cmd . prompt . startsWith ( "!options" ) ) {
53
63
const [ _c , optstr ] = cmd . prompt . split ( " " ) ;
54
64
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
+ ) ;
56
68
continue ;
57
69
}
58
70
if ( cmd . prompt ) {
59
71
if ( ! chatBot . chatHub ) {
60
72
await chatBot . reset ( ) ;
61
73
}
62
74
let response : any ;
63
- const spinnerPrefix = "Bing is typing..." ;
75
+
64
76
const spinner = ora ( spinnerPrefix ) ;
65
77
spinner . start ( ) ;
66
78
if ( config . stream ) {
67
79
response = await chatBot . ask ( cmd . prompt , ( msg ) => {
68
- spinner . text = `${ spinnerPrefix } \n ${ marked ( msg ) } ` ;
80
+ spinner . text = `${ spinnerPrefix } ${ marked ( msg ?? "" ) } ` ;
69
81
} ) ;
70
82
spinner . stop ( ) ;
83
+ spinnerPrefix = createOrUpdateSpinnerPrefix (
84
+ response [ "item" ] [ "throttling" ]
85
+ ) ;
71
86
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
+ )
77
94
) ;
78
95
} else {
79
96
const msg = await chatBot . askAsync ( cmd . prompt , ( res ) => {
80
97
spinner . stop ( ) ;
81
98
response = res ;
99
+ spinnerPrefix = createOrUpdateSpinnerPrefix (
100
+ response [ "item" ] [ "throttling" ]
101
+ ) ;
82
102
} ) ;
83
-
84
- console . log ( marked ( msg ?. trim ( ) ) ) ;
103
+ console . log (
104
+ chalk . green ( "? " ) + spinnerPrefix + marked ( msg ?. trim ( ) ?? "" )
105
+ ) ;
85
106
}
86
107
try {
87
108
choices = response [ "item" ] [ "messages" ] [ 1 ] [ "suggestedResponses" ]
0 commit comments