@@ -49,11 +49,12 @@ export const CustomOpenAIProvider = {
4949 try {
5050 const { getCustomAPIInfo } = await import ( "#root/src/api/providers_custom.js" ) ;
5151 apiData = await getCustomAPIInfo ( url ) ;
52+ this . info . type = this . info . type ?? apiData . type ;
5253 // eslint-disable-next-line no-empty
5354 } catch { }
5455
5556 // Initialize
56- const api_url = getChatCompletionsURL ( url , this . info ?. type ?? apiData . type ) ;
57+ const api_url = getChatCompletionsURL ( url , this . info ?. type ) ;
5758
5859 apiKey = apiKey || apiData . apiKey ;
5960 // The order for applying configs: reqBody -> apiData.config -> reqConfig
@@ -103,8 +104,7 @@ export const CustomOpenAIProvider = {
103104
104105 try {
105106 let json = JSON . parse ( line ) ;
106- let chunk = json [ "choices" ] [ 0 ] [ "delta" ] ?? json [ "choices" ] [ 0 ] [ "message" ] ;
107- chunk = chunk ?. content ;
107+ let chunk = this . getChunk ( json ) ;
108108 if ( chunk ) {
109109 yield chunk ;
110110 }
@@ -114,4 +114,32 @@ export const CustomOpenAIProvider = {
114114 }
115115 }
116116 } ,
117+ getChunk : function ( json ) {
118+ switch ( this . info ?. type ) {
119+ case "Anthropic" : {
120+ let chunk = "" ;
121+ if ( json [ "delta" ] [ "thinking" ] ) {
122+ if ( ! this . isThinking ) {
123+ this . isThinking = true ;
124+ chunk += "\n<thinking>\n" ;
125+ }
126+ chunk += json [ "delta" ] [ "thinking" ] ;
127+ }
128+ if ( json [ "delta" ] [ "text" ] ) {
129+ if ( this . isThinking ) {
130+ this . isThinking = false ;
131+ chunk += "\n</thinking>\n" ;
132+ }
133+ chunk += json [ "delta" ] [ "text" ] ;
134+ }
135+ return chunk ;
136+ }
137+ case "OpenAI" :
138+ default : {
139+ let chunk = json [ "choices" ] [ 0 ] [ "delta" ] ?? json [ "choices" ] [ 0 ] [ "message" ] ;
140+ chunk = chunk ?. content ;
141+ return chunk ;
142+ }
143+ }
144+ } ,
117145} ;
0 commit comments