You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
messages= [
{"role": "system", "content": "You are a helpful assistant."}, # optional
{"role": "user", "content": "What is Python?"},
{"role": "assistant", "content": "Python is a programming language."}, # history
{"role": "user", "content": "Is it good for beginners?"}, # current
]
Local embeddings
fromsentence_transformersimportSentenceTransformer, utilmodel=SentenceTransformer('all-MiniLM-L6-v2')
embeddings=model.encode(["text1", "text2"])
similarity=util.cos_sim(embeddings[0], embeddings[1]).item() # 0.0 to 1.0
RAG in 10 lines
fromsentence_transformersimportSentenceTransformer, utilimportnumpyasnpembed_model=SentenceTransformer('all-MiniLM-L6-v2')
chunks= ["chunk1 text", "chunk2 text", "chunk3 text"]
chunk_embeddings=embed_model.encode(chunks)
question="your question"q_embedding=embed_model.encode(question)
similarities=util.cos_sim(q_embedding, chunk_embeddings)[0]
best_idx=similarities.argmax().item()
best_chunk=chunks[best_idx]
# Now put best_chunk in your prompt as context
Extract [WHAT] from the text below.
Return ONLY a JSON object: {"key1": ..., "key2": ...}
If a field is missing, use null. No explanation, no markdown.
Text: [INPUT]
Code review
You are a senior [LANGUAGE] engineer. Review this code.
For each issue: Issue | Severity (Critical/High/Medium/Low) | Fix
Code: [CODE]
Summarization
Summarize the following [CONTENT TYPE] for [AUDIENCE].
Length: [SHORT/MEDIUM/DETAILED]. Format: [BULLETS/PARAGRAPH]
[CONTENT]
RAG answer
Answer the question based ONLY on the provided context.
If not in context, say "I couldn't find that in the document."
Context: [RETRIEVED CHUNKS]
Question: [USER QUESTION]
Add if hasattr(chunk, 'choices') and chunk.choices: check
CUDA out of memory
Reduce batch size, use 4-bit quantization (QLoRA)
Project Files Summary
File
Command
What it does
projects/prompt_playground.py
streamlit run ...
A/B test prompts with temperature control
projects/rag_pdf_chat.py
streamlit run ...
Chat with any PDF
projects/agent.py
streamlit run ...
Multi-tool AI agent
projects/evaluate.py
streamlit run ...
Score and compare AI outputs
projects/multimodal_app.py
streamlit run ...
Image captioning, VQA, text-to-image
Decision Guide
Do you need the AI to know YOUR specific documents/data?
→ YES → RAG (03_rag.md)
Do you need the AI to take actions in the real world?
→ YES → Function Calling (04a, 04b)
Do you need to change the AI's personality/style/format consistently?
→ YES → Fine-tuning (05a, 05b)
Is the AI's output bad/unreliable?
→ Need better quality → Improve system prompt or use RAG
→ Need to measure how bad → Evaluation (06_evaluation.md)
Do you need to understand images?
→ YES → Multi-modal (07_multimodal.md)
Want to deploy publicly?
→ YES → Production (10_production.md)