feat: initial bot orchestrator with AI integration
This commit is contained in:
99
ai_generator.py
Normal file
99
ai_generator.py
Normal file
@@ -0,0 +1,99 @@
|
||||
import os
|
||||
from openai import OpenAI
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# Setup OpenRouter Client
|
||||
client = OpenAI(
|
||||
base_url="https://openrouter.ai/api/v1",
|
||||
api_key=os.getenv("OPENROUTER_API_KEY"),
|
||||
)
|
||||
|
||||
def generate_bot_data():
|
||||
"""
|
||||
Generate realistic Indonesian persona and service data using OpenRouter.
|
||||
"""
|
||||
prompt = """
|
||||
Kamu adalah pembuat data realistis untuk platform Microjob/Gig Economy di Indonesia.
|
||||
Buat 1 set data dalam format JSON yang berisi:
|
||||
{
|
||||
"akun1": {
|
||||
"nama_lengkap": "Nama orang Indonesia yang realistis",
|
||||
"email": "Email pribadi realistis berdasarkan nama",
|
||||
"nama_bisnis": "Nama profesional atau brand jasa (contoh: Jasa Desain Grafis Budi, Tukang AC Cepat)",
|
||||
"deskripsi_bisnis": "Deskripsi singkat tentang keahlian atau layanan yang ditawarkan",
|
||||
"lokasi": {
|
||||
"lat": "Latitude acak di area perkotaan Indonesia (misal: Jakarta, Bandung, atau Surabaya)",
|
||||
"lng": "Longitude acak di area perkotaan Indonesia",
|
||||
"alamat": "Alamat lengkap realistis di Indonesia",
|
||||
"radius": "Angka radius layanan dalam KM (antara 10-100)"
|
||||
},
|
||||
"identitas": {
|
||||
"tipe": "KTP",
|
||||
"nomor": "16 digit angka KTP acak yang valid secara format"
|
||||
}
|
||||
},
|
||||
"akun2": {
|
||||
"nama_lengkap": "Nama pembeli Indonesia yang realistis",
|
||||
"email": "Email pribadi realistis berdasarkan nama"
|
||||
},
|
||||
"layanan": {
|
||||
"judul": "Judul jasa yang ditawarkan",
|
||||
"deskripsi": "Deskripsi lengkap layanan tersebut",
|
||||
"harga": "Angka saja dalam rupiah, misal 50000"
|
||||
},
|
||||
"review": {
|
||||
"rating": 5,
|
||||
"komentar": "Komentar positif dari pembeli"
|
||||
}
|
||||
}
|
||||
Berikan HANYA JSON output tanpa teks lain.
|
||||
"""
|
||||
|
||||
try:
|
||||
response = client.chat.completions.create(
|
||||
model="meta-llama/llama-3-8b-instruct:free", # Free tier model for testing, can be changed
|
||||
messages=[
|
||||
{"role": "system", "content": "You output only valid JSON."},
|
||||
{"role": "user", "content": prompt}
|
||||
]
|
||||
)
|
||||
content = response.choices[0].message.content.strip()
|
||||
|
||||
# Strip markdown backticks if present
|
||||
if content.startswith("```"):
|
||||
content = content.split("```")[1]
|
||||
if content.startswith("json"):
|
||||
content = content[4:]
|
||||
content = content.split("```")[0].strip()
|
||||
|
||||
import json
|
||||
return json.loads(content)
|
||||
except Exception as e:
|
||||
print(f"Error generating AI data: {e}")
|
||||
# Fallback dummy data if AI fails
|
||||
return {
|
||||
"akun1": {
|
||||
"nama_lengkap": "Budi Santoso",
|
||||
"email": "budi.santoso@gmail.com",
|
||||
"nama_bisnis": "Budi Creative Design",
|
||||
"deskripsi_bisnis": "Spesialis desain grafis dan branding logo",
|
||||
"lokasi": {
|
||||
"lat": -6.2088,
|
||||
"lng": 106.8456,
|
||||
"alamat": "Jl. Gajah Mada No. 12, Jakarta Pusat",
|
||||
"radius": 25
|
||||
},
|
||||
"identitas": {
|
||||
"tipe": "KTP",
|
||||
"nomor": "3171234567890001"
|
||||
}
|
||||
},
|
||||
"akun2": {"nama_lengkap": "Andi Pratama", "email": "andipratama12@yahoo.com"},
|
||||
"layanan": {"judul": "Jasa Desain Banner", "deskripsi": "Desain banner cepat dan profesional", "harga": 50000},
|
||||
"review": {"rating": 5, "komentar": "Pekerjaannya cepat dan hasilnya bagus sekali!"}
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(generate_bot_data())
|
||||
Reference in New Issue
Block a user