@@ -2,45 +2,37 @@ import OpenAI from 'openai';
22import * as vscode from 'vscode' ;
33import { Cvb , TCVB } from './cvbManager' ;
44
5- /**
6- * 获取 DeepSeek API Key
7- * @returns DeepSeek API Key
8- */
9- function getDeepSeekApiKey ( ) : string | null {
10- const apiKey = vscode . workspace . getConfiguration ( 'codeReDesign' ) . get < string > ( 'deepSeekApiKey' ) ;
11- if ( ! apiKey ) {
12- vscode . window . showErrorMessage ( 'DeepSeek API Key is not configured. Please set it in the settings.' ) ;
13- return null ;
14- }
15- return apiKey ;
16- }
17-
185/**
196 * 获取 DeepSeek 模型配置
207 * @returns { modelName: string, apiBaseURL: string }
218 */
22- function getDeepSeekModelConfig ( ) : { modelName : string , apiBaseURL : string } {
9+ function getDeepSeekModelConfig ( ) : { modelName : string , apiBaseURL : string , apiKey : string | null } {
2310 const config = vscode . workspace . getConfiguration ( 'codeReDesign' ) ;
2411 const modelConfig = config . get < string > ( 'modelConfig' ) || 'deepseek-chat' ;
12+ const apiKey = config . get < string > ( 'deepSeekApiKey' ) || null ;
2513
2614 if ( modelConfig === 'custom' ) {
2715 const customModelName = config . get < string > ( 'customModelName' ) || '' ;
2816 const customApiBaseURL = config . get < string > ( 'customApiBaseURL' ) || '' ;
17+ const apiKey = config . get < string > ( 'customApiKey' ) || null ;
2918 return {
3019 modelName : customModelName ,
31- apiBaseURL : customApiBaseURL
20+ apiBaseURL : customApiBaseURL ,
21+ apiKey : apiKey
3222 } ;
3323 }
3424
3525 // 默认配置
36- const defaultConfigs : { [ key : string ] : { modelName : string , apiBaseURL : string } } = {
26+ const defaultConfigs : { [ key : string ] : { modelName : string , apiBaseURL : string , apiKey : string | null } } = {
3727 'deepseek-chat' : {
3828 modelName : 'deepseek-chat' ,
39- apiBaseURL : 'https://api.deepseek.com'
29+ apiBaseURL : 'https://api.deepseek.com' ,
30+ apiKey
4031 } ,
4132 'deepseek-reasoner' : {
4233 modelName : 'deepseek-reasoner' ,
43- apiBaseURL : 'https://api.deepseek.com'
34+ apiBaseURL : 'https://api.deepseek.com' ,
35+ apiKey
4436 }
4537 } ;
4638
@@ -65,15 +57,14 @@ async function callDeepSeekApi(
6557 endstring ?: string ,
6658 abortSignal ?: AbortSignal
6759) : Promise < string | null > {
68- const apiKey = getDeepSeekApiKey ( ) ;
60+ const { modelName, apiBaseURL, apiKey } = getDeepSeekModelConfig ( ) ;
61+ const userStopException = 'operation stop by user' ;
62+
6963 if ( ! apiKey ) {
70- vscode . window . showWarningMessage ( '请先设置DeepSeek API Key') ;
64+ vscode . window . showErrorMessage ( 'DeepSeek API Key is not configured. Please set it in the settings. ') ;
7165 return null ;
7266 }
7367
74- const { modelName, apiBaseURL } = getDeepSeekModelConfig ( ) ;
75- const userStopException = 'operation stop by user' ;
76-
7768 if ( ! modelName || ! apiBaseURL ) {
7869 vscode . window . showErrorMessage ( 'DeepSeek Model Name or API Base URL is not configured.' ) ;
7970 return null ;
0 commit comments