Practical Ways to Put a Locally Deployed LLM to Work

    After deploying a large language model locally, most people stop at chatting with it in a terminal. This article explains how to turn a local model into a service that business software can call: the three core benefits of local deployment, the layered architecture (inference runtime, knowledge base middleware, office spreadsheet layer), working VBA code for calling a streaming chat endpoint from a spreadsheet, how to parse text/event-stream responses, how to surface reasoning output, and a hardening plus troubleshooting checklist. Readers will learn how to keep sensitive data on-premises, control cost, and build a private assistant without sending content to external networks.

    1. Where the Value Actually Comes From

    Many people download a model to their machine, chat with it a few times from the command line, and then leave it idle. The real problem is not that “the model isn’t strong enough” — it’s that the model never enters the workflow. Local deployment delivers three core benefits:

    1. Data stays inside your network: contracts, financial reports, medical records, and code snippets never have to travel over external networks, which significantly reduces compliance pressure.
    2. Predictable cost structure: a one-time hardware investment replaces per-call billing, so high-volume, long-context batch jobs have a marginal cost close to zero.
    3. Deep customization: you decide the model size, context length, system prompt, knowledge base chunking strategy, and even quantization level to fit your VRAM.

    To realize these benefits, the model has to be wrapped as a service that business software can call. A typical chain looks like this:

    1. Spreadsheet app (VBA/script) → Knowledge base middleware (authenticated HTTP API) → Local inference service (model runtime) → Model weights

    Every layer is replaceable: the spreadsheet app can be any office suite or a custom front end; the middleware can be an open-source knowledge base framework or a lightweight service you write yourself; the inference service loads the weights and exposes a compatible API.

    2. Environment Setup and Layer Responsibilities

    2.1 Inference Runtime Layer

    Install a local model runtime. It handles model download, quantization, and VRAM scheduling, and exposes an HTTP API that follows a common specification. A useful rule of thumb when picking a model size: VRAM capacity roughly determines the parameter scale you can host. A 7B-class model runs smoothly on a consumer GPU, while 14B and above usually need more VRAM or more aggressive quantization. Pulling the weights the first time requires a network connection; after that you can run fully offline.

    2.2 Knowledge Base Middleware Layer

    A common pain point with local deployment is that “the model doesn’t know your private material.” The middleware chunks documents, vectorizes them, retrieves matches, and stitches the hits into the prompt. It typically offers two capabilities: a workspace concept for isolating corpora by topic, and a token-authenticated chat API with streaming support.

    Configuration: in the middleware settings, enter the inference service address and model name, create an access token, and note the internal workspace identifier (usually required to be all lowercase).

    2.3 Office Spreadsheet Layer

    Using a spreadsheet app as the example, open the built-in script editor (Alt + F11), insert a module, and issue requests with the built-in HTTP object. No extra dependencies are needed, which makes this a good way to validate the setup quickly.

    3. Core Code: From a Spreadsheet Cell to a Model Response

    The code below is illustrative and shows the whole flow: building the request, the auth header, reading the streamed response, and writing the result back. The address, token, and workspace identifier are all placeholders.

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

    This approach has two pitfalls that must be fixed:

    • Unescaped double quotes: a single quote character in the user’s question breaks the JSON. The example above escapes them with Replace, but a safer approach is a general-purpose JSON serialization function.
    • No timeout set: local inference can take tens of seconds on long input, and the default timeout will cut the request off early.

    4. The Tricky Part: Parsing a Streamed Response

    The API returns text/event-stream, a body made of multiple data: lines and terminated by [DONE]. Because the request is synchronous, what you get in one shot is the concatenated text, so the parsing strategy is: split by line → drop lines that don’t start with data: → strip the prefix and parse each JSON fragment → accumulate the text field. An illustrative implementation:

    1. Function ExtractText(raw As String) As String
    2. Dim lines() As String, i As Long, s As String, out As String
    3. lines = Split(Replace(raw, vbCrLf, vbLf), vbLf)
    4. For i = 0 To UBound(lines)
    5. s = Trim(lines(i))
    6. If Left(s, 5) = "data:" Then
    7. s = Trim(Mid(s, 6))
    8. If s <> "[DONE]" And Len(s) > 2 Then
    9. out = out & PickText(s) ' pull the incremental text from the fragment JSON
    10. End If
    11. End If
    12. Next
    13. ExtractText = out
    14. End Function

    If you want a typewriter effect, you need to switch to an asynchronous request and read in chunks, which adds noticeable complexity. In an office scenario, getting the complete result first is usually enough.

    5. Showing the Reasoning Process Too

    Reasoning models emit reasoning content separately from the final answer. If the middleware returns both a reasoning field and an answer field, accumulate them separately and write them to two cells (for example, reasoning in A3 and the final answer in A4). That gives you a direct view of the model’s reasoning chain inside the spreadsheet and makes it easier to check whether a conclusion is sound.

    6. Security and Stability Hardening

    • Bind to loopback only: have the inference service and middleware listen on 127.0.0.1; don’t expose them to the LAN or the public internet.
    • Least-privilege tokens: issue separate tokens per workspace to make auditing and revocation easier.
    • Cap input length: truncate the question in the script so it can’t exceed the context window and throw an error.
    • Throttle batch jobs: call serially with a delay between requests so a full VRAM allocation doesn’t stall the whole machine.
    • Redact logs: when troubleshooting, log status codes and elapsed time only — don’t write full prompts to disk.

    7. Troubleshooting Order

    1. Connection refused → the inference service isn’t running or the port is wrong;
    2. 401 → wrong token or missing Bearer prefix;
    3. 404 → workspace identifier case mismatch;
    4. Garbled text in the cell → streamed fragments weren’t parsed correctly; check the prefix filtering logic;
    5. Extremely slow response → the model size exceeds your VRAM; drop to a lower quantization level.

    8. Where to Take It Next

    Once the chain is working, you can extend it: turn the spreadsheet into a batch ticket classifier; connect an internal document library for policy Q&A; use a scheduled task to generate a daily summary; and, in environments with a container platform and object storage, package the whole stack into an image that can be replicated to other machines for a team-level private assistant. If you need elastic inference or a unified gateway, you can also evaluate general-purpose container, object storage, and monitoring/alerting services on Baidu AI Cloud as the underlying platform.