|
| 1 | +# LLM Enrichment |
| 2 | + |
| 3 | +AI-BOM can optionally use an LLM to analyze code snippets around detected AI components and extract the specific model names being used (e.g., `gpt-4o`, `claude-3-opus-20240229`, `llama3`). |
| 4 | + |
| 5 | +This fills the `model_name` field that static pattern matching may leave empty, particularly when model names are passed as variables or constructed dynamically. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +LLM enrichment requires the `litellm` package: |
| 12 | + |
| 13 | +```bash |
| 14 | +pip install ai-bom[enrich] |
| 15 | +``` |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### Basic |
| 22 | + |
| 23 | +```bash |
| 24 | +ai-bom scan . --llm-enrich |
| 25 | +``` |
| 26 | + |
| 27 | +This uses `gpt-4o-mini` by default (requires `OPENAI_API_KEY` environment variable). |
| 28 | + |
| 29 | +### With a specific model |
| 30 | + |
| 31 | +```bash |
| 32 | +# OpenAI |
| 33 | +ai-bom scan . --llm-enrich --llm-model gpt-4o |
| 34 | + |
| 35 | +# Anthropic |
| 36 | +ai-bom scan . --llm-enrich --llm-model anthropic/claude-3-haiku-20240307 |
| 37 | + |
| 38 | +# Local Ollama (no API key needed) |
| 39 | +ai-bom scan . --llm-enrich --llm-model ollama/llama3 --llm-base-url http://localhost:11434 |
| 40 | +``` |
| 41 | + |
| 42 | +### With an explicit API key |
| 43 | + |
| 44 | +```bash |
| 45 | +ai-bom scan . --llm-enrich --llm-api-key sk-your-key-here |
| 46 | +``` |
| 47 | + |
| 48 | +If `--llm-api-key` is not provided, litellm falls back to standard environment variables (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, etc.). |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## CLI Options |
| 53 | + |
| 54 | +| Flag | Default | Description | |
| 55 | +|------|---------|-------------| |
| 56 | +| `--llm-enrich` | `False` | Enable LLM enrichment | |
| 57 | +| `--llm-model` | `gpt-4o-mini` | litellm model identifier | |
| 58 | +| `--llm-api-key` | None | API key (falls back to env vars) | |
| 59 | +| `--llm-base-url` | None | Custom API base URL (e.g., Ollama) | |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## How It Works |
| 64 | + |
| 65 | +1. After all scanners run, components with type `llm_provider` or `model` that have an empty `model_name` are selected for enrichment. |
| 66 | +2. For each eligible component, ~20 lines of code around the detection site are read from the source file. |
| 67 | +3. The code snippet is sent to the configured LLM with a prompt asking it to extract the model identifier. |
| 68 | +4. The response is parsed and cross-referenced with AI-BOM's built-in model registry to validate the name and fill in provider/deprecation metadata. |
| 69 | +5. If the LLM call fails or returns no model name, the component is left unchanged. |
| 70 | + |
| 71 | +Components that already have a `model_name` (from static detection) are skipped. Non-model component types (containers, tools, MCP servers, workflows) are never sent to the LLM. |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## Privacy and Security |
| 76 | + |
| 77 | +**Code snippets are sent to the LLM provider.** When using cloud-hosted models (OpenAI, Anthropic, etc.), approximately 20 lines of source code around each detected AI import or usage site are transmitted to the provider's API. |
| 78 | + |
| 79 | +Recommendations: |
| 80 | + |
| 81 | +- **For sensitive or proprietary codebases**, use a local model via Ollama (`--llm-model ollama/llama3`). No data leaves your machine. |
| 82 | +- **Before using cloud APIs**, ensure you have organizational approval to send source code excerpts to the provider. |
| 83 | +- **Only code around detected AI components** is sent — not entire files, not the full repository. |
| 84 | +- AI-BOM does not intentionally include secrets in snippets, but if API keys are hard-coded near import statements, they may be included in the context window. Use `--deep` scanning to detect and remediate hard-coded keys separately. |
| 85 | + |
| 86 | +A warning is printed when using non-local models: |
| 87 | + |
| 88 | +``` |
| 89 | +Warning: LLM enrichment sends code snippets to an external API. |
| 90 | +Use ollama/* models for local-only processing. |
| 91 | +``` |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## Cost |
| 96 | + |
| 97 | +Each eligible component triggers one or more LLM API calls. For projects with many detected AI components, this can result in non-trivial API costs when using paid providers. |
| 98 | + |
| 99 | +- Components are batched (default: 5 per call) to reduce the number of API requests. |
| 100 | +- Use a low-cost model like `gpt-4o-mini` for bulk enrichment. |
| 101 | +- **Ollama is free** — run models locally with zero API cost. |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +## Supported Providers |
| 106 | + |
| 107 | +LLM enrichment uses [litellm](https://docs.litellm.ai/) as its backend, which supports 100+ LLM providers including: |
| 108 | + |
| 109 | +- OpenAI (`gpt-4o`, `gpt-4o-mini`, etc.) |
| 110 | +- Anthropic (`anthropic/claude-3-haiku-20240307`, etc.) |
| 111 | +- Ollama (`ollama/llama3`, `ollama/mistral`, etc.) |
| 112 | +- Azure OpenAI, AWS Bedrock, Google Vertex AI |
| 113 | +- Mistral, Cohere, and many more |
| 114 | + |
| 115 | +See the [litellm provider list](https://docs.litellm.ai/docs/providers) for the full list. |
0 commit comments