Skip to content

Commit

Permalink
opt.: claude title generation prompt (#37)
Browse files Browse the repository at this point in the history
Fixes #36
  • Loading branch information
lollipopkit authored Jun 21, 2024
1 parent 9be4b06 commit 0a76ac0
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/core/util/chat_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ abstract final class ChatTitleUtil {

static const userCotentLocator = 'GPTBOX>>>';

static final claudeEndReg = RegExp(r'\[\]\(ID:\d+\|UUID:\S+');

static const titlePrompt = '''
Generate a title for the user content behind `$userCotentLocator` with requirements:
0. the language of the generated title should be the same as the user content
1. <= 10 characters if Chinese, Japanese, Korean, etc.
2. <= $_maxLen letters if English, German, French, etc.
3. the title should be meaningful, concise, no additional punctuation and only title itself.
0. you are generating a title, not a content.
1. the language of the generated title should be the same as the user content
2. <= 10 characters if Chinese, Japanese, Korean, etc.
3. <= $_maxLen letters if English, German, French, etc.
4. the title should be meaningful, concise, no additional punctuation and only title itself.
$userCotentLocator''';

/// TODO: Implement this method
static String getTitlePromptByModel(String model) {
return switch (model) {
_ when model.startsWith('claude') => '',
_ => titlePrompt,
};
}

static final _punctionsRm = RegExp('[“”]');

static String prettify(String title) {
Expand All @@ -27,6 +38,11 @@ $userCotentLocator''';
title = title.substring(0, _maxLen);
}

final claudeMatch = claudeEndReg.firstMatch(title);
if (claudeMatch != null) {
title = title.substring(0, claudeMatch.start);
}

return title;
}
}

0 comments on commit 0a76ac0

Please sign in to comment.