@@ -33,31 +33,7 @@ const process_stream_chunk = (
3333 if ( ! json_string || json_string == DONE_TOKEN ) continue
3434
3535 const json_data = JSON . parse ( json_string )
36- let content = json_data . choices ?. [ 0 ] ?. delta ?. content
37-
38- // Special handling for ChatGPT provider
39- if ( content === undefined && json_data . type ) {
40- if (
41- [
42- 'response.text.delta' ,
43- 'response.output_text.delta' ,
44- 'response.reasoning.delta' ,
45- 'response.reasoning_text.delta'
46- ] . includes ( json_data . type )
47- ) {
48- content = json_data . delta
49- } else if ( json_data . type === 'response.content_part.added' ) {
50- content =
51- typeof json_data . part ?. text === 'string'
52- ? json_data . part . text
53- : json_data . part ?. text ?. value
54- } else if (
55- json_data . type === 'response.output_item.added' &&
56- json_data . item ?. type === 'text'
57- ) {
58- content = json_data . item ?. text
59- }
60- }
36+ const content = json_data . choices ?. [ 0 ] ?. delta ?. content
6137
6238 if ( typeof content == 'string' ) {
6339 new_content += content
@@ -139,75 +115,8 @@ export const make_api_request = async (params: {
139115 }
140116
141117 try {
142- const is_chatgpt = params . endpoint_url . includes ( 'chatgpt.com/backend-api' )
143- const request_url = is_chatgpt
144- ? params . endpoint_url + '/responses'
145- : params . endpoint_url + '/chat/completions'
146-
147- let request_body : any = { ...params . body , stream : true }
148-
149- if ( is_chatgpt ) {
150- const system_message = params . body . messages ?. find (
151- ( m : any ) => m . role === 'system'
152- )
153- const other_messages =
154- params . body . messages ?. filter ( ( m : any ) => m . role !== 'system' ) || [ ]
155-
156- const formatted_input = other_messages . map ( ( m : any ) => {
157- if ( m . role == 'user' ) {
158- const content = [ ]
159- if ( typeof m . content == 'string' ) {
160- content . push ( { type : 'input_text' , text : m . content } )
161- } else if ( Array . isArray ( m . content ) ) {
162- for ( const block of m . content ) {
163- if ( block . type == 'text' ) {
164- content . push ( { type : 'input_text' , text : block . text } )
165- } else if ( block . type == 'image_url' ) {
166- content . push ( {
167- type : 'input_image' ,
168- image_url : block . image_url . url
169- } )
170- }
171- }
172- }
173- return { role : 'user' , content }
174- } else if ( m . role == 'assistant' ) {
175- const content = [ ]
176- if ( typeof m . content == 'string' ) {
177- content . push ( { type : 'output_text' , text : m . content } )
178- } else if ( Array . isArray ( m . content ) ) {
179- for ( const block of m . content ) {
180- if ( block . type == 'text' ) {
181- content . push ( { type : 'output_text' , text : block . text } )
182- }
183- }
184- }
185- return { role : 'assistant' , content }
186- }
187- return m
188- } )
189-
190- request_body = {
191- model : params . body . model ,
192- input : formatted_input ,
193- stream : true ,
194- store : false
195- }
196- if ( system_message ) {
197- request_body . instructions = system_message . content
198- } else {
199- request_body . instructions = ''
200- }
201- if ( params . body . temperature !== undefined ) {
202- request_body . temperature = params . body . temperature
203- }
204- if ( params . body . reasoning_effort ) {
205- request_body . reasoning = {
206- effort : params . body . reasoning_effort ,
207- summary : 'auto'
208- }
209- }
210- }
118+ const request_url = params . endpoint_url + '/chat/completions'
119+ const request_body : any = { ...params . body , stream : true }
211120
212121 Logger . info ( {
213122 function_name : 'make_api_request' ,
@@ -339,10 +248,6 @@ export const make_api_request = async (params: {
339248 : { } )
340249 }
341250
342- if ( is_chatgpt ) {
343- headers [ 'originator' ] = 'code-web-chat'
344- }
345-
346251 const response : AxiosResponse < NodeJS . ReadableStream > = await axios . post (
347252 request_url ,
348253 request_body ,
@@ -388,31 +293,7 @@ export const make_api_request = async (params: {
388293 const json_string = trimmed_line . slice ( DATA_PREFIX . length ) . trim ( )
389294 if ( json_string && json_string !== DONE_TOKEN ) {
390295 const json_data = JSON . parse ( json_string )
391- let content = json_data . choices ?. [ 0 ] ?. delta ?. content
392-
393- // Special handling for ChatGPT provider
394- if ( content === undefined && json_data . type ) {
395- if (
396- [
397- 'response.text.delta' ,
398- 'response.output_text.delta' ,
399- 'response.reasoning.delta' ,
400- 'response.reasoning_text.delta'
401- ] . includes ( json_data . type )
402- ) {
403- content = json_data . delta
404- } else if ( json_data . type === 'response.content_part.added' ) {
405- content =
406- typeof json_data . part ?. text === 'string'
407- ? json_data . part . text
408- : json_data . part ?. text ?. value
409- } else if (
410- json_data . type === 'response.output_item.added' &&
411- json_data . item ?. type === 'text'
412- ) {
413- content = json_data . item ?. text
414- }
415- }
296+ const content = json_data . choices ?. [ 0 ] ?. delta ?. content
416297
417298 if ( typeof content == 'string' ) {
418299 process_content ( content )
0 commit comments