{"id":13588421,"url":"https://github.com/ollama/ollama-js","last_synced_at":"2025-05-14T22:06:16.095Z","repository":{"id":194546914,"uuid":"691303110","full_name":"ollama/ollama-js","owner":"ollama","description":"Ollama JavaScript library","archived":false,"fork":false,"pushed_at":"2025-04-16T21:55:33.000Z","size":541,"stargazers_count":3347,"open_issues_count":61,"forks_count":298,"subscribers_count":28,"default_branch":"main","last_synced_at":"2025-05-07T22:00:01.655Z","etag":null,"topics":["javascript","js","ollama"],"latest_commit_sha":null,"homepage":"https://ollama.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ollama.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2023-09-13T22:58:51.000Z","updated_at":"2025-05-06T23:21:41.000Z","dependencies_parsed_at":"2023-09-14T02:38:48.608Z","dependency_job_id":"be82f595-1788-430a-9273-b7c87875ffb3","html_url":"https://github.com/ollama/ollama-js","commit_stats":{"total_commits":136,"total_committers":19,"mean_commits":7.157894736842105,"dds":"0.47058823529411764","last_synced_commit":"6b6221db7b65150f826fd8beeae4d47c755a1de8"},"previous_names":["organicdesign/node-ollama","jmorganca/node-ollama","jmorganca/ollama-js","ollama/ollama-js"],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollama%2Follama-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollama%2Follama-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollama%2Follama-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollama%2Follama-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ollama","download_url":"https://codeload.github.com/ollama/ollama-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235694,"owners_count":22036963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["javascript","js","ollama"],"created_at":"2024-08-01T15:06:42.284Z","updated_at":"2025-05-14T22:06:11.069Z","avatar_url":"https://github.com/ollama.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","javascript","js","A01_文本生成_文本对话","2. Libraries \u0026 Frameworks"],"sub_categories":["大语言对话模型及数据","JavaScript / TypeScript"],"readme":"# Ollama JavaScript Library\n\nThe Ollama JavaScript library provides the easiest way to integrate your JavaScript project with [Ollama](https://github.com/jmorganca/ollama).\n\n## Getting Started\n\n```\nnpm i ollama\n```\n\n## Usage\n\n```javascript\nimport ollama from 'ollama'\n\nconst response = await ollama.chat({\n  model: 'llama3.1',\n  messages: [{ role: 'user', content: 'Why is the sky blue?' }],\n})\nconsole.log(response.message.content)\n```\n\n### Browser Usage\nTo use the library without node, import the browser module.\n```javascript\nimport ollama from 'ollama/browser'\n```\n\n## Streaming responses\n\nResponse streaming can be enabled by setting `stream: true`, modifying function calls to return an `AsyncGenerator` where each part is an object in the stream.\n\n```javascript\nimport ollama from 'ollama'\n\nconst message = { role: 'user', content: 'Why is the sky blue?' }\nconst response = await ollama.chat({ model: 'llama3.1', messages: [message], stream: true })\nfor await (const part of response) {\n  process.stdout.write(part.message.content)\n}\n```\n\n## API\n\nThe Ollama JavaScript library's API is designed around the [Ollama REST API](https://github.com/jmorganca/ollama/blob/main/docs/api.md)\n\n### chat\n\n```javascript\nollama.chat(request)\n```\n\n- `request` `\u003cObject\u003e`: The request object containing chat parameters.\n\n  - `model` `\u003cstring\u003e` The name of the model to use for the chat.\n  - `messages` `\u003cMessage[]\u003e`: Array of message objects representing the chat history.\n    - `role` `\u003cstring\u003e`: The role of the message sender ('user', 'system', or 'assistant').\n    - `content` `\u003cstring\u003e`: The content of the message.\n    - `images` `\u003cUint8Array[] | string[]\u003e`: (Optional) Images to be included in the message, either as Uint8Array or base64 encoded strings.\n  - `format` `\u003cstring\u003e`: (Optional) Set the expected format of the response (`json`).\n  - `stream` `\u003cboolean\u003e`: (Optional) When true an `AsyncGenerator` is returned.\n  - `keep_alive` `\u003cstring | number\u003e`: (Optional) How long to keep the model loaded. A number (seconds) or a string with a duration unit suffix (\"300ms\", \"1.5h\", \"2h45m\", etc.)\n  - `tools` `\u003cTool[]\u003e`: (Optional) A list of tool calls the model may make.\n  - `options` `\u003cOptions\u003e`: (Optional) Options to configure the runtime.\n\n- Returns: `\u003cChatResponse\u003e`\n\n### generate\n\n```javascript\nollama.generate(request)\n```\n\n- `request` `\u003cObject\u003e`: The request object containing generate parameters.\n  - `model` `\u003cstring\u003e` The name of the model to use for the chat.\n  - `prompt` `\u003cstring\u003e`: The prompt to send to the model.\n  - `suffix` `\u003cstring\u003e`: (Optional) Suffix is the text that comes after the inserted text.\n  - `system` `\u003cstring\u003e`: (Optional) Override the model system prompt.\n  - `template` `\u003cstring\u003e`: (Optional) Override the model template.\n  - `raw` `\u003cboolean\u003e`: (Optional) Bypass the prompt template and pass the prompt directly to the model.\n  - `images` `\u003cUint8Array[] | string[]\u003e`: (Optional) Images to be included, either as Uint8Array or base64 encoded strings.\n  - `format` `\u003cstring\u003e`: (Optional) Set the expected format of the response (`json`).\n  - `stream` `\u003cboolean\u003e`: (Optional) When true an `AsyncGenerator` is returned.\n  - `keep_alive` `\u003cstring | number\u003e`: (Optional) How long to keep the model loaded. A number (seconds) or a string with a duration unit suffix (\"300ms\", \"1.5h\", \"2h45m\", etc.)\n  - `options` `\u003cOptions\u003e`: (Optional) Options to configure the runtime.\n- Returns: `\u003cGenerateResponse\u003e`\n\n### pull\n\n```javascript\nollama.pull(request)\n```\n\n- `request` `\u003cObject\u003e`: The request object containing pull parameters.\n  - `model` `\u003cstring\u003e` The name of the model to pull.\n  - `insecure` `\u003cboolean\u003e`: (Optional) Pull from servers whose identity cannot be verified.\n  - `stream` `\u003cboolean\u003e`: (Optional) When true an `AsyncGenerator` is returned.\n- Returns: `\u003cProgressResponse\u003e`\n\n### push\n\n```javascript\nollama.push(request)\n```\n\n- `request` `\u003cObject\u003e`: The request object containing push parameters.\n  - `model` `\u003cstring\u003e` The name of the model to push.\n  - `insecure` `\u003cboolean\u003e`: (Optional) Push to servers whose identity cannot be verified.\n  - `stream` `\u003cboolean\u003e`: (Optional) When true an `AsyncGenerator` is returned.\n- Returns: `\u003cProgressResponse\u003e`\n\n### create\n\n```javascript\nollama.create(request)\n```\n\n- `request` `\u003cObject\u003e`: The request object containing create parameters.\n  - `model` `\u003cstring\u003e` The name of the model to create.\n  - `from` `\u003cstring\u003e`: The base model to derive from.\n  - `stream` `\u003cboolean\u003e`: (Optional) When true an `AsyncGenerator` is returned.\n  - `quantize` `\u003cstring\u003e`: Quanization precision level (`q8_0`, `q4_K_M`, etc.).\n  - `template` `\u003cstring\u003e`: (Optional) The prompt template to use with the model.\n  - `license` `\u003cstring|string[]\u003e`: (Optional) The license(s) associated with the model.\n  - `system` `\u003cstring\u003e`: (Optional) The system prompt for the model.\n  - `parameters` `\u003cRecord\u003cstring, unknown\u003e\u003e`: (Optional) Additional model parameters as key-value pairs.\n  - `messages` `\u003cMessage[]\u003e`: (Optional) Initial chat messages for the model.\n  - `adapters` `\u003cRecord\u003cstring, string\u003e\u003e`: (Optional) A key-value map of LoRA adapter configurations.\n- Returns: `\u003cProgressResponse\u003e`\n\nNote: The `files` parameter is not currently supported in `ollama-js`.\n\n### delete\n\n```javascript\nollama.delete(request)\n```\n\n- `request` `\u003cObject\u003e`: The request object containing delete parameters.\n  - `model` `\u003cstring\u003e` The name of the model to delete.\n- Returns: `\u003cStatusResponse\u003e`\n\n### copy\n\n```javascript\nollama.copy(request)\n```\n\n- `request` `\u003cObject\u003e`: The request object containing copy parameters.\n  - `source` `\u003cstring\u003e` The name of the model to copy from.\n  - `destination` `\u003cstring\u003e` The name of the model to copy to.\n- Returns: `\u003cStatusResponse\u003e`\n\n### list\n\n```javascript\nollama.list()\n```\n\n- Returns: `\u003cListResponse\u003e`\n\n### show\n\n```javascript\nollama.show(request)\n```\n\n- `request` `\u003cObject\u003e`: The request object containing show parameters.\n  - `model` `\u003cstring\u003e` The name of the model to show.\n  - `system` `\u003cstring\u003e`: (Optional) Override the model system prompt returned.\n  - `template` `\u003cstring\u003e`: (Optional) Override the model template returned.\n  - `options` `\u003cOptions\u003e`: (Optional) Options to configure the runtime.\n- Returns: `\u003cShowResponse\u003e`\n\n### embed\n\n```javascript\nollama.embed(request)\n```\n\n- `request` `\u003cObject\u003e`: The request object containing embedding parameters.\n  - `model` `\u003cstring\u003e` The name of the model used to generate the embeddings.\n  - `input` `\u003cstring\u003e | \u003cstring[]\u003e`: The input used to generate the embeddings.\n  - `truncate` `\u003cboolean\u003e`: (Optional) Truncate the input to fit the maximum context length supported by the model.\n  - `keep_alive` `\u003cstring | number\u003e`: (Optional) How long to keep the model loaded. A number (seconds) or a string with a duration unit suffix (\"300ms\", \"1.5h\", \"2h45m\", etc.)\n  - `options` `\u003cOptions\u003e`: (Optional) Options to configure the runtime.\n- Returns: `\u003cEmbedResponse\u003e`\n\n### ps\n\n```javascript\nollama.ps()\n```\n\n- Returns: `\u003cListResponse\u003e`\n\n### abort\n\n```javascript\nollama.abort()\n```\n\nThis method will abort **all** streamed generations currently running with the client instance.\nIf there is a need to manage streams with timeouts, it is recommended to have one Ollama client per stream.\n\nAll asynchronous threads listening to streams (typically the ```for await (const part of response)```) will throw an ```AbortError``` exception. See [examples/abort/abort-all-requests.ts](examples/abort/abort-all-requests.ts) for an example.\n\n## Custom client\n\nA custom client can be created with the following fields:\n\n- `host` `\u003cstring\u003e`: (Optional) The Ollama host address. Default: `\"http://127.0.0.1:11434\"`.\n- `fetch` `\u003cObject\u003e`: (Optional) The fetch library used to make requests to the Ollama host.\n\n```javascript\nimport { Ollama } from 'ollama'\n\nconst ollama = new Ollama({ host: 'http://127.0.0.1:11434' })\nconst response = await ollama.chat({\n  model: 'llama3.1',\n  messages: [{ role: 'user', content: 'Why is the sky blue?' }],\n})\n```\n\n## Building\n\nTo build the project files run:\n\n```sh\nnpm run build\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Follama%2Follama-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Follama%2Follama-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Follama%2Follama-js/lists"}