Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/chore/ai-native-module' into cho…
Browse files Browse the repository at this point in the history
…re/improve-inline-chat-position
  • Loading branch information
Ricbet committed Nov 17, 2023
2 parents 152649b + 39f7064 commit 5fc0588
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/ai-native/src/browser/ai-sumi/sumi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,8 @@ export class AiSumiService {
private readonly loggerManagerClient: ILoggerManagerClient;

protected logger: ILogServiceClient;
// 用来记录查找失败的,因为用 any,在 catch 里不好处理,加个变量记录下
private findCommandRequestErrorCode = 0;

constructor() {
this.logger = this.loggerManagerClient.getLogger(SupportLogNamespace.Browser);
Expand Down Expand Up @@ -1277,15 +1279,20 @@ export class AiSumiService {
}

public async searchCommand(input: string): Promise<IAiBackServiceResponse<Command>> {
return this.searchGroup(input);
this.findCommandRequestErrorCode = 0;
try {
return this.searchGroup(input);
} catch {
return { errorCode: 1 };
}
}

public async searchGroup(input: string) {
const enPrompt = this.promptManager.searchGroup(input, { useCot: true });

const groupReply = await this.requestToModel(enPrompt);

if (groupReply.errorCode) {
if (groupReply?.errorCode) {
return { errorCode: groupReply.errorCode, errorMsg: groupReply.errorMsg };
}

Expand Down Expand Up @@ -1319,7 +1326,7 @@ export class AiSumiService {
return { data: commands.find((c) => c.id === command?.data) };
} catch (e) {
this.logger.error('Find command failed: ', e.message);
return { errorCode: 1 };
return { errorCode: this.findCommandRequestErrorCode };
}
}

Expand All @@ -1332,6 +1339,11 @@ export class AiSumiService {
});

const commandReply = await this.requestToModel(prompt);

if (commandReply.errorCode) {
this.findCommandRequestErrorCode = commandReply.errorCode;
}

const answerCommand = this.matchCommand(commandReply.data || '');

if (answerCommand && commands.find((c) => c.id === answerCommand)) {
Expand Down

0 comments on commit 5fc0588

Please sign in to comment.