-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
832 lines (672 loc) · 35.6 KB
/
test.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
import requests
import json, sys
#from adventure import ADVENTURE1
from schemas import GPT_TOOL_SLIDE_SCHEMA
import uuid
from pathlib import Path
def gen_pptx(output_path, title, subtitle, template = "Entrevue_template_advanced", url = "pptx/generate_presentation_advanced"):
json_response = ""
try:
with open(output_path, 'r') as f:
json_response = f.read()
except FileNotFoundError:
print(f"File {output_path} not found")
exit(1)
#
print("json_slides = ", json_response)
json_dict = json.loads(json_response)
print("json_dict = ", json_dict)
slides = json.dumps(json_dict["slides"])
print("slides = ", slides)
result_file_name = f"{uuid.uuid4().hex}.pptx"
data = {
"filename": result_file_name,
"slides": slides,
"template": template,
"title": title,
"subtitle": subtitle
}
url = f'http://localhost:{PORT}/{url}'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"default.pptx").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = './test/'+json_file
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
return response.content
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
return None
#
def gen_pptx_external(output_path, title, subtitle, template = "Entrevue_template_advanced", url = "pptx/generate_presentation_advanced"):
json_response = ""
try:
with open(output_path, 'r') as f:
json_response = f.read()
except FileNotFoundError:
print(f"File {output_path} not found")
exit(1)
#
print("json_slides = ", json_response)
json_dict = json.loads(json_response)
print("json_dict = ", json_dict)
slides = json.dumps(json_dict["slides"])
print("slides = ", slides)
result_file_name = f"{uuid.uuid4().hex}.pptx"
data = {
"filename": result_file_name,
"slides": slides,
"template": template,
"title": title,
"subtitle": subtitle
}
url = f'https://text2pptx.onrender.com/{url}'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"default.pptx").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = './test/'+json_file
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
PORT = 8501
def main(test_number):
# Read the OpenAI API key from the file
try:
with open('openai.key', 'r') as key_file:
api_key = key_file.read().strip()
except FileNotFoundError:
print("Error: openai.key file not found.")
return
except Exception as e:
print(f"Error reading openai.key file: {e}")
return
if not api_key:
print("Error: OpenAI API key is empty.")
return
if test_number == 1:
url = f'http://localhost:{PORT}/llm/big_pptx'
#url = 'https://text2pptx.onrender.com/llm/big_pptx'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"title": "Dungeons And Dragons",
"subtitle": "A presentation on the popular tabletop role-playing game",
"user_prompt": "Generate a presentation on what Dungeons And Dragons is|||Generate a presentation on Dungeons And Dragons Adventurers League and how it contributed to the renewal of interest in the game",
"api_key": api_key,
"template": "Bespoke",
"filename": "example_output.pptx"
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"default.pptx").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = './test/'+json_file
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
if test_number == 2:
url = f'http://localhost:{PORT}/llm/infer'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"system_prompt": "Extract the entities in the prompt and return it as a json",
"model":"gpt-4o",
"user_prompt": ADVENTURE1,
"api_key": api_key,
"filename": "adventure.json",
"schema": "{`title`:`Entities and Relationships`,`type`:`object`,`properties`:{`entities`:{`type`:`array`,`items`:{`type`:`object`,`properties`:{`id`:{`type`:`string`,`description`:`Unique identifier for the entity`},`name`:{`type`:`string`,`description`:`Name of the entity`},`category`:{`type`:`string`,`description`:`Main category of the entity`},`subcategory`:{`type`:`string`,`description`:`Subcategory under the main category`},`related_entities`:{`type`:`array`,`items`:{`type`:`object`,`properties`:{`id`:{`type`:`string`,`description`:`Unique identifier of the related entity`},`relation_type`:{`type`:`string`,`description`:`Type of the relationship`},`relation_subtype`:{`type`:`string`,`description`:`Subtype of the relationship`},`commentary`:{`type`:`string`,`description`:`Commentary or description of the relationship`}},`required`:[`id`,`relation_type`,`relation_subtype`]},`description`:`List of related entities`}},`required`:[`id`,`name`,`category`,`subcategory`]}}},`required`:[`entities`]}"
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
print("----------")
print("response = ", response)
print("----------")
print("headers =", response.headers)
print("----------")
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"result.out").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = './test/'+json_file
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
pass
#
if test_number == 3:
url = f'http://localhost:{PORT}/llm/big_dm_slides'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"title": "Dungeons And Dragons",
"subtitle": "A presentation on the popular tabletop role-playing game",
"user_prompt": "Generate a presentation on what Dungeons And Dragons is|||Generate a presentation on Dungeons And Dragons Adventurers League and how it contributed to the renewal of interest in the game",
"api_key": api_key,
"filename": "example_output3.md",
"options": {"sectionsExpand":"yes"}
}
# "template": "md_Bespoke.pptx",
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"default.md").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = './test/'+json_file
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
if test_number == 4:
markdown_only = True
url = f'http://localhost:{PORT}/llm/big_dm_slides'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"title": "Dungeons And Dragons",
"subtitle": "A presentation on the popular tabletop role-playing game",
"user_prompt": "Generate a presentation on what Dungeons And Dragons is|||Generate a presentation on Dungeons And Dragons Adventurers League and how it contributed to the renewal of interest in the game",
"api_key": api_key,
"filename": "example_output5.pptx",
"options": {"sectionsExpand":"yes"},
"template": "md_Bespoke.pptx",
"markdown_only": markdown_only
}
# "template": "md_Bespoke.pptx",
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"default.pptx").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = f'./test/{json_file}.md'
with open(output_path, 'wb') as f:
f.write(response.content)
f.close()
print(f"Presentation saved to {output_path}")
markdown = ""
try:
with open(output_path, 'r') as f:
markdown = f.read()
except FileNotFoundError:
print(f"File {output_path} not found")
exit(1)
#
print("markdown = ", markdown)
data = {
"filename": 'dnd4.pptx',
"markdown": markdown,
"template": "md_Bespoke.pptx",
"options": {"sectionsExpand":"yes"}
}
url = f'http://localhost:{PORT}/pptx/from_md'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"default.pptx").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = './test/'+json_file
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
if test_number == 5:
markdown_only = True
url = f'http://localhost:{PORT}/llm/text_to_slides'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"title": "Dungeons And Dragons",
"subtitle": "A presentation on the popular tabletop role-playing game",
"user_prompt": "Generate a presentation on what Dungeons And Dragons is|||Generate a presentation on Dungeons And Dragons Adventurers League and how it contributed to the renewal of interest in the game",
"api_key": api_key,
"filename": "test_output_option_5",
"options": {"sectionsExpand":"yes"},
"template": "md_Bespoke.pptx"
}
# "template": "md_Bespoke.pptx",
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"default.pptx").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = f'./out/{json_file}.final.pptx'
with open(output_path, 'wb') as f:
f.write(response.content)
f.close()
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
if test_number == 6:
url = f'http://localhost:{PORT}/llm/infer'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"ai_type":"openai",
"model":"gpt-3.5-turbo",
"schema": GPT_TOOL_SLIDE_SCHEMA,
"user_prompt": "Generate detailed slides using the provided schema on what Dungeons And Dragons is, its origin, how to play, what is a DM, why it is popular again. Use bullet points, numbered lists, etc. to present a clear and well organized presentation.",
"api_key": api_key,
"filename": "example_output_10.json"
}
# "template": "md_Bespoke.pptx",
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"default.json").split("filename=")[-1].strip('"' + "'")
print(f"json_file name: {json_file}")
# Save the response content to a file
output_path = f'./test/{json_file}.json'
with open(output_path, 'wb') as f:
f.write(response.content)
f.close()
print(f"json_file saved to {output_path}")
gen_pptx(output_path)
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
if test_number == 7:
json_path = f'./input/test_slide_advanced.json'
gen_pptx(json_path, "D&D", "A case study")
if test_number == 8:
json_path = f'./input/test_slide_simple.json'
gen_pptx(json_path,"Presentation Title", "Presentation Subtitle", "Entrevue_template" ,"pptx/generate_presentation")
if test_number == 9:
from references import GPT_TOOL_SCHEMA__BOOK_REFERENCE_small
print(GPT_TOOL_SCHEMA__BOOK_REFERENCE_small)
url = f'http://localhost:{PORT}/llm/infer'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"system_prompt": "Recommend a book based on the user's input, explain your choice, provide the url and book title as a json according to the provided json schema.",
"model":"gpt-4o",
"user_prompt": "I'm looking for a classic science fiction book to read. What would you recommend?",
"api_key": api_key,
"filename": "book.json",
"schema": GPT_TOOL_SCHEMA__BOOK_REFERENCE_small
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
print("----------")
print("response = ", response)
print("----------")
print("headers =", response.headers)
print("----------")
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"result.out").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = './test/'+json_file
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
pass
#
if test_number == 10:
from references import GPT_TOOL_SCHEMA_FINANCIAL_REFERENCES
url = f'http://localhost:{PORT}/llm/infer'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"system_prompt": "Recommend a financial reference based on the user's input, explain your choice, provide the url and book title as a json according to the provided json schema.",
"model":"gpt-4o",
"user_prompt": "I'm looking for something to help me understand venture capital and what interview questions I'm likely to get for a VC job",
"api_key": api_key,
"filename": "book.json",
"schema": GPT_TOOL_SCHEMA_FINANCIAL_REFERENCES
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
print("----------")
print("response = ", response)
print("----------")
print("headers =", response.headers)
print("----------")
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"result.out").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = './test/'+json_file
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
pass
#
if test_number == 11:
from references import GPT_TOOL_SCHEMA_30_REFS, INSTRUCTION_30_REFS
resume_string = ""
# read resume from input/resume.txt
try:
with open('input/resume.txt', 'r') as resume_file:
resume_string = resume_file.read()
except FileNotFoundError:
print("Error: resume.txt file not found.")
return
#
knowledge_gap_string = ""
# read the knowledge_gap from input/knowledge_gap.txt
try:
with open('input/knowledge_gap.txt', 'r') as knowledge_gap_file:
knowledge_gap_string = knowledge_gap_file.read()
except FileNotFoundError:
print("Error: knowledge_gap.txt file not found.")
return
#
job_description_string = ""
# read the job_description from input/job_description.txt
try:
with open('input/job_description.txt', 'r') as job_description_file:
job_description_string = job_description_file.read()
except FileNotFoundError:
print("Error: job_description.txt file not found.")
return
#instruction_string = INSTRUCTION_30_REFS
instruction_string = "Based on the KNOWLEDGE GAP and the JOB DESCRIPTION, generate 6 groups of up to 5 references each. Each group should be a list of up to 5 references that would help the user fill in the gaps in their knowledge. Provide the references as a json according to the provided json schema. Do not reuse references from one group to another."
#instruction_string = "Based on the KNOWLEDGE GAP, generate 6 groups of up to 5 references each. Each group should be a list of up to 5 references that would help the user fill in the gaps in their knowledge. Provide the references as a json according to the provided json schema. Do not reuse references from one group to another."
#instruction_string = "For each gap identified in the KNOWLEDGE GAP section, generate up to 5 references that will help the candidate fill that gap in their knowledge. Ensure that each reference is not used more than once. Provide the references as a json according to the provided json schema. "
prompt_string = ""
#prompt_string += "<RESUME>\n"+resume_string+"\n</RESUME>\n\n"
prompt_string += "<KNOWLEDGE_GAP>\n"+knowledge_gap_string+"\n</KNOWLEDGE_GAP>\n\n"
prompt_string += "<JOB_DESCRIPTION>\n"+job_description_string+"\n</JOB_DESCRIPTION>\n\n"
url = f'http://localhost:{PORT}/llm/infer'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"system_prompt": instruction_string,
"model":"gpt-4o",
"user_prompt": prompt_string,
"api_key": api_key,
"filename": "30ref.json",
"schema": GPT_TOOL_SCHEMA_30_REFS
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
print("----------")
print("response = ", response)
print("----------")
print("headers =", response.headers)
print("----------")
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"result.out").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = Path('./test/',json_file+"_"+uuid.uuid4().hex+".txt")
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
if test_number == 12:
from references import GPT_TOOL_SCHEMA_JULY
resume_string = ""
# read resume from input/resume.txt
try:
with open('input/resume.txt', 'r') as resume_file:
resume_string = resume_file.read()
except FileNotFoundError:
print("Error: resume.txt file not found.")
return
#
knowledge_gap_string = ""
# read the knowledge_gap from input/knowledge_gap.txt
try:
with open('input/knowledge_gap.txt', 'r') as knowledge_gap_file:
knowledge_gap_string = knowledge_gap_file.read()
except FileNotFoundError:
print("Error: knowledge_gap.txt file not found.")
return
#
job_description_string = ""
# read the job_description from input/job_description.txt
try:
with open('input/job_description.txt', 'r') as job_description_file:
job_description_string = job_description_file.read()
except FileNotFoundError:
print("Error: job_description.txt file not found.")
return
#instruction_string = INSTRUCTION_30_REFS
#instruction_string = "Based on the KNOWLEDGE GAP and the JOB DESCRIPTION, generate 6 groups of up to 5 references each. Each group should be a list of up to 5 references that would help the user fill in the gaps in their knowledge. Provide the references as a json according to the provided json schema. Do not reuse references from one group to another."
#instruction_string = "Based on the KNOWLEDGE GAP, generate 6 groups of up to 5 references each. Each group should be a list of up to 5 references that would help the user fill in the gaps in their knowledge. Provide the references as a json according to the provided json schema. Do not reuse references from one group to another."
instruction_string = "List each gap present in the KNOWLEDGE GAP section. For each gap identified in the KNOWLEDGE GAP section, generate up to 5 references that will help the candidate fill that gap in their knowledge. Ensure that each reference is not used more than once. Provide the references as a json according to the provided json schema. "
prompt_string = ""
#prompt_string += "<RESUME>\n"+resume_string+"\n</RESUME>\n\n"
prompt_string += "<KNOWLEDGE_GAP>\n"+knowledge_gap_string+"\n</KNOWLEDGE_GAP>\n\n"
#prompt_string += "<JOB_DESCRIPTION>\n"+job_description_string+"\n</JOB_DESCRIPTION>\n\n"
print("KNOWLEDGE GAP = ", knowledge_gap_string);
url = f'http://localhost:{PORT}/llm/infer'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"system_prompt": instruction_string,
"model":"gpt-4o",
"user_prompt": prompt_string,
"api_key": api_key,
"filename": "gaps_refs.json",
"schema": GPT_TOOL_SCHEMA_JULY
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
print("----------")
print("response = ", response)
print("----------")
print("headers =", response.headers)
print("----------")
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"result.out").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = Path('./test/',json_file+"_"+uuid.uuid4().hex+".txt")
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
if test_number == 13:
from references import GPT_TOOL_SCHEMA_JULY4, LINK_REFERENCES
schema = GPT_TOOL_SCHEMA_JULY4
resume_string = ""
# read resume from input/resume.txt
try:
with open('input/resume.txt', 'r') as resume_file:
resume_string = resume_file.read()
except FileNotFoundError:
print("Error: resume.txt file not found.")
return
#
knowledge_gap_string = ""
# read the knowledge_gap from input/knowledge_gap.txt
try:
with open('input/knowledge_gap.txt', 'r') as knowledge_gap_file:
knowledge_gap_string = knowledge_gap_file.read()
except FileNotFoundError:
print("Error: knowledge_gap.txt file not found.")
return
#
job_description_string = ""
# read the job_description from input/job_description.txt
try:
with open('input/job_description.txt', 'r') as job_description_file:
job_description_string = job_description_file.read()
except FileNotFoundError:
print("Error: job_description.txt file not found.")
return
instruction_string = "List each gap present in the KNOWLEDGE GAP section. For each identified gap, generate 2 to 5 references taken from the <REFERENCES> section that can help the candidate fill that gap in their knowledge. Ensure that each gap is addressed. Ensure that each reference is not used more than once. Provide the references as a json according to the provided json schema. "
instruction_string += LINK_REFERENCES
prompt_string = "<KNOWLEDGE_GAP>\n"+knowledge_gap_string+"\n</KNOWLEDGE_GAP>\n\n"
print("KNOWLEDGE GAP = ", knowledge_gap_string);
url = f'http://localhost:{PORT}/llm/infer'
print("requesting to ", url)
headers = {'Content-Type': 'application/json'}
data = {
"system_prompt": instruction_string,
"model":"gpt-4o",
"user_prompt": prompt_string,
"api_key": api_key,
"filename": "gaps_refs.json",
"schema": schema
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
print("----------")
print("response = ", response)
print("----------")
print("headers =", response.headers)
print("----------")
# Get the presentation name from the response headers
json_file = response.headers.get('Content-Disposition',"result.out").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
output_path = Path('./test/',json_file+"_"+uuid.uuid4().hex+".txt")
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Presentation saved to {output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
#
#
#
#
if test_number == 14:
knowledge_gap_string = ""
# read the knowledge_gap from input/knowledge_gap.txt
try:
with open('input/knowledge_gap.txt', 'r') as knowledge_gap_file:
knowledge_gap_string = knowledge_gap_file.read()
except FileNotFoundError:
print("Error: knowledge_gap.txt file not found.")
return
#
url = f'http://localhost:{PORT}/llm/remedial_resources'
print("requesting to ", url)
headers = {'Authorization': f'Bearer {api_key}','Content-Type': 'application/json'}
data = {
"gaps": knowledge_gap_string,
"model:": "gpt-4o-mini",
"filename": "gaps_refs15.json"
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response.raise_for_status() # Raise an exception for HTTP errors
print("----------")
print("response = ", response)
print("----------")
print("headers =", response.headers)
print("----------")
# Get the result name from the response headers
json_file = response.headers.get('Content-Disposition',"result.out").split("filename=")[-1].strip('"' + "'")
print(f"Presentation name: {json_file}")
# Save the response content to a file
filename = json_file+"_"+uuid.uuid4().hex
output_path = Path('./test/',filename+".txt")
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Response saved to {output_path}")
result = response.content
print("---------result-----------")
print(result)
result_json = json.loads(result.decode('utf-8'))
print("---------result_json-----------")
print(result_json)
slides_json = {}
slides_json['slides'] = json.loads(result_json['full_response'])
# Save result_json to a JSON file
json_output_path = Path('./test/', filename + ".json")
with open(json_output_path, 'w') as json_file:
json.dump(slides_json, json_file, indent=4)
print(f"JSON saved to {json_output_path}")
except requests.exceptions.RequestException as e:
print(f"Error during request: {e}")
#
#
if test_number == 15:
#json_path = f'test/result.out_44ae103c061b4e96903a2d0a928dd00f.txt'
json_path = 'test/result.out_710bd5d5478e49f98e2c9685b3b8b722.txt'
result = gen_pptx(json_path, "Knowledge Gap", "A remedial plan")
print("---------result-----------")
print(result)
result_json = json.load(result)
print("---------result_json-----------")
print(result_json)
if test_number == 16:
json_path = f'./input/test_slide_simple.json'
gen_pptx_external(json_path,"Presentation Title", "Presentation Subtitle", "Entrevue_template" ,"pptx/generate_presentation")
if test_number == 17:
result = '{"full_response": "[{\\"heading\\": \\"Direct Experience with High-Level Portfolio Management\\", \\"bullet_points\\": [[\\"https://mergersandinquisitions.com/private-equity/\\"], [[\\"Provides an overview of the private equity industry and links to portfolio management related to fixed income.\\"]], [\\"https://mergersandinquisitions.com/venture-capital\\"], [[\\"Offers insight into venture capital that can connect portfolio management practices.\\"]], [\\"https://www.wallstreetprep.com/knowledge/hedge-fund\\"], [[\\"Introduces basic concepts of hedge funds that involve comprehensive portfolio management.\\"]]]}, {\\"heading\\": \\"Advanced Knowledge of Financial Markets Products\\", \\"bullet_points\\": [[\\"https://mergersandinquisitions.com/how-to-get-a-job-at-a-hedge-fund/\\"], [[\\"Detailed strategies and advice for understanding specific financial market products related to hedge funds.\\"]], [\\"https://www.wallstreetprep.com/knowledge/operating-cash-flow-ocf/\\"], [[\\"Focuses on free cash flow, essential for understanding fixed-income investments.\\"]], [\\"https://onlinedegrees.sandiego.edu/data-science-in-finance/\\"], [[\\"Explores the role of data science in finance, particularly useful for advanced financial market product knowledge.\\"]]]}]", "usage": {"prompt_tokens": 6000, "completion_tokens": 252, "total_tokens": 6252}, "finish_reason": "stop", "model": "gpt-4o-mini"}'
result_json = json.loads(result)
slide_json = json.loads(result_json['full_response'])
print(f"slide_json = {slide_json}")
if __name__ == "__main__":
# read the test number as the first passed argument
test_number = 1
if len(sys.argv) > 1:
test_number = int(sys.argv[1])
#
print(f"Running test {test_number}")
print("----------------")
main(test_number)
#