forked from linux-china/chatgpt-spring-boot-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromptManager.java
More file actions
25 lines (20 loc) · 922 Bytes
/
PromptManager.java
File metadata and controls
25 lines (20 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package org.mvnsearch.chatgpt.demo.service;
import org.jetbrains.annotations.PropertyKey;
import java.text.MessageFormat;
import java.util.ResourceBundle;
public class PromptManager {
private static final String BUNDLE_FQN = "demo.prompts";
// Use ResourceBundle instead of Properties to support different prompts in different languages
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_FQN);
public static String prompt(@PropertyKey(resourceBundle = BUNDLE_FQN) String key, Object... params) {
if (RESOURCE_BUNDLE.containsKey(key)) {
String prompt = RESOURCE_BUNDLE.getString(key);
if (params != null && params.length > 0 && prompt.indexOf('{') >= 0) {
prompt = MessageFormat.format(prompt, params);
}
return prompt;
} else {
return "!!!" + key + "!!!";
}
}
}