-
Notifications
You must be signed in to change notification settings - Fork 114
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
feat: enhance openai prompt #186
Conversation
我将暂时先合并你的版本,但考虑到更平滑、简洁的兼容性,字段命名上,之前的 兼容性主要是考虑:用户升级到了新版本,但是API的配置并没有及时重新设置的情况。 按照你目前的更新,API参数经过一次浅合并后: kiss-translator/src/hooks/Translate.js Lines 49 to 52 in d27b9c7
大概如下: {
prompt: `You will be provided with a sentence in ${INPUT_PLACE_FROM}, and your task is to translate it into ${INPUT_PLACE_TO}.`,
systemPrompt: `You are a professional, authentic machine translation engine. You will be provided with a sentence in ${INPUT_PLACE_FROM}, and your task is to translate it into ${INPUT_PLACE_TO}.`,
} 再经过如下追加: if (!prompt.includes(INPUT_PLACE_TEXT)) {
prompt += `\nSource Text: ${INPUT_PLACE_TEXT}`;
} 最终如下: {
prompt: `You will be provided with a sentence in ${INPUT_PLACE_FROM}, and your task is to translate it into ${INPUT_PLACE_TO}.\nSource Text: ${INPUT_PLACE_TEXT}`,
systemPrompt: `You are a professional, authentic machine translation engine. You will be provided with a sentence in ${INPUT_PLACE_FROM}, and your task is to translate it into ${INPUT_PLACE_TO}.`,
} 如果是采用增加 {
prompt: `You will be provided with a sentence in ${INPUT_PLACE_FROM}, and your task is to translate it into ${INPUT_PLACE_TO}.`,
userPrompt: `Translate the following source text from ${INPUT_PLACE_FROM} to ${INPUT_PLACE_TO}. Output translation directly without any additional text.\n\nSource Text: ${INPUT_PLACE_TEXT}\n\nTranslated Text:`,
} 可见,离升级后的推荐格式: {
prompt: `You are a professional, authentic machine translation engine. You will be provided with a sentence in ${INPUT_PLACE_FROM}, and your task is to translate it into ${INPUT_PLACE_TO}.`,
userPrompt: `Translate the following source text from ${INPUT_PLACE_FROM} to ${INPUT_PLACE_TO}. Output translation directly without any additional text.\n\nSource Text: ${INPUT_PLACE_TEXT}\n\nTranslated Text:`,
} 很接近了,无需如下代码即有很好的兼容性: if (!prompt.includes(INPUT_PLACE_TEXT)) {
prompt += `\nSource Text: ${INPUT_PLACE_TEXT}`;
} |
另外 |
确实,去掉隐藏的判断比较好 也许可以完全使用 |
废弃旧字段,强制使用新字段的默认值,可能会使得部分用户 |
Close #141
根据 #185 #141 建议,对OpenAI prompt进行双重约束
默认请求示例
为兼容历史上作为systemPrompt的prompt,如果prompt中不包含带翻译文本,则添加文本到prompt末尾