-
-
Notifications
You must be signed in to change notification settings - Fork 13.5k
🐛 fix: fix inputTemplate behavior #8204
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
Conversation
Reviewer's GuideThis PR fixes the inputTemplate behavior by introducing a preprocessing step that applies the user message template replacement before adding the system role, removes the deprecated parser variable, and updates locale placeholders to use the new '{{text}}' syntax. Sequence Diagram: Updated Message Preprocessing in generateAIChatsequenceDiagram
participant C as Caller
participant GAC as generateAIChat
participant CC as chatConfig
participant AC as agentConfig
C->>GAC: generateAIChat(messages, chatConfig, agentConfig)
GAC-->>GAC: Initial preprocessMsgs from messages
GAC-->>CC: Get chatConfig.inputTemplate
alt chatConfig.inputTemplate exists
GAC-->>GAC: Loop through preprocessMsgs
opt message.role is 'user'
GAC-->>GAC: Apply inputTemplate to user message content (replace '{{text}}')
end
end
GAC-->>AC: Get agentConfig.systemRole
opt agentConfig.systemRole exists
GAC-->>GAC: Prepend systemRole to preprocessMsgs
end
GAC-->>CC: Get chatConfig.enableMaxTokens
GAC-->>AC: Potentially update agentConfig.params.max_tokens
GAC-->>CC: Get chatConfig.enableReasoningEffort
GAC-->>AC: Potentially update agentConfig.params.reasoning_effort
Class Diagram: Update to VARIABLE_GENERATORS Object StructureclassDiagram
class VARIABLE_GENERATORS {
<<Object>>
%% The 'input_template' property has been removed.
%% The following are existing properties after the update.
+ date() : string
+ time() : string
+ timezone() : string
+ language() : string
+ platform() : string
+ user_agent() : string
+ current_year() : string
+ current_month() : string
+ current_day() : string
+ current_hour() : string
+ current_minute() : string
+ current_second() : string
+ uuid_v4() : string
+ user_display_name() : string
+ user_name() : string
+ user_id() : string
+ browser() : string
+ os() : string
+ device() : string
+ device_type() : string
}
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
Thank you for raising your pull request and contributing to our Community |
TestGru AssignmentSummary
Files
Tip You can |
@hezhijie0327 is attempting to deploy a commit to the LobeHub Community Team on Vercel. A member of the Team first needs to authorize it. |
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.
Hey @hezhijie0327 - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/store/chat/slices/aiChat/actions/generateAIChat.ts:532` </location>
<code_context>
+ try {
+ return { ...m, content: chatConfig.inputTemplate.replaceAll('{{text}}', m.content) };
+ } catch (error) {
+ console.error(error);
+
+ return m;
</code_context>
<issue_to_address>
Provide more context when logging template errors
Add a descriptive message or use structured logging to indicate which template failed and the reason for the error.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
console.error(error);
return m;
=======
console.error(
"Error applying inputTemplate in aiChat: Failed to replace '{{text}}' in template.",
{
template: chatConfig.inputTemplate,
messageContent: m.content,
error,
}
);
return m;
>>>>>>> REPLACE
</suggested_fix>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
console.error(error); | ||
|
||
return m; |
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.
suggestion: Provide more context when logging template errors
Add a descriptive message or use structured logging to indicate which template failed and the reason for the error.
console.error(error); | |
return m; | |
console.error( | |
"Error applying inputTemplate in aiChat: Failed to replace '{{text}}' in template.", | |
{ | |
template: chatConfig.inputTemplate, | |
messageContent: m.content, | |
error, | |
} | |
); | |
return m; |
preprocessMsgs = !chatConfig.inputTemplate | ||
? preprocessMsgs | ||
: preprocessMsgs.map((m) => { | ||
if (m.role === 'user') { | ||
try { | ||
return { ...m, content: chatConfig.inputTemplate.replaceAll('{{text}}', m.content) }; | ||
} catch (error) { | ||
console.error(error); | ||
|
||
return m; | ||
} | ||
} | ||
|
||
return m; | ||
}); |
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.
suggestion (code-quality): Invert ternary operator to remove negation (invert-ternary
)
preprocessMsgs = !chatConfig.inputTemplate | |
? preprocessMsgs | |
: preprocessMsgs.map((m) => { | |
if (m.role === 'user') { | |
try { | |
return { ...m, content: chatConfig.inputTemplate.replaceAll('{{text}}', m.content) }; | |
} catch (error) { | |
console.error(error); | |
return m; | |
} | |
} | |
return m; | |
}); | |
preprocessMsgs = chatConfig.inputTemplate ? preprocessMsgs.map((m) => { | |
if (m.role === 'user') { | |
try { | |
return { ...m, content: chatConfig.inputTemplate.replaceAll('{{text}}', m.content) }; | |
} catch (error) { | |
console.error(error); | |
return m; | |
} | |
} | |
return m; | |
}) : preprocessMsgs; | |
Explanation
Negated conditions are more difficult to read than positive ones, so it is bestto avoid them where we can. By inverting the ternary condition and swapping the
expressions we can simplify the code.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8204 +/- ##
==========================================
- Coverage 87.84% 87.83% -0.02%
==========================================
Files 836 836
Lines 62181 62196 +15
Branches 4134 3938 -196
==========================================
+ Hits 54624 54628 +4
- Misses 7557 7568 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
如果之前的用户消息也会处理占位符的话,这个配置项的描述可能要改一下,比如:用户发送的消息均会遵循此模板处理。而不只是最新的一条消息。 |
If the previous user messages also process placeholders, the description of this configuration item may need to be changed, for example: all messages sent by the user will be filled with this template. And not just the latest news. |
现在对 {{text}} 的替换处理是包含过去用户的历史消息的,这样确实更符合直觉,就是好像没有在描述里体现出来。 单看描述好像只对最新的用户消息处理,以前的则保持原样,不经预处理模板。 比如图中的“你好呀”是历史用户消息,仍然被处理为了“将 你好呀 翻译成英文”。 |
The replacement process for {{text}} now contains historical messages from past users, which is indeed more intuitional, that is, it seems that it is not reflected in the description. It seems that the description is only processed for the latest user messages, while the previous ones remain the same without preprocessing the template. For example, the "Hello" in the picture is a historical user message, but it is still processed to "translate Hello to English". |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
❤️ Great PR @hezhijie0327 ❤️ The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world. |
## [Version 1.96.0](v1.95.0...v1.96.0) <sup>Released on **2025-06-20**</sup> #### ✨ Features - **misc**: Add v0 (Vercel) provider support. #### 🐛 Bug Fixes - **misc**: Fix inputTemplate behavior. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### What's improved * **misc**: Add v0 (Vercel) provider support, closes [#8235](#8235) ([5842a18](5842a18)) #### What's fixed * **misc**: Fix inputTemplate behavior, closes [#8204](#8204) ([61c2c3c](61c2c3c)) </details> <div align="right"> [](#readme-top) </div>
🎉 This PR is included in version 1.96.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## [Version 1.95.0](v1.94.5...v1.95.0) <sup>Released on **2025-06-25**</sup> #### ✨ Features - **misc**: Add Brave & Google PSE & Kagi as build-in Search Provider, add v0 (Vercel) provider support. #### 🐛 Bug Fixes - **misc**: Fix `MiniMax-M1` reasoning tag missing, fix inputTemplate behavior, Google Gemini tools declarations, Remove unsupported parameters of Hunyuan. #### 💄 Styles - **openrouter**: Add stable versions of Gemini 2.5 models. - **misc**: Add `blockAds` & `stealth` params for Browserless, Optimized Gemini thinkingBudget configuration, update i18n, update i18n. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### What's improved * **misc**: Add Brave & Google PSE & Kagi as build-in Search Provider, closes [lobehub#8172](https://github.com/jaworldwideorg/OneJA-Bot/issues/8172) ([16ae521](16ae521)) * **misc**: Add v0 (Vercel) provider support, closes [lobehub#8235](https://github.com/jaworldwideorg/OneJA-Bot/issues/8235) ([5842a18](5842a18)) #### What's fixed * **misc**: Fix `MiniMax-M1` reasoning tag missing, closes [lobehub#8240](https://github.com/jaworldwideorg/OneJA-Bot/issues/8240) ([ea76c11](ea76c11)) * **misc**: Fix inputTemplate behavior, closes [lobehub#8204](https://github.com/jaworldwideorg/OneJA-Bot/issues/8204) ([61c2c3c](61c2c3c)) * **misc**: Google Gemini tools declarations, closes [lobehub#8256](https://github.com/jaworldwideorg/OneJA-Bot/issues/8256) ([08f5d73](08f5d73)) * **misc**: Remove unsupported parameters of Hunyuan, closes [lobehub#8247](https://github.com/jaworldwideorg/OneJA-Bot/issues/8247) ([826d724](826d724)) #### Styles * **openrouter**: Add stable versions of Gemini 2.5 models, closes [lobehub#8239](https://github.com/jaworldwideorg/OneJA-Bot/issues/8239) ([d34ecab](d34ecab)) * **misc**: Add `blockAds` & `stealth` params for Browserless, closes [lobehub#8255](https://github.com/jaworldwideorg/OneJA-Bot/issues/8255) ([2ff3efa](2ff3efa)) * **misc**: Optimized Gemini thinkingBudget configuration, closes [lobehub#8224](https://github.com/jaworldwideorg/OneJA-Bot/issues/8224) ([03625e8](03625e8)) * **misc**: Update i18n, closes [lobehub#8253](https://github.com/jaworldwideorg/OneJA-Bot/issues/8253) ([b86dc9b](b86dc9b)) * **misc**: Update i18n, closes [lobehub#8242](https://github.com/jaworldwideorg/OneJA-Bot/issues/8242) ([2d1babc](2d1babc)) </details> <div align="right"> [](#readme-top) </div>
## [Version 1.96.0](lobehub/lobe-chat@v1.95.0...v1.96.0) <sup>Released on **2025-06-20**</sup> #### ✨ Features - **misc**: Add v0 (Vercel) provider support. #### 🐛 Bug Fixes - **misc**: Fix inputTemplate behavior. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### What's improved * **misc**: Add v0 (Vercel) provider support, closes [lobehub#8235](lobehub#8235) ([5842a18](lobehub@5842a18)) #### What's fixed * **misc**: Fix inputTemplate behavior, closes [lobehub#8204](lobehub#8204) ([61c2c3c](lobehub@61c2c3c)) </details> <div align="right"> [](#readme-top) </div>
## [Version 1.96.0](lobehub/lobe-chat@v1.95.0...v1.96.0) <sup>Released on **2025-06-20**</sup> #### ✨ Features - **misc**: Add v0 (Vercel) provider support. #### 🐛 Bug Fixes - **misc**: Fix inputTemplate behavior. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### What's improved * **misc**: Add v0 (Vercel) provider support, closes [lobehub#8235](lobehub#8235) ([d00e2f5](lobehub@d00e2f5)) #### What's fixed * **misc**: Fix inputTemplate behavior, closes [lobehub#8204](lobehub#8204) ([411607f](lobehub@411607f)) </details> <div align="right"> [](#readme-top) </div>
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
引入自 https://github.com/lobehub/lobe-chat/pull/8060/files#diff-14d8a61991816c736e782edc145026da43f50f04fcfc4eabc1536515b54a5c3d
{{text}}
,并进行内容替换处理📝 补充信息 | Additional Information
close #8187
Summary by Sourcery
Fix the inputTemplate behavior in AI chat by applying the user message template replacement, removing the old parser variable, and updating related locale placeholders.
Bug Fixes:
Enhancements: