@@ -6,7 +6,17 @@ import com.shifthackz.aisdv1.presentation.model.ExtraType
66
77object ExtrasFormatter {
88
9- fun determineExtraType (input : String? ) : ExtraType ? {
9+ /* *
10+ * Determines the type of extra based on the input string.
11+ *
12+ * This function checks if the input string matches the format of any [ExtraType].
13+ * The format is expected to be "<TYPE:...>" where TYPE is the raw value of an [ExtraType].
14+ *
15+ * @param input The string to be checked. Can be null.
16+ *
17+ * @return The matching [ExtraType] if found, or null if the input is null, blank, or doesn't match any type.
18+ */
19+ fun determineExtraType (input : String? ): ExtraType ? {
1020 if (input.isNullOrBlank()) return null
1121 ExtraType .entries.forEach { type ->
1222 if (input.startsWith(" <${type.raw} :" ) && input.endsWith(" >" )) {
@@ -16,6 +26,16 @@ object ExtrasFormatter {
1626 return null
1727 }
1828
29+ /* *
30+ * Checks if a specific embedding is present in the given prompt.
31+ *
32+ * This function splits the prompt into individual keywords and checks if the specified embedding
33+ * is present among these keywords.
34+ *
35+ * @param prompt The input prompt string to search within. It's expected to be a comma or space-separated list of keywords.
36+ * @param embedding The specific embedding string to search for in the prompt.
37+ * @return Boolean value indicating whether the embedding is present (true) or not (false) in the prompt.
38+ */
1939 fun isEmbeddingPresentInPrompt (
2040 prompt : String ,
2141 embedding : String ,
@@ -26,6 +46,17 @@ object ExtrasFormatter {
2646 return keywords.contains(embedding)
2747 }
2848
49+ /* *
50+ * Checks if a specific extra is present in the given prompt.
51+ *
52+ * This function splits the prompt into individual keywords and checks if any keyword
53+ * starts with the specified extra type and alias.
54+ *
55+ * @param prompt The input prompt string to search within. It's expected to be a comma or space-separated list of keywords.
56+ * @param loraAlias The specific alias of the extra to search for in the prompt.
57+ * @param type The type of extra to check for. Defaults to [ExtraType.Lora].
58+ * @return Boolean value indicating whether the extra is present (true) or not (false) in the prompt.
59+ */
2960 fun isExtraPresentInPrompt (
3061 prompt : String ,
3162 loraAlias : String ,
@@ -37,6 +68,20 @@ object ExtrasFormatter {
3768 return keywords.any { it.startsWith(" <${type.raw} :$loraAlias :" ) }
3869 }
3970
71+ /* *
72+ * Checks if a specific extra with its value is present in the given prompt.
73+ *
74+ * This function searches for an extra of the specified type and alias within the prompt,
75+ * and if found, extracts its value.
76+ *
77+ * @param prompt The input prompt string to search within. It's expected to be a comma or space-separated list of keywords.
78+ * @param loraAlias The specific alias of the extra to search for in the prompt.
79+ * @param type The type of extra to check for. Defaults to [ExtraType.Lora].
80+ *
81+ * @return A [Pair] where:
82+ * - The first element is a [Boolean] indicating whether the extra is present (true) or not (false) in the prompt.
83+ * - The second element is a [String] containing the value of the extra if found, or null if not found.
84+ */
4085 fun isExtraWithValuePresentInPrompt (
4186 prompt : String ,
4287 loraAlias : String ,
@@ -54,6 +99,18 @@ object ExtrasFormatter {
5499 .lastOrNull()
55100 }
56101
102+ /* *
103+ * Toggles the presence of a specific extra prompt alias in the given prompt string.
104+ *
105+ * If the extra prompt alias is not present in the prompt, it adds it with a default value of 1.
106+ * If the extra prompt alias is already present, it removes it from the prompt.
107+ *
108+ * @param prompt The input prompt string to modify. It's expected to be a comma or space-separated list of keywords.
109+ * @param loraAlias The specific alias of the extra to toggle in the prompt.
110+ * @param type The type of extra to toggle. Defaults to [ExtraType.Lora].
111+ *
112+ * @return A new string with the extra prompt alias either added or removed, depending on its initial presence.
113+ */
57114 fun toggleExtraPromptAlias (
58115 prompt : String ,
59116 loraAlias : String ,
@@ -73,6 +130,17 @@ object ExtrasFormatter {
73130 return prompt.replaceFirst(keywords[index], " " ).trim().trim(' ,' )
74131 }
75132
133+ /* *
134+ * Toggles the presence of a specific embedding in the given prompt string.
135+ *
136+ * If the embedding is not present in the prompt, it adds it.
137+ * If the embedding is already present, it removes it from the prompt.
138+ *
139+ * @param prompt The input prompt string to modify. It's expected to be a comma or space-separated list of keywords.
140+ * @param embedding The specific embedding to toggle in the prompt.
141+ *
142+ * @return A new string with the embedding either added or removed, depending on its initial presence.
143+ */
76144 fun toggleEmbedding (
77145 prompt : String ,
78146 embedding : String ,
0 commit comments