BAB 02
Estimasi Waktu: 45 menit Level: Beginner
Sebelum lo bisa bikin AI, lo harus bisa bikin software. Ini adalah skills yang SEMUA AI role butuhkan β gak peduli lo mau jadi AI engineer atau AI researcher.
Python adalah lingua franca AI. Semua major framework (PyTorch, TensorFlow, JAX, HuggingFace) pakai Python.
# Lists, dicts, sets, tuples β fundamental
data = [{"name": "Maya", "score": 92}, {"name": "Rama", "score": 87}]
scores = {d["name"]: d["score"] for d in data} # dict comprehension
class ModelEvaluator:
def __init__(self, model, test_data):
self.model = model
self.test_data = test_data
def evaluate(self) -> dict:
results = self.model.predict(self.test_data)
return {"accuracy": self._calc_accuracy(results)}
import numpy as np
# Vectorized operations β ini fundamental untuk ML
embeddings = np.random.randn(1000, 768) # 1000 vectors, 768 dims
similarities = embeddings @ embeddings.T # matrix multiplication
import json
from pathlib import Path
data = {"model": "gpt-4", "temperature": 0.7}
Path("config.json").write_text(json.dumps(data, indent=2))
import asyncio
import aiohttp
async def call_llm(prompt: str) -> dict:
async with aiohttp.ClientSession() as session:
async with session.post(url, json={"prompt": prompt}) as resp:
return await resp.json()
mypy)yielddataclasses & pydanticTenang, lo gak perlu PhD math. Tapi lo perlu paham konsep inti.
Lo gak perlu bisa hitung manual. Lo perlu paham konsep dan intuisi. Library yang hitung; lo yang paham kenapa dan kapan.
git init / clone
git add / commit / push / pull
git branch / checkout / merge
git stash / pop
.gitignore
AI Engineer kerja dengan data. Data tinggal di database. SQL = skill wajib.
-- Basic queries
SELECT column FROM table WHERE condition;
-- Joins
SELECT * FROM users
JOIN orders ON users.id = orders.user_id;
-- Aggregations
SELECT category, COUNT(*), AVG(price)
FROM products
GROUP BY category;
-- Subqueries
SELECT * FROM users
WHERE id IN (SELECT user_id FROM orders WHERE total > 100);
ROW_NUMBER(), RANK())AI models diakses via API. Paham HTTP = fundamental.
import httpx
response = httpx.post(
"https://api.openai.com/v1/chat/completions",
headers={"Authorization": f"Bearer {api_key}"},
json={
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello"}],
},
)
result = response.json()
print(result["choices"][0]["message"]["content"])
cd, ls, pwd)cp, mv, rm, mkdir)grep, cat, head, tail, wc)chmod, chown)export, .env)pip, conda)Target: Python proficiency siap ML, Github profile aktif, 1 API project.