File tree Expand file tree Collapse file tree 2 files changed +6
-5
lines changed
Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -452,10 +452,10 @@ export class ChatPanel {
452452 this . _panel . webview . postMessage ( { command : 'showStopButton' } ) ;
453453
454454 // 转换 _conversation 为 DeepSeek API 所需的消息格式
455- const conversationMessages : string [ ] = [ ] ;
455+ const conversationMessages : { role : string , content : string } [ ] = [ ] ;
456456 for ( let i = 0 ; i < this . _conversation . length ; i ++ ) {
457457 const message = this . _conversation [ i ] ;
458- conversationMessages . push ( message . content ) ; // 仅取出内容
458+ conversationMessages . push ( { role : message . role , ' content' : message . content } ) ; // 仅取出内容
459459 }
460460
461461 const response = await callDeepSeekApi (
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ export function GetLastMessageBody() : OpenAI.ChatCompletionMessageParam[] {
5656 * @returns API 返回的完整内容
5757 */
5858export async function callDeepSeekApi (
59- userContent : string | string [ ] , // 修改为支持 string 或 string[]
59+ userContent : string | { role : string , content : string } [ ] , // 修改为支持 string 或 string[]
6060 systemContent : string = 'You are a helpful assistant.' ,
6161 outputChannel ?: vscode . OutputChannel ,
6262 streamMode : boolean = true ,
@@ -90,10 +90,11 @@ export async function callDeepSeekApi(
9090 // 构造消息体
9191 let messages_body : OpenAI . ChatCompletionMessageParam [ ] = [ ] ;
9292 if ( Array . isArray ( userContent ) ) {
93+ messages_body . push ( { role : 'system' , content : systemContent } ) ;
9394 // 如果 userContent 是数组,按交替方式生成消息
9495 for ( let i = 0 ; i < userContent . length ; i ++ ) {
95- const role = i % 2 === 0 ? 'user' : 'assistant' ;
96- messages_body . push ( { role, content : userContent [ i ] } ) ;
96+ const role = ( userContent [ i ] . role === 'user' ) ? 'user' : 'assistant' ;
97+ messages_body . push ( { role, content : userContent [ i ] . content } ) ;
9798 }
9899 } else {
99100 // 如果是单个字符串,默认是 'user' 角色
You can’t perform that action at this time.
0 commit comments