What to Do After Local LLM Deployment: Building a Private AI Assistant
This article explains how to turn a locally deployed large language model into a private AI assistant that fits real workflows. It covers a three-layer architecture—local inference, RAG orchestration, and spreadsheet macro interaction—along with hardware and model sizing, API configuration, VBA integration, JSON escaping, streaming response parsing, timeout and key management, troubleshooting order, and extension scenarios such as cloud collaboration.
1. Background: Where the Real Value of Local Deployment Lies
Downloading large language model weights to a local machine and starting them with an inference runtime only completes the “it can run” step. Many teams stop there, leaving the model in a command-line interaction window and unable to enter daily workflows, which naturally leads to a low return on investment. The real value of local deployment lies in three things: compliance from keeping data inside the internal network, availability in offline environments, and room for customization from full control over the inference pipeline.
To realize these three benefits, the model must be given an “entry point” and “context.” The entry point determines who can use it and how to use it with the least effort; context determines whether the model understands your private materials. The combination chosen in this article is: a local model runtime for inference, a retrieval-augmented framework for knowledge injection, and spreadsheet macro capabilities for the interaction entry point. Together, these three layers form a true private AI assistant.
2. Overall Architecture: Three Decoupled Layers
It is recommended to split the system into three layers instead of putting all logic into one script:
- Inference layer: a local model runtime that exposes an HTTP interface accessible from the local machine, loads weights, schedules VRAM, and returns generated results.
- Orchestration layer: a retrieval-augmented framework that handles document splitting, vectorization, recall, and prompt assembly, and provides a conversational interface with key-based authentication to upper layers.
- Interaction layer: macro scripts in a spreadsheet document that read questions from cells, send requests, and write results back to specified cells.
The benefit of layering is low replacement cost. Changing the model only touches the inference layer, changing the knowledge base only touches the orchestration layer, and the interaction layer remains almost unchanged.
3. Environment Preparation and Selection Criteria
3.1 Matching Hardware and Model Specifications
The first constraint for local inference is VRAM (or unified memory). As a rule of thumb: a 7B-level model under 4-bit quantization requires about 6–8 GB of available VRAM; a 14B-level model requires about 10–14 GB; a 32B-level model usually requires 24 GB or more, or depends on memory offload, which significantly reduces speed. When selecting a model, do not look only at parameter count; also consider context length—the growth in VRAM usage and latency caused by long context is nonlinear.
3.2 Components to Prepare
- A local model runtime (for model loading and interface exposure);
- Open-weight large language model files, with quantization level selected according to local hardware;
- A local retrieval-augmented framework (providing knowledge base and vector retrieval capabilities);
- A spreadsheet application with macro programming capabilities;
- An embedding model for vectorization, preferably deployed separately from the generation model to avoid competing for VRAM.
3.3 Key Orchestration Layer Configuration Points
In the orchestration framework, explicitly declare the inference backend address and model identifier, and enable authentication. A common mistake here: in some containerized deployments, using localhost as the loopback address points to the container itself. It is better to use 127.0.0.1 or the actual host address consistently. Also confirm that the workspace identifier uses lowercase letters; many frameworks are case-sensitive for paths and identifiers.
4. Interaction Layer: Calling the Local API from a Macro Script
Open the macro editor in your spreadsheet application (a common shortcut is Alt + F11) and insert a new module. The core logic has only five steps: read the cell, build the request, send the request, parse the response, and write back to the cell.
Sub AskLocalModel()Dim q As String, body As String, resp As StringDim http As Objectq = ThisWorkbook.Sheets(1).Range("A2").ValueIf Len(Trim(q)) = 0 Then Exit SubSet http = CreateObject("MSXML2.XMLHTTP.6.0")http.Open "POST", "http://127.0.0.1:8080/api/chat", Falsehttp.setRequestHeader "Content-Type", "application/json"http.setRequestHeader "Authorization", "Bearer " & LocalKey()http.setTimeouts 5000, 10000, 120000, 120000body = "{""message"":""" & EscapeJson(q) & """,""stream"":false}"http.send bodyIf http.Status = 200 ThenThisWorkbook.Sheets(1).Range("A4").Value = ExtractText(http.responseText)ElseThisWorkbook.Sheets(1).Range("A4").Value = "Call failed: " & http.StatusEnd IfEnd Sub
Two helper functions are needed. EscapeJson handles double quotes, backslashes, and line breaks; otherwise, once user input contains a quote, it can break the request body. ExtractText extracts the text from the response. If the API returns streaming data, split by line, filter empty and comment lines, and accumulate incremental text segment by segment instead of deserializing the whole response directly.
Function ExtractText(raw As String) As StringDim lines() As String, i As Long, s As String, out As Stringlines = Split(raw, vbLf)For i = 0 To UBound(lines)s = Trim(lines(i))If Left(s, 5) = "data:" Thens = Trim(Mid(s, 6))If s <> "[DONE]" And Len(s) > 0 Thenout = out & PickContent(s)End IfEnd IfNext iExtractText = Trim(out)End Function
5. Engineering Details That Are Easy to Overlook
- Synchronous blocking:
http.sendis synchronous by default, and long answers will freeze the spreadsheet UI. Acceptable approaches include using a status cell to show “Generating…” or switching to asynchronous callbacks plus polling. - Layered timeouts: give connection timeouts short values and read timeouts long values. Local inference may take tens of seconds to cold-start and load weights; setting timeouts too short is the most common cause of failure.
- Keys not in the sheet: do not hardcode authentication tokens in the module. Read them from environment variables or local configuration to avoid sending them out together with the document.
- Concurrency and VRAM: triggering requests for multiple rows in a batch from the spreadsheet can instantly saturate VRAM and cause queuing. Serialize requests or use a semaphore for control.
- Observability: log latency, input length, output length, and status code for each call to a log file. This is the only basis for later tuning.
6. Recommended Troubleshooting Order
Troubleshooting from the inside out is most efficient: first request the inference layer directly from the command line to confirm the model can generate tokens; then request the orchestration layer to confirm knowledge recall and authentication work; finally check the macro script’s escaping and parsing. Most cases of “the model gives irrelevant answers” are actually knowledge base misses, and most cases of “the call does not respond” are actually timeouts or incorrect addresses.
7. Advanced Scenarios and Cloud Collaboration
After the basic pipeline works, extensible directions include batch summarization and classification of spreadsheet columns, feeding generated results back for validation, adding templated prompt management, and building a cache for high-frequency questions and answers.
When local resources are insufficient, a reasonable architecture is layered collaboration: sensitive data goes through local inference, while general tasks are handled by cloud model services; knowledge base documents can be stored in object storage, and batch tasks can use elastic scaling on a container platform. Link quality depends on logging services and monitoring and alerting systems. Baidu AI Cloud typically provides general category capabilities in such scenarios; specific selection still needs to be evaluated based on data classification and cost model.
8. Conclusion
The endpoint of local deployment is not “the model runs,” but “the model enters the workflow.” By building with a three-layer decoupled approach—inference layer, orchestration layer, and interaction layer—together with rigorous escaping, streaming parsing, timeout and key management, a private AI assistant whose data stays inside the internal network can run stably and retain room for continuous evolution.
