Local LLM Deployment: Practical Applications and Excel Integration
Once you have a large language model running locally or on an internal server, inference is only the starting point. This article explains how to turn a self-hosted model into a practical business capability, covering a four-layer architecture (inference, orchestration, integration, data), model size selection by available memory, environment setup, and a working VBA macro that connects desktop spreadsheet software to a local model endpoint. It also details JSON escaping, parsing streamed responses, avoiding synchronous UI freezes, prompt template design, and security, observability, and resource practices for keeping sensitive data on-premises.
1. What Actually Changes After Local LLM Deployment
Downloading a model to your own machine or an internal server and getting it to run only completes the “it can infer” step. The real value appears once the model is embedded in daily workflows: data never has to leave the internal network, calls are no longer limited by external quotas, and the response path becomes controllable and observable. Common deployment patterns fall into four categories:
- Document and knowledge Q&A: Turn policy documents, technical manuals, and historical tickets into a searchable knowledge base that can be queried in natural language.
- Structured text generation: Batch-produce summaries, classification labels, email drafts, and first-pass test cases.
- Spreadsheet and report enrichment: Apply semantic processing to a column of data in a table, for example classifying customer feedback as “performance / pricing / service”.
- Internal toolchain integration: Expose a unified service interface so scripts, background jobs, and internal systems can all call the same model.
Among these, “spreadsheet + local model” offers the highest return on investment as an entry point: business users write no code, they only fill in cells, and the data always stays local, which keeps compliance pressure low.
2. Overall Architecture: Four Layers
A robust setup is usually split into four layers, decoupled from each other so problems are easier to isolate:
- Inference layer: The local model runtime loads weights, manages GPU memory and concurrency, and exposes an HTTP interface in a commonly used style.
- Orchestration layer: A middleware service (such as a common local knowledge base / workspace framework) handles workspace isolation, knowledge base retrieval, prompt templates, and access authentication, wrapping the “raw model” into a conversation service that business users can actually use.
- Integration layer: Spreadsheet software issues HTTP requests through scripts, carries authentication information, and receives the returned content.
- Data layer: Raw documents, vector indexes, logs, and call audit records are stored separately so they can be traced back later.
The middleware service is not mandatory, and this is worth stressing. For simple single-turn Q&A, a script can call the inference layer endpoint directly. The orchestration layer only proves its value when you need a knowledge base, multi-turn conversations, or permission isolation.
3. Environment Setup and Model Selection
Inference runtime: Install the local model runtime, confirm its daemon is listening on a local port, and check that you can load a model from the command line. If you deploy with containers, mount the model cache directory as a persistent volume in advance, otherwise rebuilding the container means downloading tens of gigabytes of weights again.
Choosing a model size: Parameter count determines the resource requirement, and this is the first constraint in selection, not “bigger is always better”:
| Memory / VRAM | Recommended direction | Notes |
|---|---|---|
| Around 8 GB | 1.5B–7B quantized | Q&A and summarization work; long-text capability is limited |
| Around 16 GB | 7B–14B quantized | A balanced fit for everyday office scenarios |
| 32 GB and above | 32B and above, or dual-GPU parallelism | More stable for complex reasoning and long document processing |
Quantization (such as 4-bit) significantly reduces resource usage while keeping accuracy loss under control. Context length should match the actual document length; increasing it blindly only drives up VRAM usage and time-to-first-token.
Orchestration service: Install a local workspace framework, fill in the inference layer endpoint address and model name in its configuration, and create an access key. Workspace names are usually required to be lowercase in the API path, and this is the mistake newcomers hit most often.
Spreadsheet environment: You need desktop spreadsheet software with macro execution allowed. If company policy blocks macros across the board, fall back to either “script + command line” or “local small service + web form”.
4. Connecting Model Capability to the Spreadsheet
The core is a button-triggered macro: read the question cell → build the request → send it → parse the response → write the result back to a cell.
Sub AskLocalModel()Dim q As String, body As String, resp As StringDim url As String, key As StringDim http As Objectq = ThisWorkbook.Sheets(1).Range("A2").ValueIf Len(Trim(q)) = 0 Then Exit Suburl = "http://localhost:3001/api/v1/workspace/demo/stream-chat"key = "locally generated access key"Set http = CreateObject("MSXML2.XMLHTTP")http.Open "POST", url, Falsehttp.setRequestHeader "Content-Type", "application/json"http.setRequestHeader "Authorization", "Bearer " & key' Escape double quotes so concatenation does not break the JSONbody = "{""message"":""" & Replace(q, """", """"""") & """,""mode"":""chat""}"http.send bodyIf http.Status = 200 Thenresp = http.responseTextThisWorkbook.Sheets(1).Range("A4").Value = ExtractText(resp)ElseThisWorkbook.Sheets(1).Range("A4").Value = "Call failed: " & http.StatusEnd IfEnd Sub
A few details that must be handled properly:
- JSON escaping: User input containing double quotes, line breaks, or backslashes will break the request body. Always escape consistently, or serialize with a dictionary object instead.
- Parsing streamed responses: If the endpoint returns
text/event-stream, the body consists of multiple event blocks each starting withdata:. Split by line, filter out empty lines and the end marker, then extract and concatenate the text increments segment by segment; do not crudely slice substrings out of the string. - Synchronous blocking:
Falsemeans a synchronous wait, and a long answer will freeze the interface. Switch to asynchronous with status polling, or move the request into a background job. - Result placement: Writing the answer into a fixed cell can easily overwrite existing content. Write it to the column next to the question instead, and add elapsed time and status columns to form a traceable call record.
5. Prompts and Output Quality Control
Small local models are more sensitive to prompts, so it is better to keep prompts fixed in orchestration layer templates rather than scattered across spreadsheet formulas:
- Define the role and boundaries clearly: “Answer only from the provided material; state what is missing when the material is insufficient.”
- Define the output format: require fixed fields or a table so the result is easy to process further.
- Retrieve first, then answer for long documents, instead of stuffing a whole document into the context and diluting key information.
- Add rate limiting and retries to batch jobs so concurrency does not saturate the local inference queue.
6. Security, Stability, and Operations
- Authentication and network boundary: Have the middleware listen only on the loopback or an internal address, and do not hardcode the key in the macro; keep it in a local configuration file that the script reads.
- Input validation: The spreadsheet is an external input entry point, so limit length and filter abnormal characters to prevent injected prompts.
- Observability: Record elapsed time, token usage, and failure reasons for every call, and combine them with general logging and monitoring/alerting capabilities for trend analysis.
- Resource policy: When local inference competes with office applications for memory, set a model concurrency limit or switch to a smaller quantized version; with containerized deployment, use resource limits to keep the host stable.
- Relationship with the cloud: When you need elastic compute, model repository hosting, or object storage archiving, general capabilities from platforms such as Baidu AI Cloud (for example container platform, object storage, and log service) can carry the non-sensitive parts, while sensitive data stays local, forming a hybrid architecture.
7. Conclusion
The value of a local LLM lies not in “getting it running” but in embedding it stably into existing workflows. With the spreadsheet as the entry point and clear separation between the inference, orchestration, and integration layers, business users can gain semantic processing capability with no barrier to entry, without giving up data sovereignty. Start from one high-frequency, low-risk scenario, get the whole path working, then gradually expand to knowledge base Q&A and batch text generation.
