{"id":15177173,"url":"https://github.com/jakubburkiewicz/use-ollama","last_synced_at":"2026-02-05T13:31:54.408Z","repository":{"id":243373524,"uuid":"812272989","full_name":"jakubburkiewicz/use-ollama","owner":"jakubburkiewicz","description":"A custom hook that allows you to use the Ollama API in your React project.","archived":false,"fork":false,"pushed_at":"2024-12-23T17:52:39.000Z","size":87,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-21T04:55:00.573Z","etag":null,"topics":["api","custom-hook","hooks","ollama","react","react-hooks"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/jakubburkiewicz.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}},"created_at":"2024-06-08T12:27:51.000Z","updated_at":"2024-12-23T17:51:57.000Z","dependencies_parsed_at":"2024-06-08T12:38:27.716Z","dependency_job_id":"feca04f2-39d8-40a7-b37c-f82192760fb8","html_url":"https://github.com/jakubburkiewicz/use-ollama","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"72f4cad46f3216aaadaa4d3ddc28890793963551"},"previous_names":["jakubburkiewicz/use-ollama"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jakubburkiewicz/use-ollama","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubburkiewicz%2Fuse-ollama","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubburkiewicz%2Fuse-ollama/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubburkiewicz%2Fuse-ollama/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubburkiewicz%2Fuse-ollama/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakubburkiewicz","download_url":"https://codeload.github.com/jakubburkiewicz/use-ollama/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubburkiewicz%2Fuse-ollama/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29122609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T10:47:47.471Z","status":"ssl_error","status_checked_at":"2026-02-05T10:45:08.119Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["api","custom-hook","hooks","ollama","react","react-hooks"],"created_at":"2024-09-27T14:03:34.815Z","updated_at":"2026-02-05T13:31:54.379Z","avatar_url":"https://github.com/jakubburkiewicz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# useOllama\n\nA custom hook that allows you to use the Ollama API in your React project.\n\n## Installation\n\n```bash\nnpm install use-ollama\n```\n\n## API\n\nFor more information on the Ollama API, visit the [Ollama API documentation](https://github.com/ollama/ollama/blob/main/docs/api.md).\n\n```jsx\n\u003cOllamaProvider\n    host=\"localhost\" // string - host of the Ollama API\n/\u003e\n\nconst {\n    loading, // boolean - Loading state indicator\n    error, // string - Error message\n    response, // object - Response from the API\n    chat, // function - Generate the next message in a chat with a provided model\n    generate, // function - Generate a response for a given prompt with a provided model\n    pull, // function - Download a model from the ollama library\n    push, // function - Upload a model to a model library. Requires registering for ollama.ai and adding a public key first\n    create, // function - Create a model from a Modelfile\n    remove, // function - Delete a model and its data\n    copy, // function - Copy a model. Creates a model with another name from an existing model\n    list, // function - List models that are available locally on the host\n    show, // function - Show information about a model including details, modelfile, template, parameters, license, and system prompt\n    embeddings // function - Generate embeddings from a model\n} = useOllama();\n```\n\n## Usage\n\nHere is a really simple example of how you can use the hook to create a chat-like app.\n\n```jsx\nimport { useEffect, useState } from 'react';\nimport { OllamaProvider, useOllama } from 'use-ollama';\n\nconst App = () =\u003e {\n    return (\n        \u003cOllamaProvider host=\"localhost\"\u003e\n            \u003cComponent /\u003e\n        \u003c/OllamaProvider\u003e\n    )\n}\n\nconst Component = () =\u003e {\n    const { chat, response, error } = useOllama();\n    const [ message, setMessage ] = useState('');\n    const [ messages, setMessages ] = useState([]);\n\n    const handleMessageChange = event =\u003e {\n        setMessage(event.target.value)\n    }\n\n    const handleMessageSend = event =\u003e {\n        setMessages([\n            ...messages,\n            {\n                role: 'user',\n                content: message\n            }\n        ]);\n    }\n\n    useEffect(() =\u003e {\n        const isLatestMessageFromUser = () =\u003e (\n            messages[messages.length - 1]?.role === 'user'\n        )\n\n        const sendMessage = async () =\u003e {\n            const message = {\n                role: 'assistant',\n                content: ''\n            }\n\n            setMessages([\n                ...messages,\n                message\n            ]);\n\n            await chat( {\n                model: 'llama3',\n                messages: messages.map( message =\u003e ( {\n                    role: message.role,\n                    content: message.content\n                } ) ),\n                stream: true\n            } )\n        }\n\n        if( messages.length \u003e 0 \u0026\u0026 isLatestMessageFromUser() ) {\n            sendMessage()\n        }\n    }, [messages, chat]);\n\n    useEffect(() =\u003e {\n        const collectResponse = async response =\u003e {\n            const message = messages[messages.length - 1]\n\n            for await ( const part of response ) {\n                message.content += part.message.content\n\n                setMessages([\n                    ...messages.slice(0, -1),\n                    message\n                ])\n\n                if(part.done === true) {\n                    break\n                }\n            }\n        }\n\n        if(response) {\n            collectResponse(response)\n        }\n    }, [response])\n\n    return (\n        \u003cdiv\u003e\n            \u003cdiv\u003e\n                {messages.map((message, index) =\u003e (\n                    \u003cdiv key={index}\u003e{message.content}\u003c/div\u003e\n                ))}\n            \u003c/div\u003e\n\n            \u003cdiv\u003e\n                \u003cinput\n                    type=\"text\"\n                    value={message}\n                    onChange={handleMessageChange}\n                /\u003e\n\n                \u003cbutton onClick={handleMessageSend}\u003eSend\u003c/button\u003e\n            \u003c/div\u003e\n\n            \u003cdiv\u003e{error}\u003c/div\u003e\n        \u003c/div\u003e\n    )\n}\n\nexport default App\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakubburkiewicz%2Fuse-ollama","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakubburkiewicz%2Fuse-ollama","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakubburkiewicz%2Fuse-ollama/lists"}