Local Deployment of Open-Source LLMs: Building a Private AI Assistant with Spreadsheet Software
Deploying an open-source Large Language Model (LLM) locally transforms it from a simple chat interface into a versatile inference engine. This article explores how to build a private AI assistant directly within spreadsheet software by combining a local inference engine, an application framework, and VBA scripting. It covers the overall architecture, environment setup, core code implementation, and optimization strategies, enabling you to perform secure, automated text processing and Q&A without relying on cloud APIs.
1. What Can You Do After Local Deployment?
Once an open-source LLM is deployed locally, it becomes more than just a chat window; it serves as an “inference engine” that can be called by programs at any time. Common application directions include:
- Personal Knowledge Base Q&A: Importing local documents into a Retrieval-Augmented Generation (RAG) framework allows the model to answer questions based on your own materials, which is ideal for organizing notes, policy documents, and technical manuals.
- Office Automation: Integrating the model into daily office tools, such as asking questions, generating summaries, translating, or polishing content directly within spreadsheet software.
- Batch Text Processing: Classifying, tagging, or extracting key fields from hundreds or thousands of data entries. These tasks can be accomplished by looping through API calls.
- Private Data Security: All data remains on the local machine, making it suitable for handling sensitive information—a significant advantage over cloud APIs.
This article focuses on one of the most representative scenarios: integrating a local LLM into spreadsheet software to create an on-demand private AI assistant. Technically, this solution involves three layers: model service, middleware framework, and script programming. Once mastered, this architecture can be adapted to other scenarios.
2. Overall Architecture Design
The core workflow follows a three-tier structure:
Spreadsheet Software (Frontend Interaction) -> Knowledge Base/Application Framework (API Gateway) -> Local Inference Service (Model Execution)
The responsibilities of each layer are as follows:
- Spreadsheet Software Layer: Handles user interaction. Users enter questions in a cell, trigger a script via a button to send an HTTP request, and write the returned result to a designated cell.
- Middleware Framework Layer: Manages conversations and exposes APIs. A locally deployed LLM application framework typically provides standardized HTTP interfaces, supporting workspace isolation, conversation history management, and document retrieval, while abstracting the complexity of underlying model calls.
- Model Service Layer: The local inference engine loads model weights and executes inference. It exposes services through a unified local API specification, which is the mainstream approach for deploying open-source models locally today.
3. Environment Preparation
1. Deploy a Local Inference Engine
First, install a local model runtime framework responsible for model downloading, quantized loading, and inference services. After installation, pull an appropriate model using a command similar to:
ollama pull deepseek-r1:7b
Model Selection Recommendations:
| VRAM/RAM Condition | Recommended Specification |
|---|---|
| Below 8GB | 1.5B quantized version |
| 8-16GB | 7B/8B quantized version |
| Over 24GB VRAM | 14B and above |
Quantized versions significantly reduce resource requirements with minimal precision loss, allowing even standard office laptops to run small models smoothly.
2. Build the Application Framework
Install an open-source LLM application framework. In its configuration, point the model provider to the local inference engine’s API address (e.g., http://localhost:11434) and select the downloaded model. The framework will typically launch a local web service (e.g., listening on port 3001) and support creating multiple “workspaces” to isolate conversations and knowledge bases for different purposes.
After creating a workspace, generate an API key in the settings page for script authentication later. Note that workspace names must be in lowercase in the URL.
3. Prepare the Spreadsheet Environment
Ensure you have mainstream spreadsheet software installed and possess basic macro (VBA) programming skills. Design a simple UI layout:
- Cell A2: Input question
- Button: Binds a macro to trigger the call on click
- Cell A4: Displays the model’s thinking process and answer
4. Core Code Implementation
Open the macro editor in your spreadsheet software (shortcut Alt + F11), insert a module, and write the following code:
Sub CallLocalLLM()Dim question As String, response As StringDim url As String, apiKey As StringDim http As Object' Read the questionquestion = ThisWorkbook.Sheets(1).Range("A2").Value' The middleware framework's streaming chat endpoint and API keyurl = "http://localhost:3001/api/v1/workspace/myworkspace/stream-chat"apiKey = "Replace with your generated API Key"Set http = CreateObject("MSXML2.XMLHTTP")http.Open "POST", url, Falsehttp.setRequestHeader "accept", "text/event-stream"http.setRequestHeader "Content-Type", "application/json"http.setRequestHeader "Authorization", "Bearer " & apiKey' Construct the request bodyDim body As Stringbody = "{""message"":""" & question & """,""mode"":""chat""}"http.send body' Process the responseIf http.Status = 200 Thenresponse = http.responseTextThisWorkbook.Sheets(1).Range("A4").Value = ParseNestedJSON(response)ElseMsgBox "Request failed, status code: " & http.StatusEnd IfEnd Sub
Key implementation details to consider:
- Streaming Response Parsing: The API returns responses in Server-Sent Events (SSE) format, where the body consists of multiple JSON segments prefixed with
data:. You need to write aParseNestedJSONfunction to extract and concatenate text fields segment by segment. Even without streaming rendering, the content must be split by lines and merged. - Request Body Escaping: If the question contains quotes or newline characters, directly concatenating the JSON will cause the request to fail. It is recommended to escape special characters.
- Synchronous vs. Asynchronous: The example uses a synchronous request, which is simple and reliable but blocks the UI. For a better user experience, you can switch to asynchronous callbacks or split it into multiple polls.
- Timeout Control: Local model inference time depends on model size and hardware performance. Small models return within seconds, while large models may take tens of seconds. The script should set reasonable timeout expectations.
5. Extensions and Optimization Directions
After completing the basic Q&A, you can further evolve the solution:
- Integrate Private Knowledge Base: Upload local documents to the workspace. The framework will automatically handle chunking, vectorization, and retrieval. When asking questions, the model will answer based on your materials, which is ideal for querying internal company policies or technical documentation.
- Batch Processing: Write a loop script to send 100 rows of data in Column A into the model one by one for classification or summarization, and write the results in Column B, achieving lightweight data cleaning.
- Switch Models: The inference engine supports multiple models simultaneously. You can flexibly switch based on task difficulty—use small models for simple tasks to ensure speed, and large models for complex reasoning to ensure quality.
- Security Reminders: Even with local deployment, API keys should not be hardcoded in shared files. It is recommended to store keys in environment variables or protected configuration areas, and enable signatures and permission controls for macros.
6. Conclusion
The value of local deployment lies not just in “running” the model, but in “using” it. By combining a local inference engine, an application framework, and spreadsheet scripts, you can build an AI assistant that keeps data strictly on the local machine at zero cloud cost. The key to this architecture is the standardized HTTP interface—mastering it once allows you to embed LLM capabilities into any office tool that supports script extensions, truly making AI a part of your daily workflow.
