File tree Expand file tree Collapse file tree
src/main/java/com/phantoms/phantomsbackend/common/LLM Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414@ Slf4j
1515@ Component
1616public class FF14Prompt {
17- private static String SYSTEM_PROMPT ;
18-
19- @ PostConstruct
20- public void init () {
21- try {
22- ClassPathResource resource = new ClassPathResource ("prompts/ff14-translator-prompt.md" );
23- Path path = Paths .get (resource .getURI ());
24- SYSTEM_PROMPT = Files .readString (path , StandardCharsets .UTF_8 );
25- log .info ("FF14翻译提示词加载成功,长度: {} 字符" , SYSTEM_PROMPT .length ());
26- } catch (IOException e ) {
27- log .error ("加载FF14翻译提示词失败" , e );
28- SYSTEM_PROMPT = "你是最终幻想14专用翻译器。" ;
29- }
30- }
17+ private static volatile String SYSTEM_PROMPT ;
18+ private static final Object LOCK = new Object ();
3119
3220 public static String getSystemPrompt () {
21+ // 懒加载:首次调用时才加载
22+ if (SYSTEM_PROMPT == null ) {
23+ synchronized (LOCK ) {
24+ if (SYSTEM_PROMPT == null ) {
25+ try {
26+ ClassPathResource resource = new ClassPathResource ("prompts/ff14-translator-prompt.md" );
27+ Path path = Paths .get (resource .getURI ());
28+ SYSTEM_PROMPT = Files .readString (path , StandardCharsets .UTF_8 );
29+ log .info ("FF14翻译提示词加载成功,长度: {} 字符" , SYSTEM_PROMPT .length ());
30+ } catch (IOException e ) {
31+ log .error ("加载FF14翻译提示词失败" , e );
32+ SYSTEM_PROMPT = "你是最终幻想14专用翻译器。" ;
33+ }
34+ }
35+ }
36+ }
3337 return SYSTEM_PROMPT ;
3438 }
3539}
You can’t perform that action at this time.
0 commit comments