File tree Expand file tree Collapse file tree 1 file changed +28
-3
lines changed
Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -67,10 +67,32 @@ class PoemGenerator {
6767 return ;
6868 }
6969
70- // TODO 2: Panggil fungsi generatePoem dan kirimkan tema dari input
70+ await this . generatePoem ( theme ) ;
7171 }
7272
73- // TODO 2: Logika Generasi Puisi dengan Model AI
73+ async generatePoem ( theme ) {
74+ try {
75+ const prompt = `Write a beautiful poem about ${ theme } . Make it creative and expressive.` ;
76+
77+ const result = await this . generator ( prompt , {
78+ max_new_tokens : 150 , // Panjang maksimal puisi
79+ temperature : 0.8 , // Tingkat kreativitas (0.0-1.0)
80+ do_sample : true , // Aktifkan sampling probabilistik
81+ top_p : 0.9 // Nucleus sampling untuk variasi
82+ } ) ;
83+
84+ // Mengambil teks dari hasil generasi
85+ const poem = result [ 0 ] . generated_text ;
86+
87+ // Menampilkan hasil ke layar
88+ this . showResult ( poem ) ;
89+
90+ } catch ( error ) {
91+ console . log ( 'error' )
92+ } finally {
93+ console . log ( 'selesai' )
94+ }
95+ }
7496
7597 // TODO 3: Logika Copy to Clipboard
7698
@@ -84,7 +106,10 @@ class PoemGenerator {
84106 this . loadingSection . style . display = 'none' ;
85107 }
86108
87- // TODO 2: Fungsi Tampilkan Hasil Puisi
109+ showResult ( poem ) {
110+ this . poemOutput . textContent = poem ;
111+ this . resultSection . style . display = 'block' ;
112+ }
88113
89114 hideResult ( ) {
90115 this . resultSection . style . display = 'none' ;
You can’t perform that action at this time.
0 commit comments