# microsoft/phicookbook architecture

> Architecture diagram of the GitHub repository microsoft/phicookbook, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/phicookbook
- Repository: https://github.com/microsoft/phicookbook

## Overview

Phi Cookbook is a collection of independent, hands-on examples for using Microsoft Phi models—not one integrated application. Its user-to-result path varies by sample: users provide prompts, files, or datasets; an example performs inference, retrieval, evaluation, or fine-tuning; and the result is generated text, a ranked answer, or a trained model. The README also describes deployment across cloud and edge environments and capabilities including reasoning, coding, vision, and audio. The sampled source supports the WebGPU RAG and .NET sample links shown; other links are limited to README-level capability descriptions because those implementations were not sampled.

Main entry points: [`code/08.RAG/rag_webgpu_chat/main.js`](https://github.com/microsoft/phicookbook/blob/main/code/08.RAG/rag_webgpu_chat/main.js) (Browser chat), [`md/04.HOL/dotnet/src/LabsPhi304/Program.cs`](https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi304/Program.cs) (.NET vision chat), [`md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/Program.cs`](https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/Program.cs) (GenAI chat client), [`code/08.RAG/rag_webgpu_chat/rag.js`](https://github.com/microsoft/phicookbook/blob/main/code/08.RAG/rag_webgpu_chat/rag.js) (RAG retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_rag["Browser RAG"]
  node_browser["Browser chat<br/>[main.js]"]
  node_retrieval["RAG retrieval<br/>[rag.js]"]
  node_phiweb["Phi WebGPU<br/>[phi3_slm.js]"]
  node_localrag["Local hybrid RAG"]
  node_promptflow["Prompt Flow RAG"]
end

subgraph group_training["Fine-tuning"]
  node_traintext["Text fine-tuning"]
  node_trainvision["Vision fine-tuning"]
  node_dataset["Dataset generation"]
  node_docvqa["DocVQA training"]
  node_memes["Meme training"]
  node_nlvr["Visual reasoning training"]
  node_ucf["Video training"]
end

subgraph group_inference["Inference examples"]
  node_olive["ONNX inference demo<br/>[app.py]"]
  node_chat["Command-line chat<br/>[chat.py]"]
  node_eval["Reasoning evaluation<br/>[reasoning_eval.py]"]
  node_vscode["VS Code Phi<br/>[extension.ts]"]
  node_imageembed["Image embeddings"]
end

subgraph group_dotnet[".NET samples"]
  node_vision[".NET vision chat<br/>[Program.cs]"]
  node_console["Console presentation"]
  node_chatclient["GenAI chat client<br/>[Program.cs]"]
  node_clientoptions["Prompt options"]
  node_audio["Audio inference<br/>[Program.cs]"]
end

node_developer(("Developer"))
node_modelruntime["Phi model runtime"]
node_user(("User"))

node_user -->|"asks question"| node_browser
node_browser -->|"queries"| node_retrieval
node_browser -->|"initializes"| node_retrieval
node_retrieval -->|"generates tokens"| node_phiweb
node_user -->|"uses example"| node_localrag
node_user -->|"uses example"| node_promptflow
node_user -->|"fine-tunes"| node_traintext
node_user -->|"fine-tunes"| node_trainvision
node_user -->|"fine-tunes"| node_docvqa
node_user -->|"fine-tunes"| node_memes
node_user -->|"fine-tunes"| node_nlvr
node_user -->|"fine-tunes"| node_ucf
node_user -->|"generates dataset"| node_dataset
node_user -->|"runs inference"| node_olive
node_user -->|"chats with"| node_chat
node_user -->|"evaluates reasoning"| node_eval
node_user -->|"uses coding assistant"| node_vscode
node_user -->|"processes images"| node_imageembed
node_user -->|"asks about image"| node_vision
node_vision -->|"displays output"| node_console
node_vision -->|"runs inference"| node_modelruntime
node_user -->|"asks question"| node_chatclient
node_chatclient -->|"gets defaults"| node_clientoptions
node_chatclient -->|"streams response"| node_modelruntime
node_user -->|"transcribes audio"| node_audio
node_audio -->|"generates transcript"| node_modelruntime

click node_browser "https://github.com/microsoft/phicookbook/blob/main/code/08.RAG/rag_webgpu_chat/main.js"
click node_retrieval "https://github.com/microsoft/phicookbook/blob/main/code/08.RAG/rag_webgpu_chat/rag.js"
click node_phiweb "https://github.com/microsoft/phicookbook/blob/main/code/08.RAG/rag_webgpu_chat/phi3_slm.js"
click node_localrag "https://github.com/microsoft/phicookbook/blob/main/code/06.E2E/E2E_Phi-4-mini_Local_Hybrid_RAG_SQLite_FTS5.py"
click node_promptflow "https://github.com/microsoft/phicookbook/blob/main/code/07.Lab/RAG_with_PromptFlow_and_AISearch/prompt-flow-frontend.py"
click node_traintext "https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/FineTrainingScript.py"
click node_trainvision "https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/Phi-3-vision-Trainingscript.py"
click node_dataset "https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/generate_dataset.py"
click node_docvqa "https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/vision_finetuning/finetune_hf_trainer_docvqa.py"
click node_memes "https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/vision_finetuning/finetune_hf_trainer_hateful_memes.py"
click node_nlvr "https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/vision_finetuning/finetune_hf_trainer_nlvr2.py"
click node_ucf "https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/vision_finetuning/finetune_hf_trainer_ucf101.py"
click node_olive "https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/olive-ort-example/app/app.py"
click node_chat "https://github.com/microsoft/phicookbook/blob/main/code/01.Introduce/chat.py"
click node_eval "https://github.com/microsoft/phicookbook/blob/main/md/02.Application/03.AdvancedReasoning/Phi4/LogicalReasoningEval/reasoning_eval.py"
click node_vscode "https://github.com/microsoft/phicookbook/blob/main/code/09.UpdateSamples/Aug/vscode/phiext/src/extension.ts"
click node_imageembed "https://github.com/microsoft/phicookbook/blob/main/code/06.E2E/phi3imageembedding.py"
click node_vision "https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi304/Program.cs"
click node_console "https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi304/SpectreConsoleOutput.cs"
click node_chatclient "https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/Program.cs"
click node_clientoptions "https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/OnnxRuntimeGenAIChatClientOptionsGenerator.cs"
click node_audio "https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi4-MultiModal-02Audio/Program.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_retrieval,node_phiweb,node_localrag,node_promptflow,node_user toneBlue
class node_traintext,node_trainvision,node_dataset,node_docvqa,node_memes,node_nlvr,node_ucf toneAmber
class node_olive,node_chat,node_eval,node_vscode,node_imageembed toneMint
class node_vision,node_console,node_chatclient,node_clientoptions,node_audio toneRose
class node_developer,node_modelruntime toneIndigo
```

## Components

### Browser RAG

- [Browser chat](https://github.com/microsoft/phicookbook/blob/main/code/08.RAG/rag_webgpu_chat/main.js): `code/08.RAG/rag_webgpu_chat/main.js`
- [RAG retrieval](https://github.com/microsoft/phicookbook/blob/main/code/08.RAG/rag_webgpu_chat/rag.js): `code/08.RAG/rag_webgpu_chat/rag.js`
- [Phi WebGPU](https://github.com/microsoft/phicookbook/blob/main/code/08.RAG/rag_webgpu_chat/phi3_slm.js): `code/08.RAG/rag_webgpu_chat/phi3_slm.js`
- [Local hybrid RAG](https://github.com/microsoft/phicookbook/blob/main/code/06.E2E/E2E_Phi-4-mini_Local_Hybrid_RAG_SQLite_FTS5.py): `code/06.E2E/E2E_Phi-4-mini_Local_Hybrid_RAG_SQLite_FTS5.py`
- [Prompt Flow RAG](https://github.com/microsoft/phicookbook/blob/main/code/07.Lab/RAG_with_PromptFlow_and_AISearch/prompt-flow-frontend.py): `code/07.Lab/RAG_with_PromptFlow_and_AISearch/prompt-flow-frontend.py`

### Fine-tuning

- [Text fine-tuning](https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/FineTrainingScript.py): `code/03.Finetuning/FineTrainingScript.py`
- [Vision fine-tuning](https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/Phi-3-vision-Trainingscript.py): `code/03.Finetuning/Phi-3-vision-Trainingscript.py`
- [Dataset generation](https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/generate_dataset.py): `code/03.Finetuning/generate_dataset.py`
- [DocVQA training](https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/vision_finetuning/finetune_hf_trainer_docvqa.py): `code/03.Finetuning/vision_finetuning/finetune_hf_trainer_docvqa.py`
- [Meme training](https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/vision_finetuning/finetune_hf_trainer_hateful_memes.py): `code/03.Finetuning/vision_finetuning/finetune_hf_trainer_hateful_memes.py`
- [Visual reasoning training](https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/vision_finetuning/finetune_hf_trainer_nlvr2.py): `code/03.Finetuning/vision_finetuning/finetune_hf_trainer_nlvr2.py`
- [Video training](https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/vision_finetuning/finetune_hf_trainer_ucf101.py): `code/03.Finetuning/vision_finetuning/finetune_hf_trainer_ucf101.py`

### Inference examples

- [ONNX inference demo](https://github.com/microsoft/phicookbook/blob/main/code/03.Finetuning/olive-ort-example/app/app.py): `code/03.Finetuning/olive-ort-example/app/app.py`
- [Command-line chat](https://github.com/microsoft/phicookbook/blob/main/code/01.Introduce/chat.py): `code/01.Introduce/chat.py`
- [Reasoning evaluation](https://github.com/microsoft/phicookbook/blob/main/md/02.Application/03.AdvancedReasoning/Phi4/LogicalReasoningEval/reasoning_eval.py): `md/02.Application/03.AdvancedReasoning/Phi4/LogicalReasoningEval/reasoning_eval.py`
- [VS Code Phi](https://github.com/microsoft/phicookbook/blob/main/code/09.UpdateSamples/Aug/vscode/phiext/src/extension.ts): `code/09.UpdateSamples/Aug/vscode/phiext/src/extension.ts`
- [Image embeddings](https://github.com/microsoft/phicookbook/blob/main/code/06.E2E/phi3imageembedding.py): `code/06.E2E/phi3imageembedding.py`

### .NET samples

- [.NET vision chat](https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi304/Program.cs): `md/04.HOL/dotnet/src/LabsPhi304/Program.cs`
- [Console presentation](https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi304/SpectreConsoleOutput.cs): `md/04.HOL/dotnet/src/LabsPhi304/SpectreConsoleOutput.cs`
- [GenAI chat client](https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/Program.cs): `md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/Program.cs`
- [Prompt options](https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/OnnxRuntimeGenAIChatClientOptionsGenerator.cs): `md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/OnnxRuntimeGenAIChatClientOptionsGenerator.cs`
- [Audio inference](https://github.com/microsoft/phicookbook/blob/main/md/04.HOL/dotnet/src/LabsPhi4-MultiModal-02Audio/Program.cs): `md/04.HOL/dotnet/src/LabsPhi4-MultiModal-02Audio/Program.cs`

### Other components

- **Developer**
- **Phi model runtime**
- **User**

## Connections

- User → Browser chat: asks question (evidence: `README.md`)
- Browser chat → RAG retrieval: queries (evidence: `code/08.RAG/rag_webgpu_chat/main.js`)
- Browser chat → RAG retrieval: initializes (evidence: `code/08.RAG/rag_webgpu_chat/main.js`)
- RAG retrieval → Phi WebGPU: generates tokens (evidence: `code/08.RAG/rag_webgpu_chat/rag.js`)
- User → Local hybrid RAG: uses example (evidence: `README.md`)
- User → Prompt Flow RAG: uses example (evidence: `README.md`)
- User → Text fine-tuning: fine-tunes (evidence: `README.md`)
- User → Vision fine-tuning: fine-tunes (evidence: `README.md`)
- User → DocVQA training: fine-tunes (evidence: `README.md`)
- User → Meme training: fine-tunes (evidence: `README.md`)
- User → Visual reasoning training: fine-tunes (evidence: `README.md`)
- User → Video training: fine-tunes (evidence: `README.md`)
- User → Dataset generation: generates dataset (evidence: `README.md`)
- User → ONNX inference demo: runs inference (evidence: `README.md`)
- User → Command-line chat: chats with (evidence: `README.md`)
- User → Reasoning evaluation: evaluates reasoning (evidence: `README.md`)
- User → VS Code Phi: uses coding assistant (evidence: `README.md`)
- User → Image embeddings: processes images (evidence: `README.md`)
- User → .NET vision chat: asks about image (evidence: `md/04.HOL/dotnet/src/LabsPhi304/Program.cs`)
- .NET vision chat → Console presentation: displays output (evidence: `md/04.HOL/dotnet/src/LabsPhi304/Program.cs`)
- .NET vision chat → Phi model runtime: runs inference (evidence: `md/04.HOL/dotnet/src/LabsPhi304/Program.cs`)
- User → GenAI chat client: asks question (evidence: `md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/Program.cs`)
- GenAI chat client → Prompt options: gets defaults (evidence: `md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/Program.cs`)
- GenAI chat client → Phi model runtime: streams response (evidence: `md/04.HOL/dotnet/src/LabsPhi4-Chat-03GenAIChatClient/Program.cs`)
- User → Audio inference: transcribes audio (evidence: `md/04.HOL/dotnet/src/LabsPhi4-MultiModal-02Audio/Program.cs`)
- Audio inference → Phi model runtime: generates transcript (evidence: `md/04.HOL/dotnet/src/LabsPhi4-MultiModal-02Audio/Program.cs`)
