Skip to content

Commit 19fc0bf

Browse files
committed
feat(devti): add prompt enhancement feature
#358 - Add PromptEnhancer service to enhance user input based on domain dictionary - Implement prompt enhancement functionality in AutoDevInputSection - Add new resources for prompt enhancement templates in both English and Chinese
1 parent 4b9f2e9 commit 19fc0bf

File tree

4 files changed

+154
-1
lines changed

4 files changed

+154
-1
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/AutoDevInputSection.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import cc.unitmesh.devti.gui.chat.ui.file.RelatedFileListCellRenderer
1010
import cc.unitmesh.devti.gui.chat.ui.file.RelatedFileListViewModel
1111
import cc.unitmesh.devti.gui.chat.ui.file.WorkspaceFilePanel
1212
import cc.unitmesh.devti.gui.chat.ui.file.WorkspaceFileToolbar
13+
import cc.unitmesh.devti.indexer.DomainDictService
14+
import cc.unitmesh.devti.indexer.usage.PromptEnhancer
15+
import cc.unitmesh.devti.llms.LlmFactory
1316
import cc.unitmesh.devti.llms.tokenizer.Tokenizer
1417
import cc.unitmesh.devti.llms.tokenizer.TokenizerFactory
1518
import cc.unitmesh.devti.provider.RelatedClassesProvider
1619
import cc.unitmesh.devti.settings.AutoDevSettingsState
1720
import cc.unitmesh.devti.settings.customize.customizeSetting
21+
import cc.unitmesh.devti.util.parser.CodeFence
1822
import com.intellij.codeInsight.lookup.LookupManagerListener
1923
import com.intellij.ide.IdeTooltip
2024
import com.intellij.ide.IdeTooltipManager
@@ -23,6 +27,7 @@ import com.intellij.openapi.actionSystem.Presentation
2327
import com.intellij.openapi.actionSystem.impl.ActionButton
2428
import com.intellij.openapi.application.ApplicationManager
2529
import com.intellij.openapi.application.runInEdt
30+
import com.intellij.openapi.components.service
2631
import com.intellij.openapi.diagnostic.logger
2732
import com.intellij.openapi.editor.event.DocumentEvent
2833
import com.intellij.openapi.editor.event.DocumentListener
@@ -124,6 +129,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
124129
}
125130
this.enhanceButtonPresentation = Presentation("Enhance").apply {
126131
icon = AutoDevIcons.MAGIC
132+
isEnabled = project.service<DomainDictService>().loadContent()?.isNotEmpty() == true
127133
}
128134

129135
sendButton = ActionButton(
@@ -142,7 +148,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
142148

143149
enhanceButton = ActionButton(
144150
DumbAwareAction.create {
145-
AutoDevNotifications.notify(project, "Enhancing input text...")
151+
enhancePrompt()
146152
},
147153
this.enhanceButtonPresentation, "", Dimension(20, 20)
148154
)
@@ -227,6 +233,24 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
227233
}
228234
}
229235

236+
private fun enhancePrompt() {
237+
val originalIcon = enhanceButtonPresentation.icon
238+
enhanceButtonPresentation.icon = AutoDevIcons.InProgress
239+
enhanceButtonPresentation.isEnabled = false
240+
241+
try {
242+
val content = project.service<PromptEnhancer>().create(input.text)
243+
val code = CodeFence.parse(content).text
244+
this.setText(code)
245+
} catch (e: Exception) {
246+
logger.error("Failed to enhance prompt", e)
247+
AutoDevNotifications.error(project, e.message ?: "An error occurred while enhancing the prompt")
248+
} finally {
249+
enhanceButtonPresentation.icon = originalIcon
250+
enhanceButtonPresentation.isEnabled = true
251+
}
252+
}
253+
230254
private fun createButtonPanel(): JPanel {
231255
val panel = JPanel(CardLayout())
232256

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cc.unitmesh.devti.indexer.usage
2+
3+
import cc.unitmesh.devti.indexer.DomainDictService
4+
import cc.unitmesh.devti.template.GENIUS_CODE
5+
import cc.unitmesh.devti.template.TemplateRender
6+
import cc.unitmesh.devti.template.context.TemplateContext
7+
import com.intellij.openapi.components.Service
8+
import com.intellij.openapi.project.Project
9+
10+
@Service(Service.Level.PROJECT)
11+
class PromptEnhancer(val project: Project) {
12+
val templateRender: TemplateRender get() = TemplateRender(GENIUS_CODE)
13+
val template = templateRender.getTemplate("enhance.vm")
14+
15+
fun create(input: String): String {
16+
val dict = project.getService(DomainDictService::class.java).loadContent() ?: ""
17+
val context = PromptEnhancerContext(dict, input)
18+
return templateRender.renderTemplate(template, context)
19+
}
20+
}
21+
22+
data class PromptEnhancerContext(
23+
val dict: String,
24+
val userInput: String
25+
) : TemplateContext {
26+
27+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
你是一个专业的 AI 提示词优化专家。请帮我优化以下 prompt,并按照格式返回。
2+
3+
以下是用户提供的词汇表:
4+
5+
```csv
6+
中文,英语(代码用),描述
7+
金融产品,FinancialProduct,金融领域核心聚合根,包含产品基础信息和生命周期状态
8+
产品ID,productId,产品的唯一标识符,通常为UUID或业务编码
9+
产品名称,productName,金融产品的公开名称(如"稳健理财30天")
10+
产品类型,productType,枚举值:DEPOSIT(存款)、FUND(基金)、INSURANCE(保险)等
11+
风险等级,riskLevel,产品风险分级:R1(保守型)到R5(激进型)
12+
起购金额,minPurchaseAmount,最小购买额度,Money值对象类型
13+
利率规则,InterestRateRule,定义利息计算规则的实体
14+
计息方式,interestCalculationMethod,枚举值:SIMPLE(单利)、COMPOUND(复利)
15+
基准利率,baseRate,央行公布的基准利率百分比
16+
费用规则,FeeRule,定义各类手续费的实体
17+
费用类型,feeType,枚举值:PURCHASE_FEE(申购费)、MANAGEMENT_FEE(管理费)
18+
货币金额,Money,值对象,包含金额数值和货币类型
19+
持有份额,shares,用户当前持有的产品份额(支持小数)
20+
购买服务,PurchaseService,领域服务,处理购买业务逻辑
21+
收益计算,YieldCalculator,领域服务,封装收益计算算法
22+
产品仓储,ProductRepository,持久化接口,管理金融产品聚合根
23+
购买事件,PurchaseEvent,领域事件,记录用户购买行为
24+
账户适配器,AccountAdapter,防腐层,对接外部账户系统
25+
合规检查,ComplianceCheck,领域服务,执行KYC/AML验证
26+
专属理财顾问,ZSLCGW,招行高净值用户专属服务
27+
理财产品,LiCai,理财公司按照约定条件和实际投资收益情况向投资者支付收益、不保证本金支付和收益水平的非保本理财产品
28+
产品转让平台,CPZRPT,招行特有的二手理财转让市场
29+
招行风险评估,ZSYHFXPG,特有的在线风险评估问卷
30+
手机银行购买,SJYHGM,招行主推的购买渠道标识
31+
朝朝宝实例,ZZB,招行明星产品:代码ZHZB001,R1风险,T+0赎回
32+
日日盈实例,RRY,招行定期开放产品:代码ZHRR005,R2风险
33+
季季宝实例,JJB,招行固收类产品:代码ZHJJ008,R3风险
34+
```
35+
36+
## 输出格式要求:
37+
38+
- 使用 markdown 代码块返回结果,方便我解析
39+
- 改进后的完整示例要和用户提供的 prompt 语言一致
40+
- 改进后的完整示例要和用户提供的 prompt 描述的信息一致
41+
- 输出的内容只包含改进后的完整示例,不要添加任何其他内容
42+
43+
问答示例:
44+
45+
Question: 购买朝朝宝产品的流程
46+
Anwswer: 购买朝朝宝(zzb)理财(LiCai)产品的流程
47+
48+
Question:创建聚益生金金融产品的代码示例
49+
Anwswer: 创建聚益生金(JYSJ)金融产品(FinancialProduct)代码示例
50+
51+
现在,用户的 Question 是:重构日日盈相关服务
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
你是一个专业的 AI 提示词优化专家。请帮我优化以下 prompt,并按照格式返回。
2+
3+
以下是用户提供的词汇表:
4+
5+
```csv
6+
中文,英语(代码用),描述
7+
金融产品,FinancialProduct,金融领域核心聚合根,包含产品基础信息和生命周期状态
8+
产品ID,productId,产品的唯一标识符,通常为UUID或业务编码
9+
产品名称,productName,金融产品的公开名称(如"稳健理财30天")
10+
产品类型,productType,枚举值:DEPOSIT(存款)、FUND(基金)、INSURANCE(保险)等
11+
风险等级,riskLevel,产品风险分级:R1(保守型)到R5(激进型)
12+
起购金额,minPurchaseAmount,最小购买额度,Money值对象类型
13+
利率规则,InterestRateRule,定义利息计算规则的实体
14+
计息方式,interestCalculationMethod,枚举值:SIMPLE(单利)、COMPOUND(复利)
15+
基准利率,baseRate,央行公布的基准利率百分比
16+
费用规则,FeeRule,定义各类手续费的实体
17+
费用类型,feeType,枚举值:PURCHASE_FEE(申购费)、MANAGEMENT_FEE(管理费)
18+
货币金额,Money,值对象,包含金额数值和货币类型
19+
持有份额,shares,用户当前持有的产品份额(支持小数)
20+
购买服务,PurchaseService,领域服务,处理购买业务逻辑
21+
收益计算,YieldCalculator,领域服务,封装收益计算算法
22+
产品仓储,ProductRepository,持久化接口,管理金融产品聚合根
23+
购买事件,PurchaseEvent,领域事件,记录用户购买行为
24+
账户适配器,AccountAdapter,防腐层,对接外部账户系统
25+
合规检查,ComplianceCheck,领域服务,执行KYC/AML验证
26+
专属理财顾问,ZSLCGW,招行高净值用户专属服务
27+
理财产品,LiCai,理财公司按照约定条件和实际投资收益情况向投资者支付收益、不保证本金支付和收益水平的非保本理财产品
28+
产品转让平台,CPZRPT,招行特有的二手理财转让市场
29+
招行风险评估,ZSYHFXPG,特有的在线风险评估问卷
30+
手机银行购买,SJYHGM,招行主推的购买渠道标识
31+
朝朝宝实例,ZZB,招行明星产品:代码ZHZB001,R1风险,T+0赎回
32+
日日盈实例,RRY,招行定期开放产品:代码ZHRR005,R2风险
33+
季季宝实例,JJB,招行固收类产品:代码ZHJJ008,R3风险
34+
```
35+
36+
## 输出格式要求:
37+
38+
- 使用 markdown 代码块返回结果,方便我解析
39+
- 改进后的完整示例要和用户提供的 prompt 语言一致
40+
- 改进后的完整示例要和用户提供的 prompt 描述的信息一致
41+
- 输出的内容只包含改进后的完整示例,不要添加任何其他内容
42+
43+
问答示例:
44+
45+
Question: 购买朝朝宝产品的流程
46+
Anwswer: 购买朝朝宝(zzb)理财(LiCai)产品的流程
47+
48+
Question:创建聚益生金金融产品的代码示例
49+
Anwswer: 创建聚益生金(JYSJ)金融产品(FinancialProduct)代码示例
50+
51+
现在,用户的 Question 是:重构日日盈相关服务

0 commit comments

Comments
 (0)