File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed
Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ const newChatStore = (
4444 postBeginIndex : 0 ,
4545 tokenMargin : 1024 ,
4646 totalTokens : 0 ,
47- maxTokens : models [ getDefaultParams ( "model" , model ) ] . maxToken ,
47+ maxTokens : models [ getDefaultParams ( "model" , model ) ] ? .maxToken ?? 4096 ,
4848 apiKey : getDefaultParams ( "key" , apiKey ) ,
4949 apiEndpoint : getDefaultParams ( "api" , apiEndpoint ) ,
5050 streamMode : getDefaultParams ( "mode" , streamMode ) ,
Original file line number Diff line number Diff line change @@ -87,15 +87,16 @@ export default function ChatBOX(props: {
8787 // estimate cost
8888 if ( chatStore . responseModelName ) {
8989 chatStore . cost +=
90- token * models [ chatStore . responseModelName ] . price . completion ;
90+ token *
91+ ( models [ chatStore . responseModelName ] ?. price ?. completion ?? 0 ) ;
9192 let sum = 0 ;
9293 for ( const msg of chatStore . history
9394 . filter ( ( { hide } ) => ! hide )
9495 . slice ( chatStore . postBeginIndex ) ) {
9596 sum += msg . token ;
9697 }
9798 chatStore . cost +=
98- sum * models [ chatStore . responseModelName ] . price . prompt ;
99+ sum * ( models [ chatStore . responseModelName ] ? .price ? .prompt ?? 0 ) ;
99100 }
100101 chatStore . history . push ( {
101102 role : "assistant" ,
@@ -119,10 +120,11 @@ export default function ChatBOX(props: {
119120 chatStore . responseModelName = data . model ?? "" ;
120121 if ( data . model ) {
121122 chatStore . cost +=
122- ( data . usage . prompt_tokens ?? 0 ) * models [ data . model ] . price . prompt ;
123+ ( data . usage . prompt_tokens ?? 0 ) *
124+ ( models [ data . model ] ?. price ?. prompt ?? 0 ) ;
123125 chatStore . cost +=
124126 ( data . usage . completion_tokens ?? 0 ) *
125- models [ data . model ] . price . completion ;
127+ ( models [ data . model ] ? .price ? .completion ?? 0 ) ;
126128 }
127129 const content = client . processFetchResponse ( data ) ;
128130 chatStore . history . push ( {
You can’t perform that action at this time.
0 commit comments