-
Notifications
You must be signed in to change notification settings - Fork 626
Bugfix/custom prompt cant load content #936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| name: Bug | ||
| description: Report a problem / 报告一个问题 | ||
| title: "[BUG] " | ||
| labels: | ||
| - bug | ||
| body: | ||
| - type: markdown | ||
| attributes: | ||
| value: | | ||
| Remember: DeepChat is an open source gift, not a product you bought from a vendor. | ||
|
|
||
| Use English or Chinese. You may keep only one language when filling. | ||
| 可以只使用其中一种语言填写,保留一种语言即可。 | ||
|
|
||
| - type: input | ||
| id: system-details | ||
| attributes: | ||
| label: System details / 系统信息 | ||
| description: CPU, GPU, OS and DeepChat version / CPU、GPU、操作系统与 DeepChat 版本 | ||
| placeholder: e.g. M3 Max, macOS 15.0, DeepChat 0.10.0 | ||
| validations: | ||
| required: true | ||
|
|
||
| - type: textarea | ||
| id: steps | ||
| attributes: | ||
| label: What's wrong? / 出了什么问题? | ||
| description: | | ||
| Briefly describe the problem and how to reproduce it (steps, expected vs actual). | ||
| 简要描述问题及其复现步骤(步骤、预期与实际结果)。 | ||
| placeholder: | | ||
| 1. Go to ... | ||
| 2. Click ... | ||
| Expected: ... | ||
| Actual: ... | ||
|
|
||
| 1. 前往 ... | ||
| 2. 点击 ... | ||
| 预期:... | ||
| 实际:... | ||
| validations: | ||
| required: true | ||
|
|
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| name: Enhancement | ||
| description: Feature or change / 功能或改动 | ||
| title: "[Feature] " | ||
| labels: | ||
| - enhancement | ||
| body: | ||
| - type: markdown | ||
| attributes: | ||
| value: | | ||
| Remember: DeepChat is an open source gift, not a product you bought from a vendor. | ||
|
|
||
| Use English or Chinese. You may keep only one language when filling. | ||
| 可以只使用其中一种语言填写,保留一种语言即可。 | ||
|
|
||
| - type: textarea | ||
| id: request | ||
| attributes: | ||
| label: What do you need? / 你需要什么? | ||
| description: Describe the feature or change you want / 描述你希望的功能或改动 | ||
| placeholder: | | ||
| English: I need ... because ... | ||
| 中文:我需要……,因为…… | ||
| validations: | ||
| required: true | ||
|
|
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -100,6 +100,8 @@ export class ConfigPresenter implements IConfigPresenter { | |||||||||||||||||||||||||||||||||
| private knowledgeConfHelper: KnowledgeConfHelper // Knowledge configuration helper | ||||||||||||||||||||||||||||||||||
| // Model status memory cache for high-frequency read/write operations | ||||||||||||||||||||||||||||||||||
| private modelStatusCache: Map<string, boolean> = new Map() | ||||||||||||||||||||||||||||||||||
| // Custom prompts cache for high-frequency read operations | ||||||||||||||||||||||||||||||||||
| private customPromptsCache: Prompt[] | null = null | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| constructor() { | ||||||||||||||||||||||||||||||||||
| this.userDataPath = app.getPath('userData') | ||||||||||||||||||||||||||||||||||
|
|
@@ -1194,45 +1196,81 @@ export class ConfigPresenter implements IConfigPresenter { | |||||||||||||||||||||||||||||||||
| return nativeTheme.shouldUseDarkColors ? 'dark' : 'light' | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // 获取所有自定义 prompts | ||||||||||||||||||||||||||||||||||
| // 获取所有自定义 prompts (with cache) | ||||||||||||||||||||||||||||||||||
| async getCustomPrompts(): Promise<Prompt[]> { | ||||||||||||||||||||||||||||||||||
| // Check cache first | ||||||||||||||||||||||||||||||||||
| if (this.customPromptsCache !== null) { | ||||||||||||||||||||||||||||||||||
| return this.customPromptsCache | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Load from store and cache it | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| return this.customPromptsStore.get('prompts') || [] | ||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||
| const prompts = this.customPromptsStore.get('prompts') || [] | ||||||||||||||||||||||||||||||||||
| this.customPromptsCache = prompts | ||||||||||||||||||||||||||||||||||
| console.log(`[Config] Custom prompts cache loaded: ${prompts.length} prompts`) | ||||||||||||||||||||||||||||||||||
| return prompts | ||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||
| console.error('[Config] Failed to load custom prompts:', error) | ||||||||||||||||||||||||||||||||||
| this.customPromptsCache = [] | ||||||||||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // 保存自定义 prompts | ||||||||||||||||||||||||||||||||||
| // 保存自定义 prompts (with cache update) | ||||||||||||||||||||||||||||||||||
| async setCustomPrompts(prompts: Prompt[]): Promise<void> { | ||||||||||||||||||||||||||||||||||
| await this.customPromptsStore.set('prompts', prompts) | ||||||||||||||||||||||||||||||||||
| this.clearCustomPromptsCache() | ||||||||||||||||||||||||||||||||||
| console.log(`[Config] Custom prompts cache updated: ${prompts.length} prompts`) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // 添加单个 prompt | ||||||||||||||||||||||||||||||||||
| // 添加单个 prompt (optimized with cache) | ||||||||||||||||||||||||||||||||||
| async addCustomPrompt(prompt: Prompt): Promise<void> { | ||||||||||||||||||||||||||||||||||
| const prompts = await this.getCustomPrompts() | ||||||||||||||||||||||||||||||||||
| prompts.push(prompt) | ||||||||||||||||||||||||||||||||||
| await this.setCustomPrompts(prompts) | ||||||||||||||||||||||||||||||||||
| // 事件会在 setCustomPrompts 中触发 | ||||||||||||||||||||||||||||||||||
| const updatedPrompts = [...prompts, prompt] // Create new array | ||||||||||||||||||||||||||||||||||
| await this.setCustomPrompts(updatedPrompts) | ||||||||||||||||||||||||||||||||||
| this.clearCustomPromptsCache() | ||||||||||||||||||||||||||||||||||
| console.log(`[Config] Added custom prompt: ${prompt.name}`) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // 更新单个 prompt | ||||||||||||||||||||||||||||||||||
| // 更新单个 prompt (optimized with cache) | ||||||||||||||||||||||||||||||||||
| async updateCustomPrompt(promptId: string, updates: Partial<Prompt>): Promise<void> { | ||||||||||||||||||||||||||||||||||
| const prompts = await this.getCustomPrompts() | ||||||||||||||||||||||||||||||||||
| const index = prompts.findIndex((p) => p.id === promptId) | ||||||||||||||||||||||||||||||||||
| if (index !== -1) { | ||||||||||||||||||||||||||||||||||
| prompts[index] = { ...prompts[index], ...updates } | ||||||||||||||||||||||||||||||||||
| await this.setCustomPrompts(prompts) | ||||||||||||||||||||||||||||||||||
| // 事件会在 setCustomPrompts 中触发 | ||||||||||||||||||||||||||||||||||
| const updatedPrompts = [...prompts] // Create new array | ||||||||||||||||||||||||||||||||||
| updatedPrompts[index] = { ...updatedPrompts[index], ...updates } | ||||||||||||||||||||||||||||||||||
| await this.setCustomPrompts(updatedPrompts) | ||||||||||||||||||||||||||||||||||
| // remove cache | ||||||||||||||||||||||||||||||||||
| this.clearCustomPromptsCache() | ||||||||||||||||||||||||||||||||||
| console.log(`[Config] Updated custom prompt: ${promptId}`) | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| console.warn(`[Config] Custom prompt not found for update: ${promptId}`) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // 删除单个 prompt | ||||||||||||||||||||||||||||||||||
| // 删除单个 prompt (optimized with cache) | ||||||||||||||||||||||||||||||||||
| async deleteCustomPrompt(promptId: string): Promise<void> { | ||||||||||||||||||||||||||||||||||
| const prompts = await this.getCustomPrompts() | ||||||||||||||||||||||||||||||||||
| const initialCount = prompts.length | ||||||||||||||||||||||||||||||||||
| const filteredPrompts = prompts.filter((p) => p.id !== promptId) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (filteredPrompts.length === initialCount) { | ||||||||||||||||||||||||||||||||||
| console.warn(`[Config] Custom prompt not found for deletion: ${promptId}`) | ||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| await this.setCustomPrompts(filteredPrompts) | ||||||||||||||||||||||||||||||||||
| // 事件会在 setCustomPrompts 中触发 | ||||||||||||||||||||||||||||||||||
| this.clearCustomPromptsCache() | ||||||||||||||||||||||||||||||||||
| console.log(`[Config] Deleted custom prompt: ${promptId}`) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||
| * 清除自定义 prompts 缓存 | ||||||||||||||||||||||||||||||||||
| * 这将强制下次访问时重新加载 | ||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||
| clearCustomPromptsCache(): void { | ||||||||||||||||||||||||||||||||||
| console.log('[Config] Clearing custom prompts cache') | ||||||||||||||||||||||||||||||||||
| this.customPromptsCache = null | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1267
to
1274
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments must be in English Align with repository guidelines. Apply this diff: - /**
- * 清除自定义 prompts 缓存
- * 这将强制下次访问时重新加载
- */
+ /**
+ * Clear custom prompts cache
+ * Forces reload on next access
+ */📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // 获取默认系统提示词 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not cache failure results; also use English comments per guidelines
Caching [] on error locks out future reads until an external invalidation. Prefer leaving cache null after failures. Also, comments must be in English (see coding guidelines).
Apply this diff:
🤖 Prompt for AI Agents