@@ -7,20 +7,25 @@ import {
7
7
ChatMessageTool ,
8
8
usePluginStore ,
9
9
} from "@/app/store" ;
10
- import { streamWithThink } from "@/app/utils/chat" ;
10
+ import {
11
+ preProcessImageContentForAlibabaDashScope ,
12
+ streamWithThink ,
13
+ } from "@/app/utils/chat" ;
11
14
import {
12
15
ChatOptions ,
13
16
getHeaders ,
14
17
LLMApi ,
15
18
LLMModel ,
16
19
SpeechOptions ,
17
20
MultimodalContent ,
21
+ MultimodalContentForAlibaba ,
18
22
} from "../api" ;
19
23
import { getClientConfig } from "@/app/config/client" ;
20
24
import {
21
25
getMessageTextContent ,
22
26
getMessageTextContentWithoutThinking ,
23
27
getTimeoutMSByModel ,
28
+ isVisionModel ,
24
29
} from "@/app/utils" ;
25
30
import { fetch } from "@/app/utils/stream" ;
26
31
@@ -89,14 +94,6 @@ export class QwenApi implements LLMApi {
89
94
}
90
95
91
96
async chat ( options : ChatOptions ) {
92
- const messages = options . messages . map ( ( v ) => ( {
93
- role : v . role ,
94
- content :
95
- v . role === "assistant"
96
- ? getMessageTextContentWithoutThinking ( v )
97
- : getMessageTextContent ( v ) ,
98
- } ) ) ;
99
-
100
97
const modelConfig = {
101
98
...useAppConfig . getState ( ) . modelConfig ,
102
99
...useChatStore . getState ( ) . currentSession ( ) . mask . modelConfig ,
@@ -105,6 +102,21 @@ export class QwenApi implements LLMApi {
105
102
} ,
106
103
} ;
107
104
105
+ const visionModel = isVisionModel ( options . config . model ) ;
106
+
107
+ const messages : ChatOptions [ "messages" ] = [ ] ;
108
+ for ( const v of options . messages ) {
109
+ const content = (
110
+ visionModel
111
+ ? await preProcessImageContentForAlibabaDashScope ( v . content )
112
+ : v . role === "assistant"
113
+ ? getMessageTextContentWithoutThinking ( v )
114
+ : getMessageTextContent ( v )
115
+ ) as any ;
116
+
117
+ messages . push ( { role : v . role , content } ) ;
118
+ }
119
+
108
120
const shouldStream = ! ! options . config . stream ;
109
121
const requestPayload : RequestPayload = {
110
122
model : modelConfig . model ,
@@ -129,7 +141,7 @@ export class QwenApi implements LLMApi {
129
141
"X-DashScope-SSE" : shouldStream ? "enable" : "disable" ,
130
142
} ;
131
143
132
- const chatPath = this . path ( Alibaba . ChatPath ) ;
144
+ const chatPath = this . path ( Alibaba . ChatPath ( modelConfig . model ) ) ;
133
145
const chatPayload = {
134
146
method : "POST" ,
135
147
body : JSON . stringify ( requestPayload ) ,
@@ -162,7 +174,7 @@ export class QwenApi implements LLMApi {
162
174
const json = JSON . parse ( text ) ;
163
175
const choices = json . output . choices as Array < {
164
176
message : {
165
- content : string | null ;
177
+ content : string | null | MultimodalContentForAlibaba [ ] ;
166
178
tool_calls : ChatMessageTool [ ] ;
167
179
reasoning_content : string | null ;
168
180
} ;
@@ -212,7 +224,9 @@ export class QwenApi implements LLMApi {
212
224
} else if ( content && content . length > 0 ) {
213
225
return {
214
226
isThinking : false ,
215
- content : content ,
227
+ content : Array . isArray ( content )
228
+ ? content . map ( ( item ) => item . text ) . join ( "," )
229
+ : content ,
216
230
} ;
217
231
}
218
232
0 commit comments