Views
No views yet

1from openai import OpenAI
2from IPython.display import display, Markdown
3
4client = OpenAI(
5 api_key="hf_xxxxxxxxxxxxxxx", # isi dengan token "FINE GRAINED" huggingface anda!
6 base_url="https://huggingface.co/api/integrations/dgx/v1",
7)
8
9# System prompts - pastikan ini sudah didefinisikan
10notes_prompt = "..." # wajib isi dengan prompt notes yang sudah ditentukan (notes_prompt.txt)
11flashcards_prompt = "..." # wajib isi dengan prompt flashcards yang sudah ditentukan (flashcards_prompt.txt)
12quiz_prompt = "..." # wajib isi dengan prompt quiz yang sudah ditentukan (quiz_prompt.txt)
13
14content = "..." # isi dengan dokumen yang sudah di ekstrak dari si parser (PDF, TXT, DOCX)
15
16
17# 1. Generate notes
18notes_response = client.chat.completions.create(
19 model="meta-llama/Llama-3.1-70B-Instruct",
20 messages=[
21 {"role": "system", "content": notes_prompt},
22 {"role": "user", "content": content},
23 ],
24 temperature=0.3,
25 max_tokens=10_000
26)
27
28# Notes response
29notes_md = notes_response.choices[0].message.content
30
31# 2. Generate flashcards
32flashcards_response = client.chat.completions.create(
33 model="meta-llama/Llama-3.1-70B-Instruct",
34 messages=[
35 {"role": "system", "content": flashcards_prompt},
36 {"role": "user", "content": notes_md},
37 ],
38 temperature=0.3,
39 max_tokens=1024
40)
41
42# flashcards response
43flashcards_md = flashcards_response.choices[0].message.content
44
45# 3. Generate quiz
46quiz_response = client.chat.completions.create(
47 model="meta-llama/Llama-3.1-70B-Instruct",
48 messages=[
49 {"role": "system", "content": quiz_prompt},
50 {"role": "user", "content": notes_md},
51 ],
52 temperature=0.3,
53 max_tokens=5048
54)
55
56# Quiz response
57quiz_md = quiz_response.choices[0].message.content
58
59print(notes_md)
60print(flashcards_md)
61print(quiz_md)1import { HfInference } from "@huggingface/inference";
2
3const client = new HfInference("hf_xxxxxxxxxxxxxxx"); // isi dengan token "FINE GRAINED" huggingface anda!
4
5// System prompts - pastikan ini sudah didefinisikan
6const notes_prompt = "..." // wajib isi dengan prompt notes yang sudah ditentukan (notes_prompt.txt)
7const flashcards_prompt = "..." // wajib isi dengan prompt flashcards yang sudah ditentukan (flashcards_prompt.txt)
8const quiz_prompt = "..." // wajib isi dengan prompt quiz yang sudah ditentukan (quiz_prompt.txt)
9
10
11const content = "..." // isi dengan dokumen yang sudah di ekstrak dari si parser (PDF, TXT, DOCX)
12
13async function generateEducationalContent() {
14 try {
15 // 1. Generate Notes
16 const notesResponse = await client.chatCompletion({
17 model: "meta-llama/Llama-3.1-70B-Instruct",
18 messages: [
19 { role: "system", content: notes_prompt },
20 { role: "user", content: content }
21 ],
22 temperature: 0.3,
23 max_tokens: 10_000
24 });
25
26 const notesMd = notesResponse.choices[0].message.content;
27 console.log("=== CATATAN ===");
28 console.log(notesMd);
29
30 // 2. Generate Flashcards
31 const flashcardsResponse = await client.chatCompletion({
32 model: "meta-llama/Llama-3.1-70B-Instruct",
33 messages: [
34 { role: "system", content: flashcards_prompt },
35 { role: "user", content: notesMd }
36 ],
37 temperature: 0.3,
38 max_tokens: 1024
39 });
40
41 const flashcardsMd = flashcardsResponse.choices[0].message.content;
42 console.log("\n=== FLASHCARDS ===");
43 console.log(flashcardsMd);
44
45 // 3. Generate Quiz
46 const quizResponse = await client.chatCompletion({
47 model: "meta-llama/Llama-3.1-70B-Instruct",
48 messages: [
49 { role: "system", content: quiz_prompt },
50 { role: "user", content: notesMd }
51 ],
52 temperature: 0.3,
53 max_tokens: 5048
54 });
55
56 const quizMd = quizResponse.choices[0].message.content;
57 console.log("\n=== KUIS ===");
58 console.log(quizMd);
59
60 } catch (error) {
61 console.error("Error:", error);
62 }
63}
64
65// Eksekusi fungsi utama
66generateEducationalContent();npm install @huggingface/inference