Skip to content

Commit 8b1eb49

Browse files
authored
chore: import new prompts and add featured category (#7859)
* chore: mark prompts as featured * chore: implement is featured list * chore: implement categories * chore: remove learning category
1 parent 4a4ee79 commit 8b1eb49

File tree

6 files changed

+688
-79
lines changed

6 files changed

+688
-79
lines changed

frontend/appflowy_flutter/assets/built_in_prompts.json

Lines changed: 640 additions & 45 deletions
Large diffs are not rendered by default.

frontend/appflowy_flutter/lib/ai/service/ai_entities.dart

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ enum AiPromptCategory {
122122
business,
123123
@JsonValue("marketing")
124124
marketing,
125-
@JsonValue("learning")
126-
learning,
127125
@JsonValue("travel")
128126
travel,
129127
@JsonValue("contentSeo")
@@ -145,7 +143,17 @@ enum AiPromptCategory {
145143
@JsonValue("caseStudies")
146144
caseStudies,
147145
@JsonValue("salesCopy")
148-
salesCopy;
146+
salesCopy,
147+
@JsonValue("education")
148+
education,
149+
@JsonValue("work")
150+
work,
151+
@JsonValue("podcastProduction")
152+
podcastProduction,
153+
@JsonValue("copyWriting")
154+
copyWriting,
155+
@JsonValue("customerSuccess")
156+
customerSuccess;
149157

150158
String get i18n {
151159
return switch (this) {
@@ -155,7 +163,6 @@ enum AiPromptCategory {
155163
healthAndFitness => LocaleKeys.ai_customPrompt_healthAndFitness.tr(),
156164
business => LocaleKeys.ai_customPrompt_business.tr(),
157165
marketing => LocaleKeys.ai_customPrompt_marketing.tr(),
158-
learning => LocaleKeys.ai_customPrompt_learning.tr(),
159166
travel => LocaleKeys.ai_customPrompt_travel.tr(),
160167
contentSeo => LocaleKeys.ai_customPrompt_contentSeo.tr(),
161168
emailMarketing => LocaleKeys.ai_customPrompt_emailMarketing.tr(),
@@ -167,6 +174,11 @@ enum AiPromptCategory {
167174
strategy => LocaleKeys.ai_customPrompt_strategy.tr(),
168175
caseStudies => LocaleKeys.ai_customPrompt_caseStudies.tr(),
169176
salesCopy => LocaleKeys.ai_customPrompt_salesCopy.tr(),
177+
education => LocaleKeys.ai_customPrompt_education.tr(),
178+
work => LocaleKeys.ai_customPrompt_work.tr(),
179+
podcastProduction => LocaleKeys.ai_customPrompt_podcastProduction.tr(),
180+
copyWriting => LocaleKeys.ai_customPrompt_copyWriting.tr(),
181+
customerSuccess => LocaleKeys.ai_customPrompt_customerSuccess.tr(),
170182
};
171183
}
172184
}
@@ -190,12 +202,16 @@ class AiPrompt extends Equatable {
190202
final String id;
191203
final String name;
192204
final String content;
205+
@JsonKey(
206+
unknownEnumValue: AiPromptCategory.other,
207+
defaultValue: AiPromptCategory.other,
208+
)
193209
final AiPromptCategory category;
194210
@JsonKey(defaultValue: "")
195211
final String example;
196212
@JsonKey(defaultValue: false)
197213
final bool isFeatured;
198214

199215
@override
200-
List<Object?> get props => [id, name, content, category];
216+
List<Object?> get props => [id, name, content, category, example, isFeatured];
201217
}

frontend/appflowy_flutter/lib/ai/service/ai_prompt_selector_cubit.dart

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ class AiPromptSelectorCubit extends Cubit<AiPromptSelectorState> {
2929

3030
void _loadPrompts() async {
3131
availablePrompts.addAll(await _aiService.getBuiltInPrompts());
32-
final visiblePrompts = _getFilteredPrompts(availablePrompts);
32+
final featuredPrompts =
33+
availablePrompts.where((prompt) => prompt.isFeatured);
34+
final visiblePrompts = _getFilteredPrompts(featuredPrompts);
3335
emit(
3436
AiPromptSelectorState.ready(
3537
visiblePrompts: visiblePrompts,
3638
showCustomPrompts: false,
37-
isFeaturedCategorySelected: false,
39+
isFeaturedCategorySelected: true,
3840
selectedPromptId: visiblePrompts.firstOrNull?.id,
3941
selectedCategory: null,
4042
favoritePrompts: [],
@@ -45,12 +47,13 @@ class AiPromptSelectorCubit extends Cubit<AiPromptSelectorState> {
4547
void selectFeaturedCategory() {
4648
state.maybeMap(
4749
ready: (readyState) {
50+
final prompts = availablePrompts.where((prompt) => prompt.isFeatured);
51+
final visiblePrompts = _getFilteredPrompts(prompts);
4852
emit(
4953
readyState.copyWith(
50-
// TODO(RS): Add logic to filter prompts based on the featured category
51-
// visiblePrompts: prompts,
54+
visiblePrompts: visiblePrompts,
5255
isFeaturedCategorySelected: true,
53-
// selectedPromptId: prompts.firstOrNull?.id,
56+
selectedPromptId: visiblePrompts.firstOrNull?.id,
5457
),
5558
);
5659
},
@@ -136,22 +139,13 @@ class AiPromptSelectorCubit extends Cubit<AiPromptSelectorState> {
136139
);
137140
}
138141

139-
AiPrompt? get selectedPrompt {
140-
return state.maybeMap(
141-
ready: (readyState) {
142-
return readyState.visiblePrompts.firstWhereOrNull(
143-
(prompt) => prompt.id == readyState.selectedPromptId,
144-
);
145-
},
146-
orElse: () => null,
147-
);
148-
}
149-
150142
void _filterTextChanged() {
151143
state.maybeMap(
152144
ready: (readyState) {
153145
final unfilteredPrompts = readyState.selectedCategory == null
154-
? availablePrompts
146+
? readyState.isFeaturedCategorySelected
147+
? availablePrompts.where((prompt) => prompt.isFeatured)
148+
: availablePrompts
155149
: availablePrompts.where(
156150
(prompt) => prompt.category == readyState.selectedCategory,
157151
);

frontend/appflowy_flutter/lib/ai/service/appflowy_ai_service.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ abstract class AIRepository {
4545
}
4646

4747
class AppFlowyAIService implements AIRepository {
48-
final List<AiPrompt> _builtInPrompts = [];
49-
5048
@override
5149
Future<(String, CompletionStream)?> streamCompletion({
5250
String? objectId,
@@ -98,10 +96,6 @@ class AppFlowyAIService implements AIRepository {
9896

9997
@override
10098
Future<List<AiPrompt>> getBuiltInPrompts() async {
101-
if (_builtInPrompts.isNotEmpty) {
102-
return _builtInPrompts;
103-
}
104-
10599
final prompts = <AiPrompt>[];
106100

107101
try {
@@ -120,8 +114,6 @@ class AppFlowyAIService implements AIRepository {
120114
Log.error(e);
121115
}
122116

123-
_builtInPrompts.addAll(prompts);
124-
125117
return prompts;
126118
}
127119

frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_category_list.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class _AiPromptCategoryListState extends State<AiPromptCategoryList> {
4444
_buildCategoryItem(context, AiPromptCategory.writing),
4545
_buildCategoryItem(context, AiPromptCategory.business),
4646
_buildCategoryItem(context, AiPromptCategory.marketing),
47-
_buildCategoryItem(context, AiPromptCategory.learning),
4847
_buildCategoryItem(
4948
context,
5049
AiPromptCategory.healthAndFitness,
@@ -60,6 +59,15 @@ class _AiPromptCategoryListState extends State<AiPromptCategoryList> {
6059
_buildCategoryItem(context, AiPromptCategory.strategy),
6160
_buildCategoryItem(context, AiPromptCategory.caseStudies),
6261
_buildCategoryItem(context, AiPromptCategory.salesCopy),
62+
_buildCategoryItem(context, AiPromptCategory.education),
63+
_buildCategoryItem(context, AiPromptCategory.work),
64+
_buildCategoryItem(
65+
context,
66+
AiPromptCategory.podcastProduction,
67+
),
68+
_buildCategoryItem(context, AiPromptCategory.copyWriting),
69+
_buildCategoryItem(context, AiPromptCategory.customerSuccess),
70+
_buildCategoryItem(context, AiPromptCategory.other),
6371
],
6472
),
6573
),

frontend/resources/translations/en.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,7 +3331,6 @@
33313331
"healthAndFitness": "Health & fitness",
33323332
"business": "Business",
33333333
"marketing": "Marketing",
3334-
"learning": "Learning",
33353334
"travel": "Travel",
33363335
"others": "Other",
33373336
"prompt": "Prompt",
@@ -3346,7 +3345,12 @@
33463345
"socialMedia": "Social Media",
33473346
"strategy": "Strategy",
33483347
"caseStudies": "Case Studies",
3349-
"salesCopy": "Sales Copy"
3348+
"salesCopy": "Sales Copy",
3349+
"education": "Education",
3350+
"work": "Work",
3351+
"podcastProduction": "Podcast Production",
3352+
"copyWriting": "Copy Writing",
3353+
"customerSuccess": "Customer Success"
33503354
}
33513355
},
33523356
"autoUpdate": {
@@ -3377,4 +3381,4 @@
33773381
"rewrite": "Rewrite",
33783382
"insertBelow": "Insert below"
33793383
}
3380-
}
3384+
}

0 commit comments

Comments
 (0)