@@ -72,6 +72,7 @@ async function callDeepSeekApi(
7272 }
7373
7474 const { modelName, apiBaseURL } = getDeepSeekModelConfig ( ) ;
75+ const userStopException = 'operation stop by user' ;
7576
7677 if ( ! modelName || ! apiBaseURL ) {
7778 vscode . window . showErrorMessage ( 'DeepSeek Model Name or API Base URL is not configured.' ) ;
@@ -117,7 +118,7 @@ async function callDeepSeekApi(
117118 if ( streamMode ) {
118119 for await ( const chunk of response as AsyncIterable < OpenAI . Chat . Completions . ChatCompletionChunk > ) {
119120 if ( abortSignal ?. aborted ) {
120- throw new Error ( 'operation stop by user' ) ;
121+ throw new Error ( userStopException ) ;
121122 }
122123 const content = chunk . choices [ 0 ] ?. delta ?. content || '' ;
123124 chunkResponse += content ;
@@ -146,7 +147,7 @@ async function callDeepSeekApi(
146147 if ( ! shouldContinue ) { break } ;
147148
148149 if ( abortSignal ?. aborted ) {
149- throw new Error ( 'operation stop by user' ) ;
150+ throw new Error ( userStopException ) ;
150151 }
151152
152153 vscode . window . showWarningMessage ( '超过最大Token数,正在重试...' ) ;
@@ -166,7 +167,7 @@ async function callDeepSeekApi(
166167 return fullResponse ;
167168
168169 } catch ( error ) {
169- if ( error instanceof Error && error . message === 'operation stop by user' ) {
170+ if ( error instanceof Error && error . message === userStopException ) {
170171 vscode . window . showInformationMessage ( 'operation stop by user' ) ;
171172 return null ;
172173 }
@@ -265,6 +266,13 @@ function cleanFilename(str: string) {
265266 * @returns 生成的文件名
266267 */
267268export async function generateFilenameFromRequest ( userRequest : string ) : Promise < string > {
269+ if ( userRequest . length < 16 ) {
270+ return cleanFilename ( userRequest )
271+ . replace ( / \s + / g, '' ) // 去除所有空格
272+ . replace ( / ^ \. + | \. + $ / g, '' ) ; // 移除开头和结尾的点
273+ }
274+
275+ // 否则,调用 API 获取概括的文件名
268276 const summaryResponse = await callDeepSeekApi (
269277 `请简单概括一下需求,输出字符串作为文件名。如果描述里有版本名称,这个名称一定要保留并放在开头。 需求:"${ userRequest } "` ,
270278 '你是一个工具函数,接收请求,只返回纯结果,不要有附加说明.' ,
@@ -277,6 +285,7 @@ export async function generateFilenameFromRequest(userRequest: string): Promise<
277285
278286 // 清理文件名
279287 summary = cleanFilename ( summary ) ;
288+ summary = summary . replace ( / \s + / g, '' ) // 去除所有空格
280289 summary = summary . replace ( / ^ \. + | \. + $ / g, '' ) ; // 移除开头和结尾的点
281290 summary = summary . replace ( / ^ + | + $ / g, '' ) ; // 移除开头和结尾的空格
282291 summary = summary . substring ( 0 , 15 ) ; // 截取前15个字符
0 commit comments