[READ-ONLY] Mirror of https://github.com/thoda-dev/nuxt-ollama. Simple integration of the official Ollama JavaScript Library for your Nuxt application.
0

Configure Feed

Select the types of activity you want to include in your feed.

support for cloud models on ollama.com using api key

Thomas (Oct 29, 2025, 6:37 PM +0100) 6cc83086 c0fc65ed

+172 -14
+97
CONTRIBUTING.md
··· 1 + # Contributing to nuxt-ollama 2 + 3 + Thank you for taking the time to contribute — we’re excited to collaborate with you! This project aims to be welcoming, kind, and inclusive. Whether you’re fixing a typo, filing a bug, improving docs, or adding features, your help is appreciated. 4 + 5 + ## 💛 Our guiding principles 6 + - Be kind and respectful. Assume positive intent. 7 + - Value all contributions, big and small. 8 + - Communicate clearly and empathetically. Prefer constructive feedback. 9 + - Be inclusive: use welcoming, gender‑neutral language and avoid sarcasm. 10 + - Celebrate learning. It’s okay to ask questions and to make mistakes. 11 + 12 + We follow a simple Code of Conduct: no harassment, no discrimination, no personal attacks. If something makes you uncomfortable, please open a private issue or contact a maintainer. 13 + 14 + ## 🧭 Ways to contribute 15 + - Report bugs 16 + - Suggest enhancements 17 + - Improve documentation or examples 18 + - Write tests 19 + - Implement features (discuss first if non-trivial) 20 + 21 + ## 🐞 Bug reports 22 + Please include: 23 + - What happened and what you expected instead 24 + - Steps to reproduce (minimal repro if possible) 25 + - Environment: Node.js version, pnpm version, OS, Nuxt version 26 + - Logs or screenshots when relevant 27 + 28 + Create a new issue and label it clearly. If you can, propose a hypothesis or a failing test. 29 + 30 + ## 💡 Feature requests 31 + Before starting work, open an issue to discuss: 32 + - The problem you’re solving and motivation 33 + - Proposed API/behavior (simple examples help) 34 + - Alternatives considered 35 + 36 + We aim to keep the module simple and focused. 37 + 38 + ## 🛠️ Local development 39 + This repository is a Nuxt module with a playground for testing. 40 + 41 + Prerequisites: 42 + - Node.js (project uses Volta pin: 24.11.0) 43 + - pnpm (packageManager: pnpm@10.20.0) 44 + 45 + Common tasks: 46 + - Prepare module and playground 47 + - pnpm run dev:prepare 48 + - Run the playground dev server 49 + - pnpm run dev 50 + - Lint 51 + - pnpm run lint 52 + - Type-check 53 + - pnpm run test:types 54 + - Tests (Vitest) 55 + - pnpm run test 56 + 57 + Tip: If you add a new public option or server/composable utility, also update the types in `src/runtime/types/` as needed and add an example usage in `playground/`. 58 + 59 + ## 🧪 Tests 60 + - Add or update tests for behavior changes. 61 + - For fixes, consider writing a failing test first. 62 + - Keep tests fast and focused; prefer unit tests when possible. 63 + 64 + ## ✏️ Code style 65 + - Follow the existing ESLint and TypeScript setup (run `pnpm run lint` and `pnpm run test:types`). 66 + - Prefer small, focused PRs over large ones. 67 + - Keep public APIs documented (JSDoc or README snippets). 68 + 69 + ## 🧾 Commit messages 70 + We recommend Conventional Commits for clarity and changelog generation, for example: 71 + - feat: add XYZ option to runtime config 72 + - fix: handle missing model name in server util 73 + - docs: clarify playground setup 74 + - test: add unit tests for useOllama composable 75 + - refactor: simplify error handling 76 + 77 + Prefix with `feat`, `fix`, `docs`, `test`, `refactor`, `chore`, etc. Use imperative mood and keep the subject short. 78 + 79 + ## 🌿 Branching and PRs 80 + - Create a topic branch from `master` (e.g. `feat/xyz`, `fix/edge-case`). 81 + - Keep PRs focused and include a short description of the change and motivation. 82 + - Checklist before opening a PR: 83 + - [ ] Lint passes (`pnpm run lint`) 84 + - [ ] Types pass (`pnpm run test:types`) 85 + - [ ] Tests pass (`pnpm run test`) 86 + - [ ] Docs updated (README/inline comments/playground if relevant) 87 + 88 + We’ll review kindly and promptly. If changes are requested, they’re meant to help — we’re on the same team. 89 + 90 + ## 🔐 Security 91 + If you discover a vulnerability, please do not open a public issue. Instead, contact a maintainer privately so we can coordinate a fix. 92 + 93 + ## 📜 License and attribution 94 + By contributing, you agree that your contributions will be licensed under the MIT License of this repository. 95 + 96 + ## 🙏 Thank you 97 + Your time and energy make this project better for everyone. We’re grateful you’re here — welcome! ❤️
+19 -2
README.md
··· 43 43 const ollama = useOllama() 44 44 45 45 const response = await ollama.chat({ 46 - model: 'llama3.1', 46 + model: 'gpt-oss:120b', 47 47 messages: [{ role: 'user', content: 'Why is the sky blue?' }], 48 48 }) 49 49 console.log(response.message.content) ··· 52 52 See [documentation](https://nuxt-ollama.jericho.dev/) for more information or examples. 53 53 54 54 ## Settings 55 + 56 + ### Local models 55 57 56 58 ```ts 57 59 // nuxt.config.ts ··· 66 68 }) 67 69 ``` 68 70 71 + ### - Cloud models with API key on https://ollama.com 72 + 73 + ```ts 74 + // nuxt.config.ts 75 + export default defineNuxtConfig({ 76 + //... 77 + ollama: { 78 + protocol: 'https', // or 'https' 79 + host: 'ollama.com', //domain or ip address 80 + api_key: 'your_api_key_here' // your Ollama API key 81 + } 82 + }) 83 + ``` 84 + 85 + 69 86 ## Contribution 70 87 71 88 Contributions are welcome, feel free to open an issue or submit a pull request! 72 89 73 - *guidelines coming soon* 90 + Please see the [contributing guide](CONTRIBUTING.md) for details. 74 91 75 92 <details> 76 93 <summary>Local development</summary>
+18
playground/app.vue
··· 1 1 <template> 2 2 <div> 3 3 Nuxt module playground! 4 + <h2>Models:</h2> 5 + <div> 6 + <button @click="refreshList()"> 7 + Refresh Models 8 + </button> 9 + </div> 10 + <ul> 11 + <li 12 + v-for="model in list" 13 + :key="model.name" 14 + > 15 + {{ model.name }} 16 + </li> 17 + </ul> 18 + <h2>Chat:</h2> 4 19 <div 5 20 v-for="(m, i) in messages" 6 21 :key="'message_'+i" ··· 29 44 </button> 30 45 </div> 31 46 </div> 47 + <h2>API Fetch Test:</h2> 32 48 <div style="margin-top:50px;"> 33 49 <pre>{{ response }}</pre> 34 50 <button @click="refresh()"> ··· 72 88 } 73 89 74 90 const { data: response, refresh } = await useFetch('/api/ollama') 91 + 92 + const { data: list, refresh: refreshList } = await useFetch('/api/list') 75 93 </script>
+10 -4
playground/nuxt.config.ts
··· 2 2 3 3 modules: ['../src/module'], 4 4 devtools: { enabled: true }, 5 - compatibilityDate: '2025-10-24', 5 + compatibilityDate: '2025-10-29', 6 + 7 + // ollama: { 8 + // protocol: 'http', 9 + // host: 'localhost', 10 + // port: 11434, 11 + // }, 6 12 7 13 ollama: { 8 - protocol: 'http', 9 - host: 'localhost', 10 - port: 11434, 14 + protocol: 'https', 15 + host: 'ollama.com', 16 + api_key: process.env.OLLAMA_API_KEY, 11 17 }, 12 18 })
+4
playground/server/api/list.get.ts
··· 1 + export default defineEventHandler(async () => { 2 + const ollama = useOllama() 3 + return (await ollama.list()).models 4 + })
+4 -3
playground/server/api/ollama.get.ts
··· 1 - export default defineEventHandler(() => { 1 + export default defineEventHandler(async () => { 2 2 const ollama = useOllama() 3 - return ollama.chat({ 4 - model: 'llama3.2', 3 + return await ollama.chat({ 4 + model: 'gpt-oss:120b', 5 5 messages: [ 6 6 { 7 7 role: 'user', 8 8 content: 'Hello', 9 9 }, 10 10 ], 11 + think: false, 11 12 }) 12 13 })
+4 -2
src/module.ts
··· 6 6 export interface ModuleOptions extends OllamaOptions { 7 7 protocol: string 8 8 host: string 9 - port: number 9 + port: number | null 10 10 proxy: boolean 11 + api_key: string | null 11 12 } 12 13 13 14 export default defineNuxtModule<ModuleOptions>({ ··· 22 23 defaults: { 23 24 protocol: 'http', 24 25 host: 'localhost', 25 - port: 11434, 26 + port: null, 26 27 proxy: false, 28 + api_key: null, 27 29 }, 28 30 setup(_options, _nuxt) { 29 31 const resolver = createResolver(import.meta.url)
+7 -1
src/runtime/composables/useOllama.ts
··· 4 4 5 5 export function useOllama() { 6 6 const options: ModuleOptions = useRuntimeConfig().public.ollama as ModuleOptions 7 + const headers: Record<string, string> = {} 8 + if (options.api_key) { 9 + headers.Authorization = `Bearer ${options.api_key}` 10 + } 11 + const host = `${options.protocol}://${options.host}${options.port ? `:${options.port}` : ''}` 7 12 return new Ollama({ 8 - host: `${options.protocol}://${options.host}:${options.port}`, 13 + host, 9 14 proxy: options.proxy, 15 + headers, 10 16 }) 11 17 }
+7 -1
src/runtime/server/utils/useOllama.ts
··· 4 4 5 5 export function useOllama() { 6 6 const options: ModuleOptions = useRuntimeConfig().public.ollama as ModuleOptions 7 + const headers: Record<string, string> = {} 8 + if (options.api_key) { 9 + headers.Authorization = `Bearer ${options.api_key}` 10 + } 11 + const host = `${options.protocol}://${options.host}${options.port ? `:${options.port}` : ''}` 7 12 return new Ollama({ 8 - host: `${options.protocol}://${options.host}:${options.port}`, 13 + host, 9 14 proxy: options.proxy, 15 + headers, 10 16 }) 11 17 }
+2 -1
src/types/OllamaOptions.ts
··· 1 1 export interface OllamaOptions { 2 2 protocol: string 3 3 host: string 4 - port: number 4 + port: number | null 5 5 proxy: boolean 6 + api_key: string | null 6 7 }