File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -60,14 +60,14 @@ export class GeminiAdapter extends BaseAdapter {
60
60
topK : 40 ,
61
61
topP : 0.95 ,
62
62
maxOutputTokens : 8192 ,
63
- responseMimeType : "text/plain"
64
63
}
65
64
} ;
66
65
}
67
66
68
67
public getTextGenerationUrl ( _apiUrl : string ) : string {
69
68
const operationName = this . isStreamEnabled ( ) ? 'streamGenerateContent' : 'generateContent' ;
70
- return `${ this . config . baseUrl } /${ this . getModel ( ) } :${ operationName } ` ;
69
+ const baseUrl = `${ this . config . baseUrl } /${ this . getModel ( ) } :${ operationName } ` ;
70
+ return this . isStreamEnabled ( ) ? `${ baseUrl } ?alt=sse` : baseUrl ;
71
71
}
72
72
73
73
public parseResponse ( response : HttpResponse < GeminiResponse | OpenAiChatCompletion > ) : string {
@@ -115,15 +115,23 @@ export class GeminiAdapter extends BaseAdapter {
115
115
targetText : string
116
116
) : string {
117
117
try {
118
- const cleanedText = streamData . text . startsWith ( ',' )
119
- ? streamData . text . slice ( 1 )
120
- : streamData . text ;
118
+ let cleanedText = streamData . text ;
119
+
120
+ // Remove "data: " prefix if present
121
+ if ( cleanedText . startsWith ( 'data: ' ) ) {
122
+ cleanedText = cleanedText . slice ( 5 ) ;
123
+ }
124
+ // Remove leading comma if present
125
+ if ( cleanedText . startsWith ( ',' ) ) {
126
+ cleanedText = cleanedText . slice ( 1 ) ;
127
+ }
121
128
122
129
const parsedChunk = JSON . parse ( cleanedText ) ;
123
130
const text = parsedChunk . candidates ?. [ 0 ] ?. content ?. parts ?. [ 0 ] ?. text ;
124
131
125
132
if ( text ) {
126
133
targetText += text ;
134
+
127
135
query . onStream ( {
128
136
result : {
129
137
from : query . detectFrom ,
You can’t perform that action at this time.
0 commit comments