@umituz/react-native-ai-generation-content 1.12.1 → 1.12.3

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.
Files changed (43) hide show
  1. package/package.json +6 -2
  2. package/src/domains/prompts/domain/entities/AIPromptTemplate.ts +48 -0
  3. package/src/domains/prompts/domain/entities/BackgroundRemovalConfig.ts +86 -0
  4. package/src/domains/prompts/domain/entities/ColorizationConfig.ts +101 -0
  5. package/src/domains/prompts/domain/entities/FaceSwapConfig.ts +54 -0
  6. package/src/domains/prompts/domain/entities/FuturePredictionConfig.ts +93 -0
  7. package/src/domains/prompts/domain/entities/GeneratedPrompt.ts +32 -0
  8. package/src/domains/prompts/domain/entities/ImageEnhancementConfig.ts +93 -0
  9. package/src/domains/prompts/domain/entities/PhotoRestorationConfig.ts +64 -0
  10. package/src/domains/prompts/domain/entities/StyleTransferConfig.ts +80 -0
  11. package/src/domains/prompts/domain/entities/TextGenerationConfig.ts +100 -0
  12. package/src/domains/prompts/domain/entities/types.ts +27 -0
  13. package/src/domains/prompts/domain/entities/value-objects.ts +33 -0
  14. package/src/domains/prompts/domain/repositories/IAIPromptServices.ts +106 -0
  15. package/src/domains/prompts/domain/repositories/IPromptHistoryRepository.ts +10 -0
  16. package/src/domains/prompts/domain/repositories/ITemplateRepository.ts +11 -0
  17. package/src/domains/prompts/index.ts +318 -0
  18. package/src/domains/prompts/infrastructure/repositories/PromptHistoryRepository.ts +85 -0
  19. package/src/domains/prompts/infrastructure/repositories/TemplateRepository.ts +77 -0
  20. package/src/domains/prompts/infrastructure/services/BackgroundRemovalService.ts +209 -0
  21. package/src/domains/prompts/infrastructure/services/ColorizationService.ts +232 -0
  22. package/src/domains/prompts/infrastructure/services/FaceSwapService.ts +198 -0
  23. package/src/domains/prompts/infrastructure/services/FuturePredictionService.ts +176 -0
  24. package/src/domains/prompts/infrastructure/services/ImageEnhancementService.ts +181 -0
  25. package/src/domains/prompts/infrastructure/services/PhotoRestorationService.ts +160 -0
  26. package/src/domains/prompts/infrastructure/services/PromptGenerationService.ts +59 -0
  27. package/src/domains/prompts/infrastructure/services/StyleTransferService.ts +194 -0
  28. package/src/domains/prompts/infrastructure/services/TextGenerationService.ts +241 -0
  29. package/src/domains/prompts/presentation/hooks/useAIServices.ts +213 -0
  30. package/src/domains/prompts/presentation/hooks/useAsyncState.ts +56 -0
  31. package/src/domains/prompts/presentation/hooks/useFaceSwap.ts +100 -0
  32. package/src/domains/prompts/presentation/hooks/useImageEnhancement.ts +100 -0
  33. package/src/domains/prompts/presentation/hooks/usePhotoRestoration.ts +100 -0
  34. package/src/domains/prompts/presentation/hooks/usePromptGeneration.ts +144 -0
  35. package/src/domains/prompts/presentation/hooks/useStyleTransfer.ts +125 -0
  36. package/src/domains/prompts/presentation/hooks/useTemplateRepository.ts +113 -0
  37. package/src/domains/prompts/presentation/theme/theme.ts +16 -0
  38. package/src/domains/prompts/presentation/theme/types.ts +82 -0
  39. package/src/domains/prompts/presentation/theme/utils.ts +24 -0
  40. package/src/index.ts +6 -0
  41. package/src/presentation/components/GenerationProgressContent.tsx +3 -3
  42. package/src/presentation/components/PendingJobCard.tsx +4 -4
  43. package/src/presentation/components/PendingJobCardActions.tsx +2 -2
@@ -0,0 +1,160 @@
1
+ import type { IPhotoRestorationService } from '../../domain/repositories/IAIPromptServices';
2
+ import type {
3
+ PhotoRestorationConfig,
4
+ } from '../../domain/entities/PhotoRestorationConfig';
5
+ import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
6
+ import type { AIPromptResult } from '../../domain/entities/types';
7
+ import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
8
+ import { validatePhotoRestorationConfig, getQualityLevel } from '../../domain/entities/PhotoRestorationConfig';
9
+ import { PromptGenerationService } from '../services/PromptGenerationService';
10
+
11
+ const createPhotoRestorationBaseTemplate = (config?: {
12
+ targetQuality?: string;
13
+ preserveOriginal?: boolean;
14
+ }): string => {
15
+ const {
16
+ targetQuality = 'high-quality',
17
+ preserveOriginal = true
18
+ } = config || {};
19
+
20
+ return `
21
+ You are an expert AI photo restoration specialist.
22
+ This is a PHOTO RESTORATION task, not image generation.
23
+
24
+ RESTORATION OBJECTIVES:
25
+ - Restore the original photo to ${targetQuality} condition
26
+ - ${preserveOriginal ? 'Preserve the original content and composition' : 'Enhance with creative improvements'}
27
+ - Remove imperfections while maintaining authenticity
28
+ - Recover lost details and enhance overall quality
29
+
30
+ RESTORATION TECHNIQUES:
31
+ - Noise reduction and grain removal
32
+ - Scratch and damage repair
33
+ - Color correction and enhancement
34
+ - Detail sharpening and clarity improvement
35
+ - Exposure and contrast adjustment
36
+
37
+ SAFETY CONSTRAINTS:
38
+ - Do not add content that wasn't originally present
39
+ - Maintain the original subject and composition
40
+ - Avoid over-processing that creates unnatural results
41
+ - Preserve important details and textures
42
+
43
+ QUALITY STANDARDS:
44
+ - Natural, authentic appearance
45
+ - Balanced color reproduction
46
+ - Appropriate level of detail enhancement
47
+ - Clean, professional-grade result
48
+
49
+ OUTPUT:
50
+ A beautifully restored version of the original photo,
51
+ maintaining its character while significantly improving quality.
52
+ `.trim();
53
+ };
54
+
55
+ export class PhotoRestorationService implements IPhotoRestorationService {
56
+ private promptService: PromptGenerationService;
57
+
58
+ constructor() {
59
+ this.promptService = new PromptGenerationService();
60
+ }
61
+
62
+ async generateTemplate(config: PhotoRestorationConfig): Promise<AIPromptResult<AIPromptTemplate>> {
63
+ try {
64
+ if (!this.validateConfig(config)) {
65
+ return {
66
+ success: false,
67
+ error: 'VALIDATION_ERROR',
68
+ message: 'Invalid photo restoration configuration'
69
+ };
70
+ }
71
+
72
+ const template = this.createPhotoRestorationTemplate(config);
73
+ return { success: true, data: template };
74
+ } catch (error) {
75
+ return {
76
+ success: false,
77
+ error: 'GENERATION_FAILED',
78
+ message: 'Failed to generate photo restoration template'
79
+ };
80
+ }
81
+ }
82
+
83
+ async generatePrompt(
84
+ template: AIPromptTemplate,
85
+ config: PhotoRestorationConfig
86
+ ): Promise<AIPromptResult<string>> {
87
+ const variables = {
88
+ severity: config.severity,
89
+ preserveOriginal: config.preserveOriginal,
90
+ enhanceColors: config.enhanceColors,
91
+ removeNoise: config.removeNoise,
92
+ fixBlur: config.fixBlur,
93
+ restoreDetails: config.restoreDetails,
94
+ qualityLevel: getQualityLevel(config.severity),
95
+ };
96
+
97
+ return this.promptService.generateFromTemplate(template, variables);
98
+ }
99
+
100
+ validateConfig(config: PhotoRestorationConfig): boolean {
101
+ return validatePhotoRestorationConfig(config);
102
+ }
103
+
104
+ estimateQuality(config: PhotoRestorationConfig): number {
105
+ let quality = 0.8;
106
+
107
+ if (config.restoreDetails) quality += 0.1;
108
+ if (config.enhanceColors) quality += 0.05;
109
+ if (config.removeNoise) quality += 0.05;
110
+
111
+ const severityMultiplier = getQualityLevel(config.severity);
112
+ return Math.min(quality * severityMultiplier, 1.0);
113
+ }
114
+
115
+ private createPhotoRestorationTemplate(config: PhotoRestorationConfig): AIPromptTemplate {
116
+ const templateId = `photo-restoration-${config.severity}`;
117
+ const qualityDesc = config.severity === 'minor' ? 'subtle restoration' :
118
+ config.severity === 'moderate' ? 'standard restoration' :
119
+ 'deep restoration';
120
+
121
+ const baseTemplate = createPhotoRestorationBaseTemplate({
122
+ targetQuality: qualityDesc,
123
+ preserveOriginal: config.preserveOriginal,
124
+ });
125
+
126
+ return createAIPromptTemplate({
127
+ id: templateId,
128
+ name: `Photo Restoration: ${config.severity}`,
129
+ description: `Restore photos with ${qualityDesc}`,
130
+ category: 'photo-restoration',
131
+ template: `${baseTemplate}
132
+
133
+ RESTORATION SEVERITY:
134
+ ${config.severity}
135
+
136
+ SPECIFIC REQUIREMENTS:
137
+ - ${config.removeNoise ? 'Remove noise and grain' : 'Maintain texture character'}
138
+ - ${config.fixBlur ? 'Fix blur and sharpen details' : 'Preserve original sharpness'}
139
+ - ${config.enhanceColors ? 'Enhance color vibrancy' : 'Maintain original colors'}
140
+ - ${config.restoreDetails ? 'Recover lost details' : 'Preserve current detail level'}
141
+
142
+ QUALITY TARGET:
143
+ ${getQualityLevel(config.severity) * 100}% quality improvement expected.
144
+
145
+ OUTPUT:
146
+ A professionally restored photo with ${qualityDesc},
147
+ ready for display or further processing.
148
+ `.trim(),
149
+ variables: [],
150
+ safety: {
151
+ contentFilter: true,
152
+ adultContentFilter: true,
153
+ violenceFilter: true,
154
+ hateSpeechFilter: true,
155
+ copyrightFilter: true,
156
+ },
157
+ version: '1.0.0',
158
+ });
159
+ }
160
+ }
@@ -0,0 +1,59 @@
1
+ import type { IPromptGenerationService } from '../../domain/repositories/IAIPromptServices';
2
+ import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
3
+ import type { AIPromptResult, AIPromptError } from '../../domain/entities/types';
4
+
5
+ export class PromptGenerationService implements IPromptGenerationService {
6
+ generateFromTemplate(
7
+ template: AIPromptTemplate,
8
+ variables: Record<string, unknown>
9
+ ): Promise<AIPromptResult<string>> {
10
+ return new Promise((resolve) => {
11
+ try {
12
+ const validation = this.validateVariables(template, variables);
13
+ if (!validation.success) {
14
+ resolve(validation as AIPromptResult<string>);
15
+ return;
16
+ }
17
+
18
+ const generatedText = this.replaceTemplateVariables(template.template, variables);
19
+ resolve({ success: true, data: generatedText });
20
+ } catch (error) {
21
+ resolve({
22
+ success: false,
23
+ error: 'GENERATION_FAILED',
24
+ message: 'Failed to generate prompt'
25
+ });
26
+ }
27
+ });
28
+ }
29
+
30
+ validateVariables(
31
+ template: AIPromptTemplate,
32
+ variables: Record<string, unknown>
33
+ ): AIPromptResult<void> {
34
+ for (const variable of template.variables) {
35
+ if (variable.required && !(variable.name in variables)) {
36
+ return {
37
+ success: false,
38
+ error: 'INVALID_VARIABLES',
39
+ message: `Required variable ${variable.name} is missing`
40
+ };
41
+ }
42
+ }
43
+ return { success: true, data: undefined };
44
+ }
45
+
46
+ replaceTemplateVariables(
47
+ template: string,
48
+ variables: Record<string, unknown>
49
+ ): string {
50
+ let result = template;
51
+
52
+ Object.entries(variables).forEach(([key, value]) => {
53
+ const regex = new RegExp(`\\$\\{${key}\\}`, 'g');
54
+ result = result.replace(regex, String(value || ''));
55
+ });
56
+
57
+ return result;
58
+ }
59
+ }
@@ -0,0 +1,194 @@
1
+ import type { IStyleTransferService } from '../../domain/repositories/IAIPromptServices';
2
+ import type {
3
+ StyleTransferConfig,
4
+ } from '../../domain/entities/StyleTransferConfig';
5
+ import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
6
+ import type { AIPromptResult } from '../../domain/entities/types';
7
+ import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
8
+ import {
9
+ validateStyleTransferConfig,
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 `
25
+ You are an expert AI style transfer specialist.
26
+ This is a STYLE TRANSFER task, applying artistic styles while maintaining content.
27
+
28
+ STYLE TRANSFER PRINCIPLES:
29
+ - Apply target artistic style to the image
30
+ - ${preserveContent ? 'Preserve original content and composition' : 'Allow creative reinterpretation'}
31
+ - Maintain key features and subject recognition
32
+ - Balance artistic expression with clarity
33
+
34
+ ARTISTIC MODE: ${artisticMode}
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:
44
+ - Smooth style transitions across the image
45
+ - Appropriate detail preservation based on style
46
+ - Consistent artistic treatment
47
+ - Professional quality output
48
+
49
+ CONTENT PRESERVATION:
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:
55
+ - Do not add inappropriate elements
56
+ - Maintain appropriate content standards
57
+ - Preserve important visual information
58
+ - Avoid destructive transformations
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
+ }
74
+
75
+ async generateTemplate(config: StyleTransferConfig): Promise<AIPromptResult<AIPromptTemplate>> {
76
+ try {
77
+ if (!this.validateConfig(config)) {
78
+ return {
79
+ success: false,
80
+ error: 'VALIDATION_ERROR',
81
+ message: 'Invalid style transfer configuration'
82
+ };
83
+ }
84
+
85
+ const template = this.createStyleTransferTemplate(config);
86
+ return { success: true, data: template };
87
+ } catch (error) {
88
+ return {
89
+ success: false,
90
+ error: 'GENERATION_FAILED',
91
+ message: 'Failed to generate style transfer template'
92
+ };
93
+ }
94
+ }
95
+
96
+ async generatePrompt(
97
+ template: AIPromptTemplate,
98
+ config: StyleTransferConfig
99
+ ): Promise<AIPromptResult<string>> {
100
+ const variables = {
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
+ };
109
+
110
+ return this.promptService.generateFromTemplate(template, variables);
111
+ }
112
+
113
+ validateConfig(config: StyleTransferConfig): boolean {
114
+ return validateStyleTransferConfig(config);
115
+ }
116
+
117
+ async getAvailableStyles(): Promise<string[]> {
118
+ return Promise.resolve([...this.availableStyles]);
119
+ }
120
+
121
+ registerStyle(style: string): void {
122
+ if (!this.availableStyles.includes(style)) {
123
+ this.availableStyles.push(style);
124
+ }
125
+ }
126
+
127
+ registerStyles(styles: string[]): void {
128
+ styles.forEach(style => this.registerStyle(style));
129
+ }
130
+
131
+ private initializeDefaultStyles(): void {
132
+ this.availableStyles = [
133
+ 'Impressionism',
134
+ 'Cubism',
135
+ 'Surrealism',
136
+ 'Pop Art',
137
+ 'Watercolor',
138
+ 'Oil Painting',
139
+ 'Pencil Sketch',
140
+ 'Anime/Manga',
141
+ 'Vintage Film',
142
+ 'Cyberpunk',
143
+ 'Steampunk',
144
+ ];
145
+ }
146
+
147
+ private createStyleTransferTemplate(config: StyleTransferConfig): AIPromptTemplate {
148
+ const templateId = `style-transfer-${config.targetStyle.toLowerCase().replace(/\s+/g, '-')}`;
149
+
150
+ const baseTemplate = createStyleTransferBaseTemplate({
151
+ artisticMode: config.artisticMode,
152
+ preserveContent: config.preserveContent,
153
+ });
154
+
155
+ return createAIPromptTemplate({
156
+ id: templateId,
157
+ name: `Style Transfer: ${config.targetStyle}`,
158
+ description: `Apply ${config.targetStyle} artistic style with ${config.artisticMode} mode`,
159
+ category: 'style-transfer',
160
+ template: `${baseTemplate}
161
+
162
+ TARGET STYLE:
163
+ ${config.targetStyle}
164
+
165
+ STYLE TRANSFER PARAMETERS:
166
+ - Style Strength: ${getStyleStrengthValue(config.styleStrength)} (${Math.round(config.styleStrength * 100)}%)
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',
192
+ });
193
+ }
194
+ }
@@ -0,0 +1,241 @@
1
+ import type { ITextGenerationService } from '../../domain/repositories/IAIPromptServices';
2
+ import type {
3
+ TextGenerationConfig,
4
+ } from '../../domain/entities/TextGenerationConfig';
5
+ import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
6
+ import type { AIPromptResult } from '../../domain/entities/types';
7
+ import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
8
+ import {
9
+ validateTextGenerationConfig,
10
+ getTokenCount,
11
+ getTemperature,
12
+ getTopP
13
+ } from '../../domain/entities/TextGenerationConfig';
14
+ import { PromptGenerationService } from '../services/PromptGenerationService';
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 || {};
26
+
27
+ return `
28
+ You are an expert text generation specialist.
29
+ This is a TEXT GENERATION task with specific requirements.
30
+
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
+ CONTENT STANDARDS:
38
+ - Clear, coherent, and well-structured text
39
+ - Appropriate for the specified tone and purpose
40
+ - 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
+
55
+ SAFETY AND QUALITY:
56
+ - Generate appropriate, non-offensive content
57
+ - Avoid harmful or misleading information
58
+ - Ensure factual accuracy when applicable
59
+ - Respect copyright and intellectual property
60
+
61
+ OUTPUT:
62
+ Professional ${promptType} content in ${language},
63
+ written with ${tone} tone,
64
+ meeting all specified requirements.
65
+ `.trim();
66
+ };
67
+
68
+ export class TextGenerationService implements ITextGenerationService {
69
+ private promptService: PromptGenerationService;
70
+
71
+ constructor() {
72
+ this.promptService = new PromptGenerationService();
73
+ }
74
+
75
+ async generateTemplate(config: TextGenerationConfig): Promise<AIPromptResult<AIPromptTemplate>> {
76
+ try {
77
+ if (!this.validateConfig(config)) {
78
+ return {
79
+ success: false,
80
+ error: 'VALIDATION_ERROR',
81
+ message: 'Invalid text generation configuration'
82
+ };
83
+ }
84
+
85
+ const template = this.createTextGenerationTemplate(config);
86
+ return { success: true, data: template };
87
+ } catch (error) {
88
+ return {
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);
112
+ }
113
+
114
+ validateConfig(config: TextGenerationConfig): boolean {
115
+ return validateTextGenerationConfig(config);
116
+ }
117
+
118
+ estimateTokens(config: TextGenerationConfig): number {
119
+ return getTokenCount(config.length);
120
+ }
121
+
122
+ getGenerationParameters(config: TextGenerationConfig): Record<string, number> {
123
+ return {
124
+ temperature: getTemperature(config.promptType, config.tone),
125
+ maxTokens: this.estimateTokens(config),
126
+ topP: getTopP(config.promptType),
127
+ frequencyPenalty: config.tone === 'formal' ? 0.3 : 0.1,
128
+ presencePenalty: config.promptType === 'creative' ? 0.2 : 0.1,
129
+ };
130
+ }
131
+
132
+ private createTextGenerationTemplate(config: TextGenerationConfig): AIPromptTemplate {
133
+ const templateId = `text-generation-${config.promptType}`;
134
+
135
+ const baseTemplate = createTextGenerationBaseTemplate({
136
+ promptType: config.promptType,
137
+ tone: config.tone,
138
+ language: config.language,
139
+ });
140
+
141
+ return createAIPromptTemplate({
142
+ id: templateId,
143
+ name: `Text Generation: ${config.promptType}`,
144
+ description: `Generate ${config.promptType} content in ${config.language}`,
145
+ category: 'text-generation',
146
+ template: `${baseTemplate}
147
+
148
+ GENERATION PARAMETERS:
149
+ - Prompt Type: ${config.promptType}
150
+ - Tone: ${config.tone}
151
+ - Length: ${config.length}
152
+ - Language: ${config.language}
153
+ - Estimated Tokens: ${this.estimateTokens(config)}
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',
191
+ });
192
+ }
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
+ }