{"id":47,"date":"2024-08-13T04:15:46","date_gmt":"2024-08-13T04:15:46","guid":{"rendered":"https:\/\/kylehayhurst.com\/?p=47"},"modified":"2024-08-13T04:51:45","modified_gmt":"2024-08-13T04:51:45","slug":"private-llm-chats-with-ollama-and-open-webui-including-llama-3-1","status":"publish","type":"post","link":"https:\/\/kylehayhurst.com\/?p=47","title":{"rendered":"Private LLM Chats with Ollama and Open WebUI &#8211; including LLaMa 3.1"},"content":{"rendered":"\n<p>Perhaps you&#8217;re concerned about chatting with one of these publicly hosted LLMs, or you&#8217;ve continuously hit your limit on the number of questions asked. These are just a few of the reasons you may want to run an LLM locally.<\/p>\n\n\n\n<p>I&#8217;ll be using docker to run these applications because I like being able to easily update them and not have to worry about the dependencies.<\/p>\n\n\n\n<p>Below is the docker-compose file used to define the services that will be pulled and run:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-\">services:\n  ollama:\n    ports:\n      - 11434:11434\n    volumes:\n      - .\/ollama:\/root\/.ollama\n    container_name: ollama\n    pull_policy: always\n    tty: true\n    restart: unless-stopped\n    image: ollama\/ollama:${OLLAMA_DOCKER_TAG-latest}\n    deploy:\n      resources:\n        reservations:\n          devices:\n            - driver: nvidia\n              count: 1\n              capabilities: [gpu]\n  open-webui:\n    image: ghcr.io\/open-webui\/open-webui:${WEBUI_DOCKER_TAG-main}\n    container_name: open-webui\n    volumes:\n      - .\/openwebui:\/app\/backend\/data\n    depends_on:\n      - ollama\n    ports:\n      - ${OPEN_WEBUI_PORT-3001}:8080\n    environment:\n      - &quot;OLLAMA_API_BASE_URL=http:\/\/ollama:11434\/api&quot;\n      - &quot;WEBUI_SECRET_KEY=&quot;\n    restart: unless-stopped<\/code><\/pre>\n\n\n\n<p>I typically name this docker-compose.yml or something along those lines. A few things that need mentioning, wherever you save this file, you need to create the directories &#8220;ollama&#8221; and &#8220;openwebui&#8221;. These directories will be filled with data required to run the containers successfully.<\/p>\n\n\n\n<p>Take note of the ports in use as well, 11434 for ollama and 3001 for open webui.<\/p>\n\n\n\n<p>With the docker-compose file in place and the directories created, simply use the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker compose up<\/code><\/pre>\n\n\n\n<p>To pull the containers and start the services. You can use the &#8216;-d&#8217; option to have it run in the background, but I like to see the output on the first run to see if any errors occurred.<\/p>\n\n\n\n<p>You should be able to see that the services are running correctly by navigating to: <a href=\"http:\/\/localhost:11434\/\">http:\/\/localhost:11434\/<\/a> for ollama, and <a href=\"http:\/\/localhost:3001\/\">http:\/\/localhost:3001\/<\/a> for open-webui. You can also check the state of the containers using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker ps<\/code><\/pre>\n\n\n\n<p>When navigating to open-webui, you&#8217;ll be greeted by a login screen. Create an account and login to see a home screen like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"660\" src=\"https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-1024x660.png\" alt=\"\" class=\"wp-image-48\" srcset=\"https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-1024x660.png 1024w, https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-300x193.png 300w, https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-768x495.png 768w, https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image.png 1479w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You&#8217;ll notice that there are no models loaded, ollama does not install a default model for you to interact with. On the <a href=\"https:\/\/github.com\/ollama\/ollama?tab=readme-ov-file#cli-reference\">ollama github<\/a>, you&#8217;ll see a bunch of CLI references. But if you&#8217;re not that familiar with docker, you may ask, how do you run these CLI commands if we&#8217;re just running docker containers. There are some options, specifically &#8216;-it&#8217;, that allow us to connect to a container and open a terminal session.<\/p>\n\n\n\n<p>You&#8217;ll need the &#8220;docker ps&#8221; command to display the container&#8217;s ID.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"107\" src=\"https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-1-1024x107.png\" alt=\"\" class=\"wp-image-49\" srcset=\"https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-1-1024x107.png 1024w, https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-1-300x31.png 300w, https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-1-768x81.png 768w, https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-1.png 1402w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then use it with the docker exec -it {CONTAINER ID} bash command. Replace the container ID with the one associated to you ollama container, and don&#8217;t use curly braces, like so:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker exec -it 1ee1cabfe771 bash<\/code><\/pre>\n\n\n\n<p>This should get you into the container to run commands such as &#8220;ollama list&#8221; which shows you the list of downloaded models, which is likely still empty.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"576\" height=\"95\" src=\"https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-2.png\" alt=\"\" class=\"wp-image-50\" srcset=\"https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-2.png 576w, https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-2-300x49.png 300w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><\/figure>\n\n\n\n<p>Running the command &#8220;ollama pull llama3.1&#8221; will download the LLaMa 3.1 model. Once it&#8217;s complete you can see the model has downloaded by running the &#8220;ollama list&#8221; command.<\/p>\n\n\n\n<p>Simply refresh the open-webui page and you should now be able to select this model from the dropdown.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"931\" height=\"243\" src=\"https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-3.png\" alt=\"\" class=\"wp-image-52\" srcset=\"https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-3.png 931w, https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-3-300x78.png 300w, https:\/\/kylehayhurst.com\/wp-content\/uploads\/2024\/08\/image-3-768x200.png 768w\" sizes=\"auto, (max-width: 931px) 100vw, 931px\" \/><\/figure>\n\n\n\n<p>This is all you need to start chatting with LLaMa 3.1. This will likely be a base for other projects I work on using AI so I&#8217;ll leave this post short and simple.<\/p>\n\n\n\n<p>If you happen to see where I could improve anything, feel free to leave a comment!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Perhaps you&#8217;re concerned about chatting with one of these publicly hosted LLMs, or you&#8217;ve continuously hit your limit on the number of questions asked. These are just a few of the reasons you may want to run an LLM locally. I&#8217;ll be using docker to run these applications because I like being able to easily [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[8,5,7,4,6],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-docker","tag-llama","tag-llm","tag-ollama","tag-open-webui"],"_links":{"self":[{"href":"https:\/\/kylehayhurst.com\/index.php?rest_route=\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kylehayhurst.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kylehayhurst.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kylehayhurst.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kylehayhurst.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=47"}],"version-history":[{"count":6,"href":"https:\/\/kylehayhurst.com\/index.php?rest_route=\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":62,"href":"https:\/\/kylehayhurst.com\/index.php?rest_route=\/wp\/v2\/posts\/47\/revisions\/62"}],"wp:attachment":[{"href":"https:\/\/kylehayhurst.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kylehayhurst.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kylehayhurst.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}