@@ -70,11 +70,11 @@ export const anthropicStreamCompletion = async (
70
70
stream : true ,
71
71
system : config . openAi . chatGpt . chatCompletionContext ,
72
72
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 } })
74
74
}
75
75
let wordCount = 0
76
76
let wordCountMinimum = 2
77
- const url = `${ API_ENDPOINT } /anthropic/completions`
77
+ const url = `${ API_ENDPOINT } /llms/completions` // `${API_ENDPOINT}/ anthropic/completions`
78
78
if ( ! ctx . chat ?. id ) {
79
79
throw new Error ( 'Context chat id should not be empty after openAI streaming' )
80
80
}
@@ -90,26 +90,17 @@ export const anthropicStreamCompletion = async (
90
90
const msg = chunk . toString ( )
91
91
if ( msg ) {
92
92
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 ]
104
100
} else {
105
101
wordCount ++
106
102
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 ) {
113
104
if ( wordCountMinimum < 64 ) {
114
105
wordCountMinimum *= 2
115
106
}
@@ -125,7 +116,7 @@ export const anthropicStreamCompletion = async (
125
116
if ( e . error_code !== 400 ) {
126
117
throw e
127
118
} else {
128
- logger . error ( e )
119
+ logger . error ( e . message )
129
120
}
130
121
} else {
131
122
throw e
0 commit comments