Calling Large Language Models with Ollama via ReST services: A step-by-step guide for Linux servers.
In our previous video, we showed how to install Ollama and the Open WebUI locally on a Linux system. You can find this first part hereIn this video we show how you can access your local LLM model via ReST Services.
Preparations:
Make sure that your Ollama is accessible from your computer (development environment).
To do this, stop the firewall if necessary:
sudo systemctl disable ufw sudo systemctl stop ufw
Make sure that Ollama is accessible from all computers. To do this, edit the service script:
sudo systemctl edit ollama.service
Add the following lines to the top of the file:
[Service] Environment="OLLAMA_HOST=0.0.0.0"
Restart the service with:
sudo systemctl restart ollama
Then enter in the browser http://deinhost:11434 You should see the message “Ollama is running” in your browser.
Code to call Ollama via ReST:
In the video you can see exactly how you can call Ollama via JavaScript.
You can find the entire code example here on Gitlab.
The video summarized:
In this post I will show you how to Large Language Model (LLM) with Ollama on your Linux server above ReST services If you missed our last post on how to Ollama installed on a Linux server, then check out our tutorial before you continue with this one. This is about how you Ollama above ReST APIs integrated and used directly in your own applications - perfect for those who do not want to use cloud solutions and want to retain maximum control over their data.
1. Preparation: Network configuration and firewall settings
Before you Ollama above ReST services you need to make sure that the Ollama service on your server is accessible over the network. By default, Ollama only accepts connections from the local server. To allow connections from other IP addresses, we need to edit the service configuration.
Sets the variable OLLAMA_HOST
on 0.0.0.0
to Ollama to accept connections from all IP addresses. Make sure that your firewall is correctly configured and the required port is open. You can do this with the command sudo systemctl status firewall
check and adjust if necessary.
2. Test call to Ollama above ReST services
After you have adjusted the network configuration, you can make a simple test call to Ollama above REST With a ReST-GET call you can check whether Ollama runs correctly. Use the IP address of the server and the standard port of Ollama.
If the answer is “Ollama running OK“ appears, then you know that Ollama is ready to respond to requests and the server is correctly configured.
3. POST request for model requests
Now it is about Ollama above Rest for specific model requests. In this example we send a POST request to the ReST API from Ollamato request a text translation. In the JSON body of the request, you specify the model ID and the desired input text. You can also set the option "Disable streaming" to send the model's response in a single response rather than streaming them gradually.
4. Development of a simple web interface to interact with Ollama
To make the whole thing clear, we develop a simple web interface that can be used with the Ollamamodel. The user interface consists of a text input field, a “Translate“ button and an output field.
As soon as the user enters a text and clicks on the button, the request is sent via JavaScript to the ReST API The model then translates the text into English and Spanish. The answer is displayed directly in the output field so the user can see the results immediately.
5. Summary and further steps
With this guide you have a complete solution for using Large Language Models How Ollama above ReST services on your Linux server without having to rely on cloud services. This approach not only gives you maximum control over your data, but also a high level of flexibility, as you Ollama you can integrate directly into your own applications.
You can find this and other exciting content on our YouTube channel CIIT-Software.