42
42
import java .sql .*;
43
43
import java .util .HashMap ;
44
44
import java .util .Map ;
45
+
45
46
import org .springframework .http .*;
46
47
import org .springframework .stereotype .Service ;
47
48
import org .springframework .web .multipart .MultipartFile ;
49
+
50
+ import java .nio .file .Files ;
51
+ import java .nio .file .Paths ;
52
+ import java .nio .charset .StandardCharsets ;
53
+
48
54
@ Controller
49
55
@ RequestMapping ("/aiholo" )
50
56
// @CrossOrigin(origins = "*")
@@ -54,7 +60,24 @@ public class AIHoloController {
54
60
private static final String SANDBOX_API_URL = System .getenv ("SANDBOX_API_URL" );
55
61
private static final String AI_OPTIMZER = System .getenv ("AI_OPTIMZER" );
56
62
static final String AUDIO_DIR_PATH = System .getenv ("AUDIO_DIR_PATH" );
57
- static int currentAnswerIntro = 0 ;
63
+ private static int currentAnswerIntro = 0 ;
64
+ private static String aiholo_prompt_additions = "" ;
65
+
66
+ static {
67
+ // Check for aiholo_prompt_additions.txt in AUDIO_DIR_PATH at startup
68
+ if (AUDIO_DIR_PATH != null ) {
69
+ try {
70
+ java .nio .file .Path additionsPath = Paths .get (AUDIO_DIR_PATH , "aiholo_prompt_additions.txt" );
71
+ if (Files .exists (additionsPath )) {
72
+ aiholo_prompt_additions = new String (Files .readAllBytes (additionsPath ), StandardCharsets .UTF_8 ).trim ();
73
+ System .out .println ("Loaded aiholo_prompt_additions: " + aiholo_prompt_additions );
74
+ }
75
+ } catch (Exception e ) {
76
+ System .err .println ("Could not load aiholo_prompt_additions.txt: " + e .getMessage ());
77
+ }
78
+ }
79
+ }
80
+
58
81
private static final String DEFAULT_LANGUAGE_CODE = "es-ES" ;
59
82
private static final String DEFAULT_VOICE_NAME = "es-ES-Wavenet-D" ;
60
83
private final static String sql = """
@@ -94,38 +117,38 @@ private void startInactivityMonitor() {
94
117
95
118
@ GetMapping ("" )
96
119
public String home (@ RequestParam (value = "languageCode" , defaultValue = "en-US" ) String languageCode , Model model ) {
97
- System .out .println ("AIHolo root languageCode = " + languageCode );
120
+ System .out .println ("AIHolo root languageCode = " + languageCode );
98
121
this .languageCode = languageCode ;
99
122
model .addAttribute ("languageCode" , languageCode );
100
123
if (languageCode .equals ("pt-BR" ))
101
124
model .addAttribute ("voiceName" , "pt-BR-Wavenet-D" );
102
125
else if (languageCode .equals ("es-ES" ))
103
126
model .addAttribute ("voiceName" , "es-ES-Wavenet-D" );
104
- else if (languageCode .equals ("zh-SG" ) )
127
+ else if (languageCode .equals ("zh-SG" ))
105
128
model .addAttribute ("voiceName" , "cmn-CN-Wavenet-A" );
106
- else if (languageCode .equals ("de-DE" ) )
129
+ else if (languageCode .equals ("de-DE" ))
107
130
model .addAttribute ("voiceName" , "de-DE-Wavenet-A" );
108
- else if (languageCode .equals ("es-MX" ) )
131
+ else if (languageCode .equals ("es-MX" ))
109
132
model .addAttribute ("voiceName" , "es-US-Wavenet-A" );
110
- else if (languageCode .equals ("it-IT" ) )
133
+ else if (languageCode .equals ("it-IT" ))
111
134
model .addAttribute ("voiceName" , "it-IT-Wavenet-A" );
112
- else if (languageCode .equals ("fr-FR" ) )
135
+ else if (languageCode .equals ("fr-FR" ))
113
136
model .addAttribute ("voiceName" , "fr-FR-Wavenet-A" );
114
- else if (languageCode .equals ("ro-RO" ) )
137
+ else if (languageCode .equals ("ro-RO" ))
115
138
model .addAttribute ("voiceName" , "ro-RO-Wavenet-A" );
116
- else if (languageCode .equals ("en-AU" ) )
139
+ else if (languageCode .equals ("en-AU" ))
117
140
model .addAttribute ("voiceName" , "en-AU-Wavenet-A" );
118
- else if (languageCode .equals ("ga-GA" ) )
141
+ else if (languageCode .equals ("ga-GA" ))
119
142
model .addAttribute ("voiceName" , "ga-GA-Wavenet-A" );
120
- else if (languageCode .equals ("ar-AE" ) )
143
+ else if (languageCode .equals ("ar-AE" ))
121
144
model .addAttribute ("voiceName" , "ar-AE-Wavenet-A" );
122
- else if (languageCode .equals ("ja-JP" ) )
145
+ else if (languageCode .equals ("ja-JP" ))
123
146
model .addAttribute ("voiceName" , "ja-JP-Wavenet-A" );
124
- else if (languageCode .equals ("hi-IN" ) )
147
+ else if (languageCode .equals ("hi-IN" ))
125
148
model .addAttribute ("voiceName" , "hi-IN-Wavenet-A" );
126
- else if (languageCode .equals ("he-IL" ) )
149
+ else if (languageCode .equals ("he-IL" ))
127
150
model .addAttribute ("voiceName" , "he-IL-Wavenet-A" );
128
- else if (languageCode .equals ("en-US" ) )
151
+ else if (languageCode .equals ("en-US" ))
129
152
model .addAttribute ("voiceName" , "Aoede" );
130
153
// model.addAttribute("voiceName", "en-US-Chirp3-HD-Aoede");
131
154
else if (languageCode .equals ("en-GB" ))
@@ -135,7 +158,6 @@ else if (languageCode.equals("en-GB"))
135
158
}
136
159
137
160
138
-
139
161
@ GetMapping ("/explainer" )
140
162
@ ResponseBody
141
163
public String explainer () throws Exception {
@@ -144,7 +166,7 @@ public String explainer() throws Exception {
144
166
String filePath = "C:/Users/opc/aiholo_output.txt" ;
145
167
try (FileWriter writer = new FileWriter (filePath )) {
146
168
JSONObject json = new JSONObject ();
147
- json .put ("data" , theValue ); // Store the response inside JSON
169
+ json .put ("data" , theValue );
148
170
writer .write (json .toString ());
149
171
writer .flush ();
150
172
} catch (IOException e ) {
@@ -154,13 +176,31 @@ public String explainer() throws Exception {
154
176
return "Explained" ;
155
177
}
156
178
179
+ @ GetMapping ("/leia" )
180
+ @ ResponseBody
181
+ public String leia () throws Exception {
182
+ System .out .println ("AIHoloController.leia" );
183
+ theValue = "leia" ;
184
+ String filePath = "C:/Users/opc/aiholo_output.txt" ;
185
+ try (FileWriter writer = new FileWriter (filePath )) {
186
+ JSONObject json = new JSONObject ();
187
+ json .put ("data" , theValue );
188
+ writer .write (json .toString ());
189
+ writer .flush ();
190
+ } catch (IOException e ) {
191
+ return "Error writing to file: " + e .getMessage ();
192
+ }
193
+ // TTSAndAudio2Face.sendToAudio2Face("explainer-leia.wav");
194
+ return "leia hologram" ;
195
+ }
196
+
157
197
158
198
@ GetMapping ("/play" )
159
199
@ ResponseBody
160
200
public String play (@ RequestParam ("question" ) String question ,
161
- @ RequestParam ("selectedMode" ) String selectedMode ,
162
- @ RequestParam ("languageCode" ) String languageCode ,
163
- @ RequestParam ("voiceName" ) String voicename ) throws Exception {
201
+ @ RequestParam ("selectedMode" ) String selectedMode ,
202
+ @ RequestParam ("languageCode" ) String languageCode ,
203
+ @ RequestParam ("voiceName" ) String voicename ) throws Exception {
164
204
System .out .println (
165
205
"play question: " + question + " selectedMode: " + selectedMode +
166
206
" languageCode:" + languageCode + " voicename:" + voicename );
@@ -211,7 +251,8 @@ public String play(@RequestParam("question") String question,
211
251
String action = "chat" ;
212
252
String answer ;
213
253
if (languageCode .equals ("pt-BR" )) answer = "Desculpe. Não consegui encontrar uma resposta no banco de dados" ;
214
- else if (languageCode .equals ("es-ES" )) answer = "Lo siento, no pude encontrar una respuesta en la base de datos." ;
254
+ else if (languageCode .equals ("es-ES" ))
255
+ answer = "Lo siento, no pude encontrar una respuesta en la base de datos." ;
215
256
else if (languageCode .equals ("en-GB" )) answer = "Sorry, I couldn't find an answer in the database." ;
216
257
else if (languageCode .equals ("zh-SG" )) answer = "抱歉,我在数据库中找不到答案" ;
217
258
else answer = "I'm sorry. I couldn't find an answer in the database" ;
@@ -226,8 +267,7 @@ public String play(@RequestParam("question") String question,
226
267
} else {
227
268
question = question .replace ("use chat" , "" ).trim ();
228
269
}
229
- question += ". If the question is something like \" Where can I find free resources to learn about new\n " +
230
- "technology trends?\" Then incorporate Oracle Academy information in the answer but balance the answer with other non-Oracle information. Respond in 20 words or less" ;
270
+ question += ". Respond in 20 words or less. " + aiholo_prompt_additions ;
231
271
try (Connection connection = dataSource .getConnection ();
232
272
PreparedStatement preparedStatement = connection .prepareStatement (sql )) {
233
273
System .out .println ("Database Connection : " + connection );
@@ -247,31 +287,35 @@ public String play(@RequestParam("question") String question,
247
287
}
248
288
String fileName = "output.wav" ;
249
289
250
- // Strip out any "A:", "A2:", "A3:", etc. at the beginning of the answer string
251
- if (answer != null ) {
252
- answer = answer .replaceFirst ("^A\\ d*:\\ s*" , "" );
253
- }
290
+ // Strip out any "A:", "A2:", "A3:", etc. at the beginning of the answer string
291
+ if (answer != null ) {
292
+ answer = answer .replaceFirst ("^A\\ d*:\\ s*" , "" );
293
+ }
254
294
255
295
System .out .println ("about to TTS and sendAudioToAudio2Face for answer: " + answer );
256
296
TTSAndAudio2Face .processMetahuman (fileName , answer , languageCode , voicename );
297
+ if (answer .toLowerCase ().contains ("leia" ) || answer .toLowerCase ().contains ("star wars" )) {
298
+ Thread .sleep (5 );
299
+ leia ();
300
+ }
257
301
return answer ;
258
302
}
259
303
260
304
261
305
/**
262
- curl -X 'POST' \
263
- 'http://host/v1/chat/completions?client=server' \
264
- -H 'accept: application/json' \
265
- -H 'Authorization: Bearer bearer' \
266
- -H 'Content-Type: application/json' \
267
- -d '{
268
- "messages": [
269
- {
270
- "role": "user",
271
- "content": "What are Alternative Dispute Resolution"
272
- }
273
- ]
274
- }'
306
+ * curl -X 'POST' \
307
+ * 'http://host/v1/chat/completions?client=server' \
308
+ * -H 'accept: application/json' \
309
+ * -H 'Authorization: Bearer bearer' \
310
+ * -H 'Content-Type: application/json' \
311
+ * -d '{
312
+ * "messages": [
313
+ * {
314
+ * "role": "user",
315
+ * "content": "What are Alternative Dispute Resolution"
316
+ * }
317
+ * ]
318
+ * }'
275
319
*/
276
320
277
321
public String executeSandbox (String cummulativeResult ) {
@@ -280,7 +324,7 @@ public String executeSandbox(String cummulativeResult) {
280
324
Map <String , String > message = new HashMap <>();
281
325
message .put ("role" , "user" );
282
326
message .put ("content" , cummulativeResult );
283
- payload .put ("messages" , new Object [] { message });
327
+ payload .put ("messages" , new Object []{ message });
284
328
JSONObject jsonPayload = new JSONObject (payload );
285
329
HttpHeaders headers = new HttpHeaders ();
286
330
headers .setContentType (MediaType .APPLICATION_JSON );
@@ -309,15 +353,14 @@ public String executeSandbox(String cummulativeResult) {
309
353
*/
310
354
311
355
312
-
313
356
// `https://host:port/aiholo/tts?textToConvert=${encodeURIComponent(textToConvert)}
314
357
// &languageCode=${encodeURIComponent(languageCode)}&ssmlGender=${encodeURIComponent(ssmlGender)}
315
358
// &voiceName=${encodeURIComponent(voiceName)}`;
316
359
@ GetMapping ("/tts" )
317
- public ResponseEntity <byte []> ttsAndReturnAudioFile (@ RequestParam ("textToConvert" ) String textToConvert ,
318
- @ RequestParam ("languageCode" ) String languageCode ,
319
- @ RequestParam ("ssmlGender" ) String ssmlGender ,
320
- @ RequestParam ("voiceName" ) String voiceName ) throws Exception {
360
+ public ResponseEntity <byte []> ttsAndReturnAudioFile (@ RequestParam ("textToConvert" ) String textToConvert ,
361
+ @ RequestParam ("languageCode" ) String languageCode ,
362
+ @ RequestParam ("ssmlGender" ) String ssmlGender ,
363
+ @ RequestParam ("voiceName" ) String voiceName ) throws Exception {
321
364
System .out .println ("TTS GCP textToConvert = " + textToConvert + ", languageCode = " + languageCode +
322
365
", ssmlGender = " + ssmlGender + ", voiceName = " + voiceName );
323
366
try (TextToSpeechClient textToSpeechClient = TextToSpeechClient .create ()) {
@@ -341,14 +384,13 @@ public ResponseEntity<byte[]> ttsAndReturnAudioFile(@RequestParam("textToConver
341
384
HttpHeaders headers = new HttpHeaders ();
342
385
headers .set (HttpHeaders .CONTENT_TYPE , "audio/mpeg" );
343
386
headers .set (HttpHeaders .CONTENT_DISPOSITION ,
344
- "attachment; filename=\" tts-" + languageCode + "" + ssmlGender + "" + voiceName + "_" +
387
+ "attachment; filename=\" tts-" + languageCode + "" + ssmlGender + "" + voiceName + "_" +
345
388
getFirst10Chars (textToConvert ) + ".mp3\" " );
346
389
return new ResponseEntity <>(audioData , headers , HttpStatus .OK );
347
390
}
348
391
}
349
392
350
393
351
-
352
394
// Vector embedding, store, langchain, etc. stuff...
353
395
354
396
@@ -384,7 +426,7 @@ public String langchain(@RequestParam("question") String question,
384
426
@ RequestParam ("selectedMode" ) String selectedMode ,
385
427
@ RequestParam ("languageCode" ) String languageCode ,
386
428
@ RequestParam ("voiceName" ) String voicename ) throws Exception {
387
- EmbeddingSearchRequest embeddingSearchRequest = null ;
429
+ EmbeddingSearchRequest embeddingSearchRequest = null ;
388
430
OracleEmbeddingStore embeddingStore =
389
431
OracleEmbeddingStore .builder ()
390
432
.dataSource (dataSource )
@@ -404,12 +446,9 @@ public String langchain(@RequestParam("question") String question,
404
446
}
405
447
406
448
407
-
408
449
//set/get etc utilites to end....
409
450
410
451
411
-
412
-
413
452
public static String getFirst10Chars (String textToConvert ) {
414
453
if (textToConvert == null || textToConvert .isEmpty ()) {
415
454
return "" ;
@@ -472,29 +511,28 @@ public String playArbitrary(
472
511
}
473
512
474
513
/**
475
- en-US (American English):
476
- • en-US-Neural2-F 
477
- • en-US-Neural2-G 
478
- • en-US-Neural2-H
479
- • en-US-Neural2-I 
480
- • en-US-Neural2-J 
481
- • en-US-Standard-C 
482
- • en-US-Standard-E
483
- • en-US-Standard-G 
484
- • en-US-Standard-I
485
- • en-US-Wavenet-C 
486
- • en-US-Wavenet-E 
487
- • en-US-Wavenet-G
488
- • en-US-Wavenet-I
489
-
490
- en-GB (British English):
491
- • en-GB-Neural2-C 
492
- • en-GB-Neural2-E 
493
- • en-GB-Standard-A 
494
- • en-GB-Standard-C 
495
- • en-GB-Standard-E
496
- • en-GB-Wavenet-A 
497
- • en-GB-Wavenet-C 
498
- • en-GB-Wavenet-E
499
-
514
+ * en-US (American English):
515
+ * • en-US-Neural2-F 
516
+ * • en-US-Neural2-G 
517
+ * • en-US-Neural2-H
518
+ * • en-US-Neural2-I 
519
+ * • en-US-Neural2-J 
520
+ * • en-US-Standard-C 
521
+ * • en-US-Standard-E
522
+ * • en-US-Standard-G 
523
+ * • en-US-Standard-I
524
+ * • en-US-Wavenet-C 
525
+ * • en-US-Wavenet-E 
526
+ * • en-US-Wavenet-G
527
+ * • en-US-Wavenet-I
528
+ * <p>
529
+ * en-GB (British English):
530
+ * • en-GB-Neural2-C 
531
+ * • en-GB-Neural2-E 
532
+ * • en-GB-Standard-A 
533
+ * • en-GB-Standard-C 
534
+ * • en-GB-Standard-E
535
+ * • en-GB-Wavenet-A 
536
+ * • en-GB-Wavenet-C 
537
+ * • en-GB-Wavenet-E
500
538
*/
0 commit comments