|
# 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 |
|
``` |