File size: 4,531 Bytes
914a10c e4dcd44 914a10c f27cc68 914a10c f27cc68 914a10c 304e76a 914a10c 304e76a 914a10c |
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 |
# Model: Llama-3.1-70B-Instruct
Model ini adalah model instruksi yang telah difinetuned dan dievaluasi untuk menghasilkan catatan, flashcards, dan kuis berdasarkan konten yang diberikan. Model ini menggunakan Hugging Face API dengan **Fine-grained** token untuk mengakses model.
## Cara Menggunakan Model

### 1. Python
Berikut adalah contoh kode Python untuk menggunakan model ini:
```python
from openai import OpenAI
from IPython.display import display, Markdown
client = OpenAI(
api_key="hf_xxxxxxxxxxxxxxx", # isi dengan token "FINE GRAINED" huggingface anda!
base_url="https://huggingface.co/api/integrations/dgx/v1",
)
# System prompts - pastikan ini sudah didefinisikan
notes_prompt = "..." # wajib isi dengan prompt notes yang sudah ditentukan (notes_prompt.txt)
flashcards_prompt = "..." # wajib isi dengan prompt flashcards yang sudah ditentukan (flashcards_prompt.txt)
quiz_prompt = "..." # wajib isi dengan prompt quiz yang sudah ditentukan (quiz_prompt.txt)
content = "..." # isi dengan dokumen yang sudah di ekstrak dari si parser (PDF, TXT, DOCX)
# 1. Generate notes
notes_response = client.chat.completions.create(
model="meta-llama/Llama-3.1-70B-Instruct",
messages=[
{"role": "system", "content": notes_prompt},
{"role": "user", "content": content},
],
temperature=0.3,
max_tokens=10_000
)
# Notes response
notes_md = notes_response.choices[0].message.content
# 2. Generate flashcards
flashcards_response = client.chat.completions.create(
model="meta-llama/Llama-3.1-70B-Instruct",
messages=[
{"role": "system", "content": flashcards_prompt},
{"role": "user", "content": notes_md},
],
temperature=0.3,
max_tokens=1024
)
# flashcards response
flashcards_md = flashcards_response.choices[0].message.content
# 3. Generate quiz
quiz_response = client.chat.completions.create(
model="meta-llama/Llama-3.1-70B-Instruct",
messages=[
{"role": "system", "content": quiz_prompt},
{"role": "user", "content": notes_md},
],
temperature=0.3,
max_tokens=5048
)
# Quiz response
quiz_md = quiz_response.choices[0].message.content
print(notes_md)
print(flashcards_md)
print(quiz_md)
```
### 2. Javascript
```javascript
import { HfInference } from "@huggingface/inference";
const client = new HfInference("hf_xxxxxxxxxxxxxxx"); // isi dengan token "FINE GRAINED" huggingface anda!
// System prompts - pastikan ini sudah didefinisikan
const notes_prompt = "..." // wajib isi dengan prompt notes yang sudah ditentukan (notes_prompt.txt)
const flashcards_prompt = "..." // wajib isi dengan prompt flashcards yang sudah ditentukan (flashcards_prompt.txt)
const quiz_prompt = "..." // wajib isi dengan prompt quiz yang sudah ditentukan (quiz_prompt.txt)
const content = "..." // isi dengan dokumen yang sudah di ekstrak dari si parser (PDF, TXT, DOCX)
async function generateEducationalContent() {
try {
// 1. Generate Notes
const notesResponse = await client.chatCompletion({
model: "meta-llama/Llama-3.1-70B-Instruct",
messages: [
{ role: "system", content: notes_prompt },
{ role: "user", content: content }
],
temperature: 0.3,
max_tokens: 10_000
});
const notesMd = notesResponse.choices[0].message.content;
console.log("=== CATATAN ===");
console.log(notesMd);
// 2. Generate Flashcards
const flashcardsResponse = await client.chatCompletion({
model: "meta-llama/Llama-3.1-70B-Instruct",
messages: [
{ role: "system", content: flashcards_prompt },
{ role: "user", content: notesMd }
],
temperature: 0.3,
max_tokens: 1024
});
const flashcardsMd = flashcardsResponse.choices[0].message.content;
console.log("\n=== FLASHCARDS ===");
console.log(flashcardsMd);
// 3. Generate Quiz
const quizResponse = await client.chatCompletion({
model: "meta-llama/Llama-3.1-70B-Instruct",
messages: [
{ role: "system", content: quiz_prompt },
{ role: "user", content: notesMd }
],
temperature: 0.3,
max_tokens: 5048
});
const quizMd = quizResponse.choices[0].message.content;
console.log("\n=== KUIS ===");
console.log(quizMd);
} catch (error) {
console.error("Error:", error);
}
}
// Eksekusi fungsi utama
generateEducationalContent();
```
Pastikan anda menginstall dependency yang diperlukan:
```node.js
npm install @huggingface/inference
``` |