Views
No views yet
transformers library — using Meta Llama 3.1 8B Instruct as the working model.kanikatestmodel/
├── phase-1-model-verification/ ← warm-up: get the model running locally
│ ├── ai_experiment.py
│ ├── ai_llama_cleanchat.py
│ └── README.md
├── phase-2-inference-prompting/ ← reusable inference + prompt engineering
│ ├── inference/ LlamaInference, chat template, structured output
│ │ ├── base_inference.py
│ │ ├── chat_template_example.py
│ │ └── structured_output.py
│ ├── prompts/ markdown prompt catalogues
│ │ ├── system_prompts.md
│ │ └── instruction_prompts.md
│ ├── tests/ assertion + observational tests
│ │ ├── test_structured_output.py
│ │ ├── test_temperature_vs_top_p.py
│ │ └── test_max_tokens.py
│ └── README.md
└── phase-3-rag/ ← current focus: end-to-end RAG
├── data/sample_docs/ 4 short markdown source documents
├── ingestion/ chunker → embedder → build_index
├── retrieval/ Retriever (top-K over Chroma)
├── rag/ RagPipeline (retrieval + grounded prompt + Llama)
├── prompts/ system_prompts.md (rag_grounded_assistant)
├── tests/ test_retriever.py, test_rag_grounded.py
└── README.mdLlamaInference wrapper from Phase 2 with a vector database so the model answers from a small corpus of source documents instead of pretraining alone.Retriever (MiniLM + Chroma) + grounded prompt + LlamaInference. There is no extra magic.| Phase | When it runs | What it does |
|---|---|---|
| Ingestion | Once per document | chunk → embed → write to vector DB |
| Query | Every user question | embed query → top-K search → grounded prompt → LLM |
ingestion/ — chunker.py (pure word-window splitter), embedder.py (sentence-transformers/all-MiniLM-L6-v2, 384-dim), build_index.py (CLI that walks a folder, chunks, batch-embeds, persists to Chroma).retrieval/retriever.py — Retriever.query(question, k=4) returning [{"text", "source", "chunk_index", "score"}, ...]. Hard-fails if no index exists, with a hint pointing at build_index.rag/pipeline.py — RagPipeline.answer(question) returning {"answer", "sources", "hits"}. The grounded prompt explicitly tells the model to refuse with a fixed phrase when the context is silent — that refusal-on-silence is what makes RAG more than autocomplete.tests/ — test_retriever.py (no LLM, fast); test_rag_grounded.py (loads Llama, asserts both that good context produces a grounded answer AND that off-topic questions trigger the refusal phrase, not a hallucination from pretraining).phase-3-rag/ for the full per-module walkthrough and design rationale.inference/ — building blocksbase_inference.py — a LlamaInference class that loads the model once (~16 GB in bfloat16) and exposes a clean .generate(messages, temperature, top_p, max_tokens, do_sample) method. This is the foundation everything else in Phase 2 imports.chat_template_example.py — demonstrates the proper multi-role chat template (system + user + assistant + user) so the model can answer follow-up questions with full conversational context.structured_output.py — generate_json(...) helper that combines a strict system prompt with low temperature to force the model to return parseable JSON, then loads it into a real Python dict.prompts/ — content separated from code| File | Purpose | Example name | Sent as |
|---|---|---|---|
system_prompts.md | Who the model is — persona, tone, global rules | json_extractor, python_tutor, creative_writer | system message |
instruction_prompts.md | What task to perform on this turn | summarize, extract_movie_info, classify_sentiment | user message |
system_prompt × any instruction_prompt = a working, reusable inference call.tests/ — verify behavior, build intuitiontest_structured_output.py) — must pass. Calls generate_json(...) and asserts the returned dict has the expected fields and types. Catches regressions when prompts or models change.test_temperature_vs_top_p.py, test_max_tokens.py) — no assertions; sends the same prompt with different generation knobs and prints the outputs side-by-side. Designed to make the abstract effects of temperature, top_p, and max_tokens concrete.phase-2-inference-prompting/ for code, prompts, and how to run each module.ai_experiment.py — a single-shot pirate-themed chat completion. Verifies the model loads and runs.ai_llama_cleanchat.py — an interactive console chat loop with warnings/logs silenced for a cleaner UX.phase-1-model-verification/ for the scripts and the full setup walkthrough (gated-model access, virtual env, dependencies, troubleshooting).1# 1. Clone
2git clone https://huggingface.co/kanika23oct/kanikatestmodel
3cd kanikatestmodel
4
5# 2. Set up Python environment
6python -m venv venv
7.\venv\Scripts\Activate.ps1
8pip install transformers torch accelerate # Phase 2
9pip install sentence-transformers chromadb # Phase 3 (added)
10
11# 3. Authenticate with Hugging Face (Llama 3.1 is gated)
12huggingface-cli login
13
14# 4. Run a Phase 2 module
15cd phase-2-inference-prompting
16python -m inference.structured_output
17python -m tests.test_structured_output
18
19# 5. Run the Phase 3 RAG pipeline
20cd ..\phase-3-rag
21python -m ingestion.build_index # build the vector store (one-time per docs change)
22python -m tests.test_retriever # fast sanity check (no LLM)
23python -m tests.test_rag_grounded # end-to-end RAG with Llama (slow on CPU)A GPU with ≥ 16 GB VRAM is strongly recommended for any phase that loads Llama; CPU inference works but is impractically slow (multiple minutes per generation).
SESSION_NOTES.md. Headline items:test_rag_grounded.py end-to-end (CPU torch makes it slow), citation parsing, bigger corpus, optional re-ranking.RagPipeline.answer behind a POST /rag HTTP endpoint.load_prompt(name) helper that wires the markdown catalogues to code.