Local LLM Deployment in Practice: Integrating Local Models with Excel

    This article explains how to turn a locally deployed large language model into real workflow value by embedding it into a spreadsheet interface. It covers a three-layer architecture that decouples the spreadsheet, a local knowledge base middleware service, and the local inference runtime; environment setup and model selection; workspace and authentication configuration; VBA code for sending a question from a cell and writing the answer back; and practical upgrades such as batch processing, result layering, context management, and observability. It also outlines security and operations boundaries for local deployments.

    1. Where the Real Value Appears After Local Deployment

    Many teams reach a brief period of confusion after getting local LLM inference running: the model can hold a conversation, but which production process has it actually changed? The answer usually lies not in “chat” itself, but in embedding the model into the work interfaces people already use every day. Local deployment delivers three core benefits: the compliance certainty of keeping data inside the internal network, the stability of running offline, and the room to modify the inference pipeline under your own control. These benefits are only realized when they are combined with a business entry point.

    One long-underestimated entry point is the spreadsheet. Finance, operations, legal, and R&D teams all use spreadsheets for data organization. Questions are written into cells and answers are filled back into cells. This “ask in place” pattern is far more natural than switching to a separate chat window. This article uses the combination of “spreadsheet + local inference service + local knowledge base” to illustrate a typical engineering path for putting a local model into production.

    2. Overall Architecture: Three-Layer Decoupling Is Key

    Split the solution into three layers to avoid hard-coding model invocation logic into spreadsheet macros:

    • Interaction layer: spreadsheet software and macro scripts, responsible for collecting questions, triggering requests, and writing back results;
    • Service layer: a local knowledge base/middleware service, responsible for session management, prompt assembly, knowledge retrieval, authentication, and rate limiting;
    • Inference layer: the local model runtime, responsible for loading weights, executing inference, and outputting streaming or one-shot results.

    The three layers communicate only through HTTP interfaces on the loopback address. The direct benefits are: swapping models does not touch spreadsheet code, changing prompts does not touch the inference layer, and migrating to a container platform or an internal server later only requires replacing where the service layer is deployed.

    3. Environment Setup and Model Selection

    1. Inference runtime. Install a runtime environment that supports local model loading and an OpenAI-compatible interface, confirm its default service port is reachable, and verify readiness through the health check endpoint.
    2. Model weights. Choose a parameter size based on VRAM or memory capacity: an 8B class model suits an ordinary office laptop, 14B to 32B class models need more VRAM, and quantized versions trade some quality for acceptable response speed under limited resources. When selecting, prioritize context length, Chinese language capability, and stability on reasoning tasks rather than blindly chasing the largest parameter count.
    3. Middleware service. Deploy a local knowledge base service with a graphical interface, used to create a “workspace,” import documents, set the system prompt, and enable developer mode to obtain invocation credentials.
    4. Spreadsheet environment. Confirm the spreadsheet software is available and macro execution is allowed; macro capability should be implemented in a way that has no third-party dependencies and assembles requests as plain text, avoiding external dynamic libraries.

    Note that model downloads and runtime installation should be completed through official channels, and the endpoint, port, and credentials should all be stored locally, never written into external links or hard-coded into shared documents.

    4. Service Layer Configuration: Give the Model Knowledge and Boundaries

    Create a new workspace in the knowledge base service, and use lowercase English letters and hyphens for the name, because this name appears in the API path and inconsistent casing is the most common cause of 404 errors. Then complete three things:

    • Mount knowledge: bulk import policy documents, product manuals, and historical tickets, then wait for vectorization to finish;
    • Set the role: state clearly in the system prompt that the model should “answer only based on retrieved material and explicitly say so when the material is insufficient”; this is the most economical way to suppress hallucination;
    • Enable authentication: generate an access credential, keep it only in a local environment variable or a hidden configuration area of the spreadsheet, and do not distribute it with the file.

    5. Calling from the Spreadsheet: From Question to Write-Back

    Open the macro editor and insert a new module. The core flow is “read cell → assemble request → send → parse → write back.” The sample code below only expresses the structure; actual fields follow the local service documentation:

    1. Sub AskLocalModel()
    2. Dim q As String, body As String, resp As String
    3. Dim base As String, token As String
    4. Dim http As Object
    5. q = ThisWorkbook.Sheets(1).Range("A2").Value
    6. If Len(Trim(q)) = 0 Then Exit Sub
    7. base = "http://127.0.0.1:3001/api/v1/workspace/demo/stream-chat"
    8. token = Environ("LOCAL_LLM_TOKEN")
    9. Set http = CreateObject("MSXML2.XMLHTTP")
    10. http.Open "POST", base, False
    11. http.setRequestHeader "Content-Type", "application/json"
    12. http.setRequestHeader "Authorization", "Bearer " & token
    13. body = "{""message"":""" & Replace(q, """", """"""") & """,""mode"":""chat""}"
    14. http.send body
    15. If http.Status = 200 Then
    16. resp = http.responseText
    17. ThisWorkbook.Sheets(1).Range("A4").Value = ExtractAnswer(resp)
    18. Else
    19. ThisWorkbook.Sheets(1).Range("A4").Value = "Call failed: " & http.Status
    20. End If
    21. End Sub

    Three easily overlooked details: first, user input must escape double quotes, otherwise a single quote can break the JSON structure; second, if the server returns a streaming chunked format, split by lines, filter out empty and comment lines, and concatenate text segment by segment instead of deserializing the whole payload; third, synchronous blocking calls freeze the interface, so for long questions switch to asynchronous initiation plus timed polling for write-back.

    6. Four Upgrades from “Usable” to “Good”

    • Batch processing: iterate over a column of questions and write back row by row, with a progress cell and an error column, forming an auditable batch sheet.
    • Layered results: write the “reasoning process” and the “final conclusion” into different cells or different worksheets to make manual review easier.
    • Context management: maintain a session identifier for the same workspace to support multi-turn follow-ups; also limit history length to avoid context bloat slowing down inference.
    • Observability: log request latency, retrieval hit status, and failure reasons in the service layer, and combine local logs with monitoring alerts to pinpoint whether “slow” and “inaccurate” originate in which layer.

    7. Security and Operations Boundaries

    Local deployment does not mean security by default. Once the interface listens on a non-loopback address, you must add authentication, rate limiting, and source restrictions; credentials should live in environment variables or a key management capability and be rotated regularly. Model output is generated content, so when amounts, contract terms, or external statements are involved, keep a human confirmation step. At the resource level, set VRAM and concurrency limits for the inference process to prevent batch jobs from dragging down an office machine.

    8. Conclusion

    The value of a local LLM lies not in replacing search or chat products, but in embedding controllable inference capability into existing workflows. With the spreadsheet as the entry point, the knowledge base service as the hub, and the local runtime as the foundation, this path has low modification cost, clear data boundaries, and can gradually extend to more scenarios such as ticket assistance, report interpretation, and internal Q&A. If higher concurrency and unified operations are needed, the service layer can be migrated to a container platform, with object storage for knowledge documents and logging and monitoring services forming a closed loop; the architecture stays the same, only “local machine” becomes “internal network.”