{"id":20755612,"url":"https://github.com/deepakness/ollama-py","last_synced_at":"2026-03-06T01:02:16.269Z","repository":{"id":224114633,"uuid":"762421748","full_name":"deepakness/ollama-py","owner":"deepakness","description":"Get outputs from local LLMs to Google Sheets.","archived":false,"fork":false,"pushed_at":"2024-02-24T06:49:10.000Z","size":8,"stargazers_count":21,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-25T00:47:27.925Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://untalkedseo.com/locally-running-llms-in-google-sheets","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deepakness.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-23T18:42:39.000Z","updated_at":"2025-06-21T23:18:53.000Z","dependencies_parsed_at":"2024-02-23T21:32:09.317Z","dependency_job_id":"0c1d5a8f-4735-4ced-8e54-467c703bd573","html_url":"https://github.com/deepakness/ollama-py","commit_stats":null,"previous_names":["deepakness/ollama-py"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/deepakness/ollama-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepakness%2Follama-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepakness%2Follama-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepakness%2Follama-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepakness%2Follama-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepakness","download_url":"https://codeload.github.com/deepakness/ollama-py/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepakness%2Follama-py/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30156849,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T22:39:40.138Z","status":"ssl_error","status_checked_at":"2026-03-05T22:39:24.771Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T09:26:28.634Z","updated_at":"2026-03-06T01:02:16.248Z","avatar_url":"https://github.com/deepakness.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# From Local LLMs to Google Sheets\n\nLocally run LLMs like `llama2`, `mistral`, `llava`, etc. on your computer and then get outputs inside Google Sheets.\n\n[Watch this YouTube video](https://www.youtube.com/watch?v=q6b9MIktSAc) for more information on this.\n\n## Requirements\n\n- Python\n- [ollama](https://ollama.com/)\n- [ngrok](https://ngrok.com/)\n- Gmail account for Google Sheets\n\n## Process\n\n### 1. Install the `ollama` app on your computer\n\nAnd run the following command after installing:\n\n```\nollama run mistral\n```\n\nIf you want to use any other model, you can replace `mistral` with other models that [you can find here](https://ollama.com/library).\n\n### 2. Run the Python code\n\nOpen a folder in VS Code or in any other code editor, and create a app.py file, and copy-paste the following code in it:\n\n```python\nfrom flask import Flask, request, jsonify\nimport ollama\n\napp = Flask(__name__)\n\n@app.route('/api/chat', methods=['POST'])\ndef chat():\n    data = request.json\n    response = ollama.chat(model='mistral', messages=[{'role': 'user', 'content': data['content']}])\n    return jsonify(response['message']['content'])\n\nif __name__ == '__main__':\n    app.run(debug=True, port=5001)\n```\n\nIf you're using any other model than `mistral`, make sure to replace in the above code as well.\n\n### 3. Install and run `ngrok`\n\nInstall `ngrok` by following the instruction from the [official website](https://ngrok.com/). You will also have to sign up for a free account, and you'll get a auth token which you can run in the terminal as:\n\n```\nngrok config add-authtoken \u003cAUTH TOKEN\u003e\n```\n\nAfter this, run the following command and it will start listening to the http://localhost:5001 PORT:\n\n```\nngrok http 5001\n```\n\nCopy the `https` forwarding URL you get, it will be used in the next step.\n\n### 4. Prepare Google Sheets Apps Script\n\nNow, you just need to copy-paste the following script inside Google Sheets Apps Script:\n\n```javascript\nfunction onOpen() {\n    var ui = SpreadsheetApp.getUi();\n    ui.createMenu('🎉')\n        .addItem(\"Fetch Ollama Data\", \"callOllamaAPI\")\n        .addToUi();\n  }\n  \n  function callOllamaAPI() {\n    var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();\n    var settingsSheet = spreadsheet.getSheetByName('Settings');\n  \n    // Fetch the settings from Settings Sheet\n    var settingsRange = settingsSheet.getRange(2, 2, 5, 1);\n    var settingsValues = settingsRange.getValues();\n  \n    var startRow = Number(settingsValues[0][0]);\n    var endRow = Number(settingsValues[1][0]);\n    var dataSheet = spreadsheet.getSheetByName(settingsValues[2][0]);\n    var promptColumns = settingsValues[3][0].split(',').map(function(item) { return letterToNum(item.trim()); });\n    var outputColumns = settingsValues[4][0].split(',').map(function(item) { return letterToNum(item.trim()); });\n  \n    for (var i = startRow - 1; i \u003c endRow; i++) {\n      for (var j = 0; j \u003c promptColumns.length; j++) {\n        var promptCell = dataSheet.getRange(i + 1, promptColumns[j]);\n        var finalPrompt = promptCell.getValue();\n  \n        if (!finalPrompt.trim()) {\n          continue;\n        }\n  \n        var outputCell = dataSheet.getRange(i + 1, outputColumns[j]);\n        \n        if (outputCell.getValue() === '') {\n          var ollamaData = {\n            content: finalPrompt\n          },\n          ollamaOptions = {\n              method: 'post',\n              contentType: 'application/json',\n              payload: JSON.stringify(ollamaData)\n          };\n  \n          try {\n            var ollamaResponse = UrlFetchApp.fetch(`\u003cTUNNEL\u003e/api/chat`, ollamaOptions);\n            var ollamaTextResponse = ollamaResponse.getContentText();\n            // Remove the leading and trailing quotation marks from the JSON response and trim any leading/trailing whitespace\n            var ollamaOutput = ollamaTextResponse.slice(1, -1).trim();\n            // If there's a trailing quotation mark left, remove it\n            if (ollamaOutput.endsWith('\"')) {\n                ollamaOutput = ollamaOutput.substring(0, ollamaOutput.length - 1);\n            }\n            // Replace \\n with actual new line characters and \\\" with \"\n            var formattedOutput = ollamaOutput.replace(/\\\\n/g, '\\n').replace(/\\\\\"/g, '\"');\n            outputCell.setValue(formattedOutput);\n          } catch(e) {\n            console.error('Error calling Ollama API: ' + e.toString());\n          }\n        }\n      }  \n    }\n  }\n  \nfunction letterToNum(letter) {\nletter = letter.toUpperCase();\nvar column = 0, length = letter.length;\nfor (var i = 0; i \u003c length; i++) {\n    column += (letter.charCodeAt(i) - 64) * Math.pow(26, length - i - 1);\n}\nreturn column;\n}\n```\n\nReplace the `\u003cTUNNEL\u003e` placeholder with the copied `ngrok` URL.\n\nSave the code and run the script, you may need to authenticate for the very first time.\n\nAnd just like that, you should start seeing your Google Sheets getting outputs from local LLMs running on your computer.\n\nHowever, if you need more information, [this blog post](https://untalkedseo.com/locally-running-llms-in-google-sheets/) talks about the subject in even more detail.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepakness%2Follama-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepakness%2Follama-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepakness%2Follama-py/lists"}