@@ -45,46 +45,53 @@ export const postCreateResponse = async (
45
45
46
46
if ( Array . isArray ( req . body . input ) ) {
47
47
messages . push (
48
- ...req . body . input . map ( ( item ) => ( {
49
- role : item . role ,
50
- content :
51
- typeof item . content === "string"
52
- ? item . content
53
- : item . content
54
- . map ( ( content ) => {
55
- switch ( content . type ) {
56
- case "input_image" :
57
- return {
58
- type : "image_url" as ChatCompletionInputMessageChunkType ,
59
- image_url : {
60
- url : content . image_url ,
61
- } ,
62
- } ;
63
- case "output_text" :
64
- return {
65
- type : "text" as ChatCompletionInputMessageChunkType ,
66
- text : content . text ,
67
- } ;
68
- case "refusal" :
69
- return undefined ;
70
- case "input_text" :
71
- return {
72
- type : "text" as ChatCompletionInputMessageChunkType ,
73
- text : content . text ,
74
- } ;
75
- }
76
- } )
77
- . filter ( ( item ) => item !== undefined ) ,
78
- } ) )
48
+ ...req . body . input
49
+ . map ( ( item ) => ( {
50
+ role : item . role ,
51
+ content :
52
+ typeof item . content === "string"
53
+ ? item . content
54
+ : item . content
55
+ . map ( ( content ) => {
56
+ switch ( content . type ) {
57
+ case "input_image" :
58
+ return {
59
+ type : "image_url" as ChatCompletionInputMessageChunkType ,
60
+ image_url : {
61
+ url : content . image_url ,
62
+ } ,
63
+ } ;
64
+ case "output_text" :
65
+ return content . text
66
+ ? {
67
+ type : "text" as ChatCompletionInputMessageChunkType ,
68
+ text : content . text ,
69
+ }
70
+ : undefined ;
71
+ case "refusal" :
72
+ return undefined ;
73
+ case "input_text" :
74
+ return {
75
+ type : "text" as ChatCompletionInputMessageChunkType ,
76
+ text : content . text ,
77
+ } ;
78
+ }
79
+ } )
80
+ . filter ( ( item ) => item !== undefined ) ,
81
+ } ) )
82
+ . filter ( ( message ) => message . content ?. length !== 0 )
79
83
) ;
80
84
} else {
81
85
messages . push ( { role : "user" , content : req . body . input } ) ;
82
86
}
83
87
88
+ const model = req . body . model . includes ( "@" ) ? req . body . model . split ( "@" ) [ 1 ] : req . body . model ;
89
+ const provider = req . body . model . includes ( "@" ) ? req . body . model . split ( "@" ) [ 0 ] : undefined ;
90
+
84
91
const payload : ChatCompletionInput = {
85
92
// main params
86
- model : req . body . model ,
87
- provider : req . body . provider ,
93
+ model : model ,
94
+ provider : provider ,
88
95
messages : messages ,
89
96
stream : req . body . stream ,
90
97
// options
@@ -239,7 +246,7 @@ export const postCreateResponse = async (
239
246
delta : chunk . choices [ 0 ] . delta . content ,
240
247
sequence_number : sequenceNumber ++ ,
241
248
} ) ;
242
- } else if ( chunk . choices [ 0 ] . delta . tool_calls ) {
249
+ } else if ( chunk . choices [ 0 ] . delta . tool_calls && chunk . choices [ 0 ] . delta . tool_calls . length > 0 ) {
243
250
if ( chunk . choices [ 0 ] . delta . tool_calls . length > 1 ) {
244
251
throw new StreamingError ( "Not implemented: only single tool call is supported in streaming mode." ) ;
245
252
}
0 commit comments