@@ -47,7 +47,7 @@ export function GetLastMessageBody() : OpenAI.ChatCompletionMessageParam[] {
4747
4848/**
4949 * 调用 DeepSeek API
50- * @param userContent 用户输入内容
50+ * @param userContent 用户输入内容,可以是字符串或字符串数组
5151 * @param systemContent 系统提示内容
5252 * @param outputChannel 输出通道,用于实时显示流式内容
5353 * @param streamMode 是否启用流式模式
@@ -56,7 +56,7 @@ export function GetLastMessageBody() : OpenAI.ChatCompletionMessageParam[] {
5656 * @returns API 返回的完整内容
5757 */
5858export async function callDeepSeekApi (
59- userContent : string ,
59+ userContent : string | string [ ] , // 修改为支持 string 或 string[]
6060 systemContent : string = 'You are a helpful assistant.' ,
6161 outputChannel ?: vscode . OutputChannel ,
6262 streamMode : boolean = true ,
@@ -87,15 +87,26 @@ export async function callDeepSeekApi(
8787 outputChannel . show ( ) ;
8888 }
8989
90- const messages_body : OpenAI . ChatCompletionMessageParam [ ] = [
91- { role : 'system' , content : systemContent } ,
92- { role : 'user' , content : userContent } ,
93- ] ;
90+ // 构造消息体
91+ let messages_body : OpenAI . ChatCompletionMessageParam [ ] = [ ] ;
92+ if ( Array . isArray ( userContent ) ) {
93+ // 如果 userContent 是数组,按交替方式生成消息
94+ for ( let i = 0 ; i < userContent . length ; i ++ ) {
95+ const role = i % 2 === 0 ? 'user' : 'assistant' ;
96+ messages_body . push ( { role, content : userContent [ i ] } ) ;
97+ }
98+ } else {
99+ // 如果是单个字符串,默认是 'user' 角色
100+ messages_body = [
101+ { role : 'system' , content : systemContent } ,
102+ { role : 'user' , content : userContent } ,
103+ ] ;
104+ }
105+
94106 let fullResponse = '' ;
95107 let maxAttempts = 5 ;
96108 let attempts = 0 ;
97109
98-
99110 vscode . window . showInformationMessage ( '开始上传DeepSeek API' ) ;
100111
101112 while ( attempts < maxAttempts ) {
0 commit comments