@umituz/react-native-ai-generation-content 1.17.169 → 1.17.171
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/domains/prompts/domain/entities/image-prompt-segments.ts +5 -41
- package/src/domains/prompts/index.ts +1 -1
- package/src/domains/prompts/infrastructure/services/BackgroundRemovalService.ts +36 -170
- package/src/domains/prompts/infrastructure/services/ColorizationService.ts +43 -185
- package/src/domains/prompts/infrastructure/services/FaceSwapService.ts +52 -143
- package/src/domains/prompts/infrastructure/services/FuturePredictionService.ts +98 -169
- package/src/domains/prompts/infrastructure/services/ImageEnhancementService.ts +35 -141
- package/src/domains/prompts/infrastructure/services/ImagePromptBuilder.ts +34 -31
- package/src/domains/prompts/infrastructure/services/PhotoRestorationService.ts +43 -121
- package/src/domains/prompts/infrastructure/services/StyleTransferService.ts +50 -150
- package/src/domains/prompts/infrastructure/services/TextGenerationService.ts +41 -192
- package/src/domains/prompts/infrastructure/services/base/index.ts +6 -0
- package/src/domains/prompts/infrastructure/services/base/prompt-service.base.ts +112 -0
|
@@ -1,113 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style Transfer Service
|
|
3
|
+
* AI prompt generation for artistic style transfer
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import type { IStyleTransferService } from '../../domain/repositories/IAIPromptServices';
|
|
2
|
-
import type {
|
|
3
|
-
StyleTransferConfig,
|
|
4
|
-
} from '../../domain/entities/StyleTransferConfig';
|
|
7
|
+
import type { StyleTransferConfig } from '../../domain/entities/StyleTransferConfig';
|
|
5
8
|
import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
getStyleStrengthValue,
|
|
11
|
-
getArtisticModeDescription
|
|
12
|
-
} from '../../domain/entities/StyleTransferConfig';
|
|
13
|
-
import { PromptGenerationService } from '../services/PromptGenerationService';
|
|
14
|
-
|
|
15
|
-
const createStyleTransferBaseTemplate = (config?: {
|
|
16
|
-
artisticMode?: string;
|
|
17
|
-
preserveContent?: boolean;
|
|
18
|
-
}): string => {
|
|
19
|
-
const {
|
|
20
|
-
artisticMode = 'artistic',
|
|
21
|
-
preserveContent = true
|
|
22
|
-
} = config || {};
|
|
23
|
-
|
|
24
|
-
return `
|
|
9
|
+
import { validateStyleTransferConfig, getStyleStrengthValue } from '../../domain/entities/StyleTransferConfig';
|
|
10
|
+
import { BasePromptService } from './base';
|
|
11
|
+
|
|
12
|
+
const BASE_TEMPLATE = `
|
|
25
13
|
You are an expert AI style transfer specialist.
|
|
26
14
|
This is a STYLE TRANSFER task, applying artistic styles while maintaining content.
|
|
27
15
|
|
|
28
|
-
|
|
16
|
+
PRINCIPLES:
|
|
29
17
|
- Apply target artistic style to the image
|
|
30
|
-
- ${preserveContent ? 'Preserve original content and composition' : 'Allow creative reinterpretation'}
|
|
31
18
|
- Maintain key features and subject recognition
|
|
32
19
|
- Balance artistic expression with clarity
|
|
33
20
|
|
|
34
|
-
|
|
35
|
-
${getArtisticModeDescription(artisticMode as StyleTransferConfig['artisticMode'])}
|
|
36
|
-
|
|
37
|
-
STYLE APPLICATION GUIDELINES:
|
|
38
|
-
- Recognize and preserve important elements
|
|
39
|
-
- Apply consistent style throughout the image
|
|
40
|
-
- Maintain appropriate color relationships
|
|
41
|
-
- Preserve facial features and expressions when present
|
|
42
|
-
|
|
43
|
-
TECHNICAL REQUIREMENTS:
|
|
21
|
+
TECHNICAL:
|
|
44
22
|
- Smooth style transitions across the image
|
|
45
23
|
- Appropriate detail preservation based on style
|
|
46
|
-
- Consistent artistic treatment
|
|
47
24
|
- Professional quality output
|
|
48
25
|
|
|
49
|
-
|
|
50
|
-
${preserveContent ?
|
|
51
|
-
'- Maintain key shapes and forms\n- Preserve facial features and expressions\n- Keep text readable if present\n- Maintain spatial relationships' :
|
|
52
|
-
'- Allow creative transformation\n- Artistic interpretation encouraged\n- Style over content fidelity'}
|
|
53
|
-
|
|
54
|
-
SAFETY CONSTRAINTS:
|
|
26
|
+
SAFETY:
|
|
55
27
|
- Do not add inappropriate elements
|
|
56
|
-
- Maintain appropriate content standards
|
|
57
28
|
- Preserve important visual information
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
OUTPUT:
|
|
61
|
-
A beautifully stylized image with the target artistic style,
|
|
62
|
-
${preserveContent ? 'maintaining content integrity' : 'with artistic freedom'}.
|
|
63
|
-
`.trim();
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export class StyleTransferService implements IStyleTransferService {
|
|
67
|
-
private promptService: PromptGenerationService;
|
|
68
|
-
private availableStyles: string[] = [];
|
|
69
|
-
|
|
70
|
-
constructor() {
|
|
71
|
-
this.promptService = new PromptGenerationService();
|
|
72
|
-
this.initializeDefaultStyles();
|
|
73
|
-
}
|
|
29
|
+
`.trim();
|
|
74
30
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
success: false,
|
|
80
|
-
error: 'VALIDATION_ERROR',
|
|
81
|
-
message: 'Invalid style transfer configuration'
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const template = this.createStyleTransferTemplate(config);
|
|
86
|
-
return Promise.resolve({ success: true, data: template });
|
|
87
|
-
} catch {
|
|
88
|
-
return Promise.resolve({
|
|
89
|
-
success: false,
|
|
90
|
-
error: 'GENERATION_FAILED',
|
|
91
|
-
message: 'Failed to generate style transfer template'
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
31
|
+
const DEFAULT_STYLES = [
|
|
32
|
+
'Impressionism', 'Cubism', 'Surrealism', 'Pop Art', 'Watercolor',
|
|
33
|
+
'Oil Painting', 'Pencil Sketch', 'Anime/Manga', 'Vintage Film', 'Cyberpunk',
|
|
34
|
+
];
|
|
95
35
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
targetStyle: config.targetStyle,
|
|
102
|
-
preserveContent: config.preserveContent,
|
|
103
|
-
styleStrength: config.styleStrength,
|
|
104
|
-
artisticMode: config.artisticMode,
|
|
105
|
-
maintainColors: config.maintainColors,
|
|
106
|
-
adaptToSubject: config.adaptToSubject,
|
|
107
|
-
strengthLevel: getStyleStrengthValue(config.styleStrength),
|
|
108
|
-
};
|
|
36
|
+
export class StyleTransferService
|
|
37
|
+
extends BasePromptService<StyleTransferConfig>
|
|
38
|
+
implements IStyleTransferService
|
|
39
|
+
{
|
|
40
|
+
private availableStyles: string[] = [...DEFAULT_STYLES];
|
|
109
41
|
|
|
110
|
-
|
|
42
|
+
protected getServiceName(): string {
|
|
43
|
+
return 'style transfer';
|
|
111
44
|
}
|
|
112
45
|
|
|
113
46
|
validateConfig(config: StyleTransferConfig): boolean {
|
|
@@ -125,70 +58,37 @@ export class StyleTransferService implements IStyleTransferService {
|
|
|
125
58
|
}
|
|
126
59
|
|
|
127
60
|
registerStyles(styles: string[]): void {
|
|
128
|
-
styles.forEach(
|
|
61
|
+
styles.forEach((s) => this.registerStyle(s));
|
|
129
62
|
}
|
|
130
63
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
'Vintage Film',
|
|
142
|
-
'Cyberpunk',
|
|
143
|
-
'Steampunk',
|
|
144
|
-
];
|
|
64
|
+
protected buildVariables(config: StyleTransferConfig): Record<string, unknown> {
|
|
65
|
+
return {
|
|
66
|
+
targetStyle: config.targetStyle,
|
|
67
|
+
preserveContent: config.preserveContent,
|
|
68
|
+
styleStrength: config.styleStrength,
|
|
69
|
+
artisticMode: config.artisticMode,
|
|
70
|
+
maintainColors: config.maintainColors,
|
|
71
|
+
adaptToSubject: config.adaptToSubject,
|
|
72
|
+
strengthLevel: getStyleStrengthValue(config.styleStrength),
|
|
73
|
+
};
|
|
145
74
|
}
|
|
146
75
|
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
const baseTemplate = createStyleTransferBaseTemplate({
|
|
151
|
-
artisticMode: config.artisticMode,
|
|
152
|
-
preserveContent: config.preserveContent,
|
|
153
|
-
});
|
|
76
|
+
protected createTemplate(config: StyleTransferConfig): AIPromptTemplate {
|
|
77
|
+
const styleId = config.targetStyle.toLowerCase().replace(/\s+/g, '-');
|
|
78
|
+
const strength = getStyleStrengthValue(config.styleStrength);
|
|
154
79
|
|
|
155
|
-
return
|
|
156
|
-
id:
|
|
80
|
+
return this.createTemplateWithDefaults({
|
|
81
|
+
id: `style-transfer-${styleId}`,
|
|
157
82
|
name: `Style Transfer: ${config.targetStyle}`,
|
|
158
|
-
description: `Apply ${config.targetStyle}
|
|
83
|
+
description: `Apply ${config.targetStyle} style with ${config.artisticMode} mode`,
|
|
159
84
|
category: 'style-transfer',
|
|
160
|
-
template: `${
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
${config.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
- Artistic Mode: ${config.artisticMode}
|
|
168
|
-
- Preserve Content: ${config.preserveContent}
|
|
169
|
-
- Maintain Colors: ${config.maintainColors}
|
|
170
|
-
- Adapt to Subject: ${config.adaptToSubject}
|
|
171
|
-
|
|
172
|
-
STYLE APPLICATION INSTRUCTIONS:
|
|
173
|
-
Apply ${config.targetStyle} style with ${config.artisticMode} interpretation,
|
|
174
|
-
using ${getStyleStrengthValue(config.styleStrength)} strength level.
|
|
175
|
-
${config.preserveContent ? 'Focus on preserving content integrity while applying style.' : 'Allow artistic interpretation and transformation.'}
|
|
176
|
-
${config.maintainColors ? 'Maintain original color palette where appropriate.' : 'Allow color changes to enhance style.'}
|
|
177
|
-
|
|
178
|
-
EXPECTED RESULT:
|
|
179
|
-
A beautifully stylized image in ${config.targetStyle} style,
|
|
180
|
-
with ${config.artisticMode} artistic interpretation,
|
|
181
|
-
using ${getStyleStrengthValue(config.styleStrength)} strength application.
|
|
182
|
-
`.trim(),
|
|
183
|
-
variables: [],
|
|
184
|
-
safety: {
|
|
185
|
-
contentFilter: true,
|
|
186
|
-
adultContentFilter: true,
|
|
187
|
-
violenceFilter: true,
|
|
188
|
-
hateSpeechFilter: true,
|
|
189
|
-
copyrightFilter: true,
|
|
190
|
-
},
|
|
191
|
-
version: '1.0.0',
|
|
85
|
+
template: `${BASE_TEMPLATE}
|
|
86
|
+
|
|
87
|
+
STYLE: ${config.targetStyle}
|
|
88
|
+
MODE: ${config.artisticMode}
|
|
89
|
+
STRENGTH: ${strength} (${Math.round(config.styleStrength * 100)}%)
|
|
90
|
+
PRESERVE CONTENT: ${config.preserveContent}
|
|
91
|
+
MAINTAIN COLORS: ${config.maintainColors}`,
|
|
192
92
|
});
|
|
193
93
|
}
|
|
194
|
-
}
|
|
94
|
+
}
|
|
@@ -1,114 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Generation Service
|
|
3
|
+
* AI prompt generation for text content creation
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import type { ITextGenerationService } from '../../domain/repositories/IAIPromptServices';
|
|
2
|
-
import type {
|
|
3
|
-
TextGenerationConfig,
|
|
4
|
-
} from '../../domain/entities/TextGenerationConfig';
|
|
7
|
+
import type { TextGenerationConfig } from '../../domain/entities/TextGenerationConfig';
|
|
5
8
|
import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
6
|
-
import type { AIPromptResult } from '../../domain/entities/types';
|
|
7
|
-
import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
8
9
|
import {
|
|
9
10
|
validateTextGenerationConfig,
|
|
10
11
|
getTokenCount,
|
|
11
12
|
getTemperature,
|
|
12
|
-
getTopP
|
|
13
|
+
getTopP,
|
|
13
14
|
} from '../../domain/entities/TextGenerationConfig';
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
const createTextGenerationBaseTemplate = (config?: {
|
|
17
|
-
promptType?: string;
|
|
18
|
-
tone?: string;
|
|
19
|
-
language?: string;
|
|
20
|
-
}): string => {
|
|
21
|
-
const {
|
|
22
|
-
promptType = 'general',
|
|
23
|
-
tone = 'professional',
|
|
24
|
-
language = 'English'
|
|
25
|
-
} = config || {};
|
|
15
|
+
import { BasePromptService } from './base';
|
|
26
16
|
|
|
27
|
-
|
|
17
|
+
const BASE_TEMPLATE = `
|
|
28
18
|
You are an expert text generation specialist.
|
|
29
19
|
This is a TEXT GENERATION task with specific requirements.
|
|
30
20
|
|
|
31
|
-
GENERATION OBJECTIVES:
|
|
32
|
-
- Generate ${promptType} content with ${tone} tone
|
|
33
|
-
- Write in ${language} language
|
|
34
|
-
- Follow provided context and constraints
|
|
35
|
-
- Deliver high-quality, appropriate content
|
|
36
|
-
|
|
37
21
|
CONTENT STANDARDS:
|
|
38
22
|
- Clear, coherent, and well-structured text
|
|
39
23
|
- Appropriate for the specified tone and purpose
|
|
40
24
|
- Natural language flow and readability
|
|
41
|
-
- Relevant and informative content
|
|
42
|
-
|
|
43
|
-
STYLE REQUIREMENTS:
|
|
44
|
-
- Maintain ${tone} tone throughout
|
|
45
|
-
- Use appropriate vocabulary and expressions
|
|
46
|
-
- Follow conventions for ${promptType} content
|
|
47
|
-
- Adapt complexity to intended audience
|
|
48
|
-
|
|
49
|
-
LANGUAGE REQUIREMENTS:
|
|
50
|
-
- Write fluently in ${language}
|
|
51
|
-
- Use proper grammar and syntax
|
|
52
|
-
- Consider cultural and regional variations
|
|
53
|
-
- Maintain consistency in language usage
|
|
54
25
|
|
|
55
|
-
SAFETY
|
|
26
|
+
SAFETY:
|
|
56
27
|
- Generate appropriate, non-offensive content
|
|
57
28
|
- Avoid harmful or misleading information
|
|
58
29
|
- Ensure factual accuracy when applicable
|
|
59
30
|
- Respect copyright and intellectual property
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
export class TextGenerationService implements ITextGenerationService {
|
|
69
|
-
private promptService: PromptGenerationService;
|
|
70
|
-
|
|
71
|
-
constructor() {
|
|
72
|
-
this.promptService = new PromptGenerationService();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
generateTemplate(config: TextGenerationConfig): Promise<AIPromptResult<AIPromptTemplate>> {
|
|
76
|
-
try {
|
|
77
|
-
if (!this.validateConfig(config)) {
|
|
78
|
-
return Promise.resolve({
|
|
79
|
-
success: false,
|
|
80
|
-
error: 'VALIDATION_ERROR',
|
|
81
|
-
message: 'Invalid text generation configuration'
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const template = this.createTextGenerationTemplate(config);
|
|
86
|
-
return Promise.resolve({ success: true, data: template });
|
|
87
|
-
} catch {
|
|
88
|
-
return Promise.resolve({
|
|
89
|
-
success: false,
|
|
90
|
-
error: 'GENERATION_FAILED',
|
|
91
|
-
message: 'Failed to generate text template'
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async generatePrompt(
|
|
97
|
-
template: AIPromptTemplate,
|
|
98
|
-
config: TextGenerationConfig
|
|
99
|
-
): Promise<AIPromptResult<string>> {
|
|
100
|
-
const parameters = this.getGenerationParameters(config);
|
|
101
|
-
const variables = {
|
|
102
|
-
promptType: config.promptType,
|
|
103
|
-
tone: config.tone,
|
|
104
|
-
length: config.length,
|
|
105
|
-
language: config.language,
|
|
106
|
-
context: config.context || '',
|
|
107
|
-
keywords: config.keywords?.join(', ') || '',
|
|
108
|
-
...parameters,
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
return this.promptService.generateFromTemplate(template, variables);
|
|
31
|
+
`.trim();
|
|
32
|
+
|
|
33
|
+
export class TextGenerationService
|
|
34
|
+
extends BasePromptService<TextGenerationConfig>
|
|
35
|
+
implements ITextGenerationService
|
|
36
|
+
{
|
|
37
|
+
protected getServiceName(): string {
|
|
38
|
+
return 'text generation';
|
|
112
39
|
}
|
|
113
40
|
|
|
114
41
|
validateConfig(config: TextGenerationConfig): boolean {
|
|
@@ -129,113 +56,35 @@ export class TextGenerationService implements ITextGenerationService {
|
|
|
129
56
|
};
|
|
130
57
|
}
|
|
131
58
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const baseTemplate = createTextGenerationBaseTemplate({
|
|
59
|
+
protected buildVariables(config: TextGenerationConfig): Record<string, unknown> {
|
|
60
|
+
return {
|
|
136
61
|
promptType: config.promptType,
|
|
137
62
|
tone: config.tone,
|
|
63
|
+
length: config.length,
|
|
138
64
|
language: config.language,
|
|
139
|
-
|
|
65
|
+
context: config.context || '',
|
|
66
|
+
keywords: config.keywords?.join(', ') || '',
|
|
67
|
+
...this.getGenerationParameters(config),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected createTemplate(config: TextGenerationConfig): AIPromptTemplate {
|
|
72
|
+
const tokens = this.estimateTokens(config);
|
|
140
73
|
|
|
141
|
-
return
|
|
142
|
-
id:
|
|
74
|
+
return this.createTemplateWithDefaults({
|
|
75
|
+
id: `text-generation-${config.promptType}`,
|
|
143
76
|
name: `Text Generation: ${config.promptType}`,
|
|
144
77
|
description: `Generate ${config.promptType} content in ${config.language}`,
|
|
145
78
|
category: 'text-generation',
|
|
146
|
-
template: `${
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
${config.context ? `CONTEXT:
|
|
156
|
-
${config.context}
|
|
157
|
-
|
|
158
|
-
` : ''}${config.keywords && config.keywords.length > 0 ? `KEYWORDS:
|
|
159
|
-
${config.keywords.join(', ')}
|
|
160
|
-
|
|
161
|
-
` : ''}CONTENT REQUIREMENTS:
|
|
162
|
-
- Generate ${config.length} content appropriate for ${config.promptType}
|
|
163
|
-
- Use ${config.tone} tone throughout the text
|
|
164
|
-
- Follow conventions for ${config.promptType} writing
|
|
165
|
-
- Write fluently in ${config.language}
|
|
166
|
-
|
|
167
|
-
STYLE GUIDELINES:
|
|
168
|
-
${this.getStyleGuidelines(config)}
|
|
169
|
-
|
|
170
|
-
GENERATION PARAMETERS:
|
|
171
|
-
- Temperature: ${getTemperature(config.promptType, config.tone)} (creativity level)
|
|
172
|
-
- Max Tokens: ${this.estimateTokens(config)} (content length)
|
|
173
|
-
- Top-P: ${getTopP(config.promptType)} (nucleus sampling)
|
|
174
|
-
- Frequency Penalty: ${config.tone === 'formal' ? 0.3 : 0.1} (repetition reduction)
|
|
175
|
-
- Presence Penalty: ${config.promptType === 'creative' ? 0.2 : 0.1} (new topic encouragement)
|
|
176
|
-
|
|
177
|
-
EXPECTED OUTPUT:
|
|
178
|
-
Professional ${config.promptType} content in ${config.language},
|
|
179
|
-
approximately ${this.estimateTokens(config)} tokens long,
|
|
180
|
-
with ${config.tone} tone and appropriate style.
|
|
181
|
-
`.trim(),
|
|
182
|
-
variables: [],
|
|
183
|
-
safety: {
|
|
184
|
-
contentFilter: true,
|
|
185
|
-
adultContentFilter: true,
|
|
186
|
-
violenceFilter: true,
|
|
187
|
-
hateSpeechFilter: true,
|
|
188
|
-
copyrightFilter: true,
|
|
189
|
-
},
|
|
190
|
-
version: '1.0.0',
|
|
79
|
+
template: `${BASE_TEMPLATE}
|
|
80
|
+
|
|
81
|
+
TYPE: ${config.promptType}
|
|
82
|
+
TONE: ${config.tone}
|
|
83
|
+
LENGTH: ${config.length}
|
|
84
|
+
LANGUAGE: ${config.language}
|
|
85
|
+
TOKENS: ~${tokens}
|
|
86
|
+
${config.context ? `CONTEXT: ${config.context}` : ''}
|
|
87
|
+
${config.keywords?.length ? `KEYWORDS: ${config.keywords.join(', ')}` : ''}`,
|
|
191
88
|
});
|
|
192
89
|
}
|
|
193
|
-
|
|
194
|
-
private getStyleGuidelines(config: TextGenerationConfig): string {
|
|
195
|
-
const guidelines: string[] = [];
|
|
196
|
-
|
|
197
|
-
switch (config.promptType) {
|
|
198
|
-
case 'creative':
|
|
199
|
-
guidelines.push('- Use imaginative and engaging language');
|
|
200
|
-
guidelines.push('- Incorporate vivid descriptions and storytelling');
|
|
201
|
-
break;
|
|
202
|
-
case 'technical':
|
|
203
|
-
guidelines.push('- Use precise terminology and clear explanations');
|
|
204
|
-
guidelines.push('- Maintain logical structure and accuracy');
|
|
205
|
-
break;
|
|
206
|
-
case 'marketing':
|
|
207
|
-
guidelines.push('- Use persuasive and compelling language');
|
|
208
|
-
guidelines.push('- Include clear calls to action');
|
|
209
|
-
break;
|
|
210
|
-
case 'educational':
|
|
211
|
-
guidelines.push('- Present information clearly and progressively');
|
|
212
|
-
guidelines.push('- Include examples and explanations');
|
|
213
|
-
break;
|
|
214
|
-
case 'conversational':
|
|
215
|
-
guidelines.push('- Use natural, approachable language');
|
|
216
|
-
guidelines.push('- Include questions and engagement elements');
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
switch (config.tone) {
|
|
221
|
-
case 'formal':
|
|
222
|
-
guidelines.push('- Maintain professional and respectful language');
|
|
223
|
-
guidelines.push('- Use proper grammar and complete sentences');
|
|
224
|
-
break;
|
|
225
|
-
case 'casual':
|
|
226
|
-
guidelines.push('- Use relaxed, natural language');
|
|
227
|
-
guidelines.push('- Include some conversational elements');
|
|
228
|
-
break;
|
|
229
|
-
case 'friendly':
|
|
230
|
-
guidelines.push('- Use warm and approachable tone');
|
|
231
|
-
guidelines.push('- Include encouraging and positive elements');
|
|
232
|
-
break;
|
|
233
|
-
case 'humorous':
|
|
234
|
-
guidelines.push('- Incorporate appropriate humor and wit');
|
|
235
|
-
guidelines.push('- Maintain lighthearted and engaging style');
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return guidelines.join('\n') || '- Follow standard writing conventions';
|
|
240
|
-
}
|
|
241
|
-
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Prompt Service
|
|
3
|
+
* Abstract class for AI prompt generation services
|
|
4
|
+
* Eliminates code duplication across service implementations
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { AIPromptTemplate } from '../../../domain/entities/AIPromptTemplate';
|
|
8
|
+
import type { AIPromptResult, AIPromptCategory } from '../../../domain/entities/types';
|
|
9
|
+
import type { AIPromptSafety } from '../../../domain/entities/value-objects';
|
|
10
|
+
import { createAIPromptTemplate } from '../../../domain/entities/AIPromptTemplate';
|
|
11
|
+
import { PromptGenerationService } from '../PromptGenerationService';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Default safety configuration for all AI prompt templates
|
|
15
|
+
*/
|
|
16
|
+
export const DEFAULT_PROMPT_SAFETY: AIPromptSafety = {
|
|
17
|
+
contentFilter: true,
|
|
18
|
+
adultContentFilter: true,
|
|
19
|
+
violenceFilter: true,
|
|
20
|
+
hateSpeechFilter: true,
|
|
21
|
+
copyrightFilter: true,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Template creation parameters
|
|
26
|
+
*/
|
|
27
|
+
export interface TemplateParams {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
category: AIPromptCategory;
|
|
32
|
+
template: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Base class for AI prompt generation services
|
|
37
|
+
* Provides common functionality for template generation
|
|
38
|
+
*/
|
|
39
|
+
export abstract class BasePromptService<TConfig> {
|
|
40
|
+
protected readonly promptService: PromptGenerationService;
|
|
41
|
+
|
|
42
|
+
constructor() {
|
|
43
|
+
this.promptService = new PromptGenerationService();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Generate template with standard error handling
|
|
48
|
+
*/
|
|
49
|
+
generateTemplate(config: TConfig): Promise<AIPromptResult<AIPromptTemplate>> {
|
|
50
|
+
try {
|
|
51
|
+
if (!this.validateConfig(config)) {
|
|
52
|
+
return Promise.resolve({
|
|
53
|
+
success: false,
|
|
54
|
+
error: 'VALIDATION_ERROR',
|
|
55
|
+
message: `Invalid ${this.getServiceName()} configuration`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const template = this.createTemplate(config);
|
|
60
|
+
return Promise.resolve({ success: true, data: template });
|
|
61
|
+
} catch {
|
|
62
|
+
return Promise.resolve({
|
|
63
|
+
success: false,
|
|
64
|
+
error: 'GENERATION_FAILED',
|
|
65
|
+
message: `Failed to generate ${this.getServiceName()} template`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Generate prompt from template
|
|
72
|
+
*/
|
|
73
|
+
async generatePrompt(
|
|
74
|
+
template: AIPromptTemplate,
|
|
75
|
+
config: TConfig,
|
|
76
|
+
): Promise<AIPromptResult<string>> {
|
|
77
|
+
const variables = this.buildVariables(config);
|
|
78
|
+
return this.promptService.generateFromTemplate(template, variables);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Create template with default safety config
|
|
83
|
+
*/
|
|
84
|
+
protected createTemplateWithDefaults(params: TemplateParams): AIPromptTemplate {
|
|
85
|
+
return createAIPromptTemplate({
|
|
86
|
+
...params,
|
|
87
|
+
variables: [],
|
|
88
|
+
safety: DEFAULT_PROMPT_SAFETY,
|
|
89
|
+
version: '1.0.0',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Service name for error messages
|
|
95
|
+
*/
|
|
96
|
+
protected abstract getServiceName(): string;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Validate configuration
|
|
100
|
+
*/
|
|
101
|
+
abstract validateConfig(config: TConfig): boolean;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Create the template (service-specific)
|
|
105
|
+
*/
|
|
106
|
+
protected abstract createTemplate(config: TConfig): AIPromptTemplate;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Build variables for prompt generation
|
|
110
|
+
*/
|
|
111
|
+
protected abstract buildVariables(config: TConfig): Record<string, unknown>;
|
|
112
|
+
}
|