Chatbot API berbasis Flask yang terhubung dengan Groq API (LLaMA3 model) dan mendukung CORS. Dilengkapi antarmuka HTML sederhana di halaman utama.
- Endpoint RESTful
/chatuntuk mengirim pesan. - Riwayat percakapan (history) didukung.
- Integrasi dengan model
llama3-8b-8192via Groq API. - Antarmuka HTML (
index.html) sebagai halaman utama. - CORS diaktifkan untuk kebutuhan frontend terpisah.
your_project/
├── app.py
├── templates/
│ └── index.html
└── README.mdgit clone https://github.com/username/groq-chatbot-flask.git
cd groq-chatbot-flaskpython3 -m venv venv
source venv/bin/activate # Mac/Linux
venv\Scripts\activate # Windowspip install -r requirements.txtPastikan GROQ_API_KEY sudah diset:
export GROQ_API_KEY=your_groq_api_key # Mac/Linux
set GROQ_API_KEY=your_groq_api_key # WindowsDi PythonAnywhere: Tambahkan GROQ_API_KEY di bagian "Environment Variables" pada file WSGI.
python app.pyKunjungi http://localhost:5000 di browser.
POST /chat Mengirim pesan ke chatbot.
Contoh Request:
{
"message": "Halo, siapa kamu?",
"history": []
}Contoh Response:
{
"reply": "Halo! Saya adalah asisten AI yang didukung oleh LLaMA3.",
"history": [
{"role": "user", "content": "Halo, siapa kamu?"},
{"role": "assistant", "content": "Halo! Saya adalah asisten AI yang didukung oleh LLaMA3."}
]
}Di PythonAnywhere atau layanan lain, pastikan:
File index.html berada dalam folder templates/
Variabel GROQ_API_KEY diatur di server
Gunakan file wsgi.py jika diperlukan untuk deployment