fix(editor): custom image width parsing, fix image paste, add AI submenu features
This commit is contained in:
@@ -10,7 +10,7 @@ import { LanguageDetectionService } from './language-detection.service'
|
||||
import { getTagsProvider } from '../factory'
|
||||
import { getSystemConfig } from '@/lib/config'
|
||||
|
||||
export type RefactorMode = 'clarify' | 'shorten' | 'improveStyle'
|
||||
export type RefactorMode = 'clarify' | 'shorten' | 'improveStyle' | 'fix_grammar' | 'translate' | 'explain'
|
||||
|
||||
export interface RefactorOption {
|
||||
mode: RefactorMode
|
||||
@@ -68,7 +68,8 @@ export class ParagraphRefactorService {
|
||||
async refactor(
|
||||
content: string,
|
||||
mode: RefactorMode,
|
||||
format: 'html' | 'markdown' = 'markdown'
|
||||
format: 'html' | 'markdown' = 'markdown',
|
||||
targetLanguage?: string
|
||||
): Promise<RefactorResult> {
|
||||
// Validate word count
|
||||
const wordCount = content.split(/\s+/).length
|
||||
@@ -78,8 +79,9 @@ export class ParagraphRefactorService {
|
||||
)
|
||||
}
|
||||
|
||||
// Detect language
|
||||
const { language } = await this.languageDetection.detectLanguage(content)
|
||||
// Detect language or use provided target language
|
||||
const { language: detectedLanguage } = await this.languageDetection.detectLanguage(content)
|
||||
const language = targetLanguage || detectedLanguage
|
||||
|
||||
try {
|
||||
// Build prompts
|
||||
@@ -233,7 +235,24 @@ Remove fluff, repetition, and unnecessary words, but keep the substance.${format
|
||||
Your goal: Enhance the text's style, vocabulary, sentence structure, and overall quality.
|
||||
|
||||
CRITICAL LANGUAGE RULE: You MUST respond in the EXACT SAME LANGUAGE as the input text. If input is French, output MUST be French. If input is German, output MUST be German. NEVER translate to English.
|
||||
Maintain similar length but make it sound more professional and polished.${formatInstruction}`
|
||||
Maintain similar length but make it sound more professional and polished.${formatInstruction}`,
|
||||
|
||||
fix_grammar: `You are an expert proofreader.
|
||||
Your goal: Fix spelling, grammar, and punctuation errors in the text without changing its meaning, tone, or style.
|
||||
|
||||
CRITICAL LANGUAGE RULE: You MUST respond in the EXACT SAME LANGUAGE as the input text. NEVER translate to English.
|
||||
Make minimal changes, only correcting errors.${formatInstruction}`,
|
||||
|
||||
translate: `You are a professional translator.
|
||||
Your goal: Translate the text perfectly into the target language requested by the user.
|
||||
Ensure the translation sounds natural and preserves the original tone and formatting.${formatInstruction}`,
|
||||
|
||||
explain: `You are an expert teacher and encyclopedia.
|
||||
Your goal: Explain the selected text, concept, or word clearly and concisely.
|
||||
Provide context, definitions, or relevant information to help the user understand it.
|
||||
|
||||
CRITICAL LANGUAGE RULE: You MUST explain it in the requested language (which is the user's interface language).
|
||||
Keep it concise but informative.${formatInstruction}`
|
||||
}
|
||||
|
||||
return prompts[mode]
|
||||
@@ -254,7 +273,17 @@ Please shorten this ${language} text while keeping all key information:`,
|
||||
|
||||
improveStyle: `IMPORTANT: The text below is in ${language}. Your response MUST be in ${language}. Do NOT translate to English.
|
||||
|
||||
Please improve the style and readability of this ${language} text:`
|
||||
Please improve the style and readability of this ${language} text:`,
|
||||
|
||||
fix_grammar: `IMPORTANT: The text below is in ${language}. Your response MUST be in ${language}. Do NOT translate to English.
|
||||
|
||||
Please fix any spelling, grammar, or punctuation errors in this ${language} text:`,
|
||||
|
||||
translate: `Please translate the following text into ${language}.
|
||||
Only return the translated text, nothing else.`,
|
||||
|
||||
explain: `Please explain the following text/concept in ${language}.
|
||||
Keep the explanation clear, educational, and concise.`
|
||||
}
|
||||
|
||||
return `${instructions[mode]}
|
||||
|
||||
Reference in New Issue
Block a user