From b452df7cebfb689f73e5ccd596e5fa64e4cbcc29 Mon Sep 17 00:00:00 2001 From: xiangtianyu Date: Wed, 30 Oct 2024 15:14:46 +0800 Subject: [PATCH] handle more case for different finish reason (#102) --- .../devpilot/integrations/llms/LlmProvider.java | 14 +++++++++++++- src/main/resources/messages/devpilot_en.properties | 5 ++++- src/main/resources/messages/devpilot_zh.properties | 13 ++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/zhongan/devpilot/integrations/llms/LlmProvider.java b/src/main/java/com/zhongan/devpilot/integrations/llms/LlmProvider.java index 0e1c29a..1396a3f 100644 --- a/src/main/java/com/zhongan/devpilot/integrations/llms/LlmProvider.java +++ b/src/main/java/com/zhongan/devpilot/integrations/llms/LlmProvider.java @@ -21,6 +21,7 @@ import java.util.function.Consumer; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -115,7 +116,18 @@ public void onEvent(@NotNull EventSource eventSource, @Nullable String id, @Null if (choice.getDelta().getContent() != null) { result.append(choice.getDelta().getContent()); } - streaming = !"stop".equals(finishReason); + + if (!StringUtils.isEmpty(finishReason)) { + streaming = Boolean.FALSE; + + if (finishReason.contains("length")) { + DevPilotNotification.info(DevPilotMessageBundle.get("devpilot.notification.stop.length")); + } + + if (finishReason.contains("content_filter")) { + DevPilotNotification.info(DevPilotMessageBundle.get("devpilot.notification.stop.filterContent")); + } + } } RecallModel recallModel = null; diff --git a/src/main/resources/messages/devpilot_en.properties b/src/main/resources/messages/devpilot_en.properties index d128dc5..e607d61 100644 --- a/src/main/resources/messages/devpilot_en.properties +++ b/src/main/resources/messages/devpilot_en.properties @@ -101,4 +101,7 @@ completion.apply.partial.tooltips=Accept by line devpilot.settings.methodShortcutDisplayModeLabel=Method Shortcut Display Mode devpilot.settings.methodShortcutHidden=Hidden devpilot.settings.methodShortcutInlineDisplay=Inline -devpilot.settings.methodShortcutGroupDisplay=Group \ No newline at end of file +devpilot.settings.methodShortcutGroupDisplay=Group + +devpilot.notification.stop.length=Devpilot terminated due to exceeding length. +devpilot.notification.stop.filterContent=Devpilot terminated due to content filter. \ No newline at end of file diff --git a/src/main/resources/messages/devpilot_zh.properties b/src/main/resources/messages/devpilot_zh.properties index 8a12fe6..7f110a5 100644 --- a/src/main/resources/messages/devpilot_zh.properties +++ b/src/main/resources/messages/devpilot_zh.properties @@ -94,9 +94,12 @@ devpilot.notification.network.setting=\u72B6\u6001\u68C0\u67E5\u914D\u7F6E devpilot.notification.version.message=DevPilot\u7248\u672C\u592A\u4F4E, \u8BF7\u5347\u7EA7\u7248\u672C devpilot.notification.upgrade.message=\u53BB\u5347\u7EA7\u63D2\u4EF6 -completion.apply.partial.tooltips=\u9010\u884C\u91C7\u7EB3 +devpilot.settings.methodShortcutDisplayModeLabel=\u65b9\u6cd5\u5feb\u6377\u952e\u663e\u793a\u65b9\u5f0f +devpilot.settings.methodShortcutHidden=\u4e0d\u663e\u793a +devpilot.settings.methodShortcutInlineDisplay=\u5e73\u94fa +devpilot.settings.methodShortcutGroupDisplay=\u5206\u7ec4\u4e0b\u62c9 + +devpilot.notification.stop.length=Devpilot\u8d85\u51fa\u957f\u5ea6\u800c\u7ec8\u6b62. +devpilot.notification.stop.filterContent=Devpilot\u8fc7\u6ee4\u4e86\u6b64\u5185\u5bb9. -devpilot.settings.methodShortcutDisplayModeLabel=\u65B9\u6CD5\u5FEB\u6377\u952E\u663E\u793A\u65B9\u5F0F -devpilot.settings.methodShortcutHidden=\u4E0D\u663E\u793A -devpilot.settings.methodShortcutInlineDisplay=\u5E73\u94FA -devpilot.settings.methodShortcutGroupDisplay=\u5206\u7EC4\u4E0B\u62C9 \ No newline at end of file +completion.apply.partial.tooltips=\u9010\u884C\u91C7\u7EB3