@@ -70,11 +70,11 @@ export const anthropicStreamCompletion = async (
7070 stream : true ,
7171 system : config . openAi . chatGpt . chatCompletionContext ,
7272 max_tokens : limitTokens ? + config . openAi . chatGpt . maxTokens : undefined ,
73- messages : conversation . filter ( c => c . model === model ) . map ( m => { return { content : m . content , role : m . role } } )
73+ messages : conversation . filter ( c => c . model === model ) // .map(m => { return { content: m.content, role: m.role } })
7474 }
7575 let wordCount = 0
7676 let wordCountMinimum = 2
77- const url = `${ API_ENDPOINT } /anthropic/completions`
77+ const url = `${ API_ENDPOINT } /llms/completions` // `${API_ENDPOINT}/ anthropic/completions`
7878 if ( ! ctx . chat ?. id ) {
7979 throw new Error ( 'Context chat id should not be empty after openAI streaming' )
8080 }
@@ -90,26 +90,17 @@ export const anthropicStreamCompletion = async (
9090 const msg = chunk . toString ( )
9191 if ( msg ) {
9292 if ( msg . includes ( 'Input Token:' ) ) {
93- const regex = / I n p u t T o k e n : ( \d + ) ( .* ) /
94- // Execute the regular expression
95- const match = regex . exec ( msg )
96- if ( match ) {
97- inputTokens = match [ 1 ] . trim ( ) // Extract the integer part
98- if ( match . length >= 3 ) {
99- completion += match [ 2 ]
100- }
101- }
102- } else if ( msg . startsWith ( 'Output Tokens' ) ) {
103- outputTokens = msg . split ( 'Output Tokens: ' ) [ 1 ] . trim ( )
93+ const tokenMsg = msg . split ( 'Input Token: ' ) [ 1 ]
94+ inputTokens = tokenMsg . split ( 'Output Tokens: ' ) [ 0 ]
95+ outputTokens = tokenMsg . split ( 'Output Tokens: ' ) [ 1 ]
96+ completion = completion . split ( 'Input Token: ' ) [ 0 ]
97+ } else if ( msg . includes ( 'Output Tokens: ' ) ) {
98+ outputTokens = msg . split ( 'Output Tokens: ' ) [ 1 ]
99+ completion = completion . split ( 'Output Tokens: ' ) [ 0 ]
104100 } else {
105101 wordCount ++
106102 completion += msg
107- if ( msg . includes ( 'Output Tokens:' ) ) {
108- outputTokens = msg . split ( 'Output Tokens: ' ) [ 1 ] . trim ( )
109- // outputTokens = tokenMsg.split('Output Tokens: ')[1].trim()
110- completion = completion . split ( 'Output Tokens: ' ) [ 0 ]
111- }
112- if ( wordCount > wordCountMinimum ) { // if (chunck === '.' && wordCount > wordCountMinimum) {
103+ if ( wordCount > wordCountMinimum ) {
113104 if ( wordCountMinimum < 64 ) {
114105 wordCountMinimum *= 2
115106 }
@@ -125,7 +116,7 @@ export const anthropicStreamCompletion = async (
125116 if ( e . error_code !== 400 ) {
126117 throw e
127118 } else {
128- logger . error ( e )
119+ logger . error ( e . message )
129120 }
130121 } else {
131122 throw e
0 commit comments