-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Add zero-configuration networking support via zeroconf #751
Conversation
7535750
to
03865ca
Compare
go.mod
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my first time working with Golang, so I'm honestly not sure if the changes to this file are what is expected.
Please let me know if I've unexpectedly broken anything.
go.sum
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my first time working with Golang, so I'm honestly not sure if the changes to this file are what is expected.
Please let me know if I've unexpectedly broken anything.
app/src/index.ts
Outdated
|
||
if (discoveryEnabled) { | ||
discoveryItems.push({ | ||
label: `Network Service: ${process.env.OLLAMA_SERVICE_NAME ?? 'OllamaProvider'}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure if there was a good way to share constant strings between the Golang code in cmd.go
and the TypeScript code in index.ts
, so I just hardcoded the String "OllamaProvider"
in both places.
We could also probably search for the service ourselves here, but I didn't want to introduce too much complexity for such a small feature that is just displaying some info to the user.
03865ca
to
1bcfb48
Compare
This makes the Ollama service discoverable across the local network so that other clients can connect to and use it.
1bcfb48
to
c188699
Compare
@@ -797,6 +799,39 @@ func RunServer(cmd *cobra.Command, _ []string) error { | |||
return err | |||
} | |||
|
|||
if d := os.Getenv("OLLAMA_DISCOVERY"); d == "ENABLED" { | |||
if host != "0.0.0.0" { | |||
host = "0.0.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Network Discovery to work the service needs to be running on the 0.0.0.0
instead of just the 127.0.0.1
loopback.
It's also possible that it might be an even better to approach this purely from the Electron app side and use |
Why are you setting the ip at all? |
Hey there, @technovangelist! With the default host ( With If I want to run Ollama on a device that's powerful enough to run these models but would like to consume them on a device that isn't, I have to run Ollama on mDNS removes the need to have pre-existing knowledge of the Ollama host machine's IP address, and allows a client running on the low-powered device to find and connect to the service without needing to know its IP address beforehand. |
Ahh. I was assuming this was for running the server on the same host and you were hitting cors issues implying you were using fetch rather than obsidians own http request methods which solve those problems. |
The end goal will be to first look for One thing I'm wondering now is if the Ollama app will automatically pick up the |
Hi @ericrallen, this is incredibly cool, and thank you for making a PR. I'm sorry I haven't had the chance to look at this sooner. Networking and service discovery isn't something Ollama is designed to handle right for the time being. Instead, it's designed to be paired with existing tools like Tailscale or similar, so it can stay focused on providing a reliable http service. Sorry about that! |
This proposal allows the Ollama service to be made discoverable via zero configuration networking across the user's local network via Bonjour/Zeroconf/Avahi aka Multicast DNS (mDNS) using the
zeroconf
Go libraryso that other clients can connect to and use it without needing to know the host's IP address.This opens up many different applications for consuming Ollama models served by other network devices.
My particular use case is to add support for Network Discoverable Ollama models to an Obsidian Plugin that I maintain so that users won't have to configure IP addresses in Obsidian or update them if/when IP addresses on their local network change (and also won't have to get into configuring a static IP for the device that is serving their local models).
Note: Network discovery is entirely opt-in via the
OLLAMA_DISCOVERY
environment variable flag being set toENABLED
and will automatically update theOLLAMA_HOST
to0.0.0.0
(the demo GIF was recorded with an earlier iteration of this PR that also required the user to manually set the host IP).Demo
Note: To test this functionality, I created a simple Node.js script on another machine on my network and had it use the
bonjour
package to search for a service with the nameOllamaProvider
. It gets the IP address and port associated with that service and then makes requests to it. I only showed the IP address at the beginning of the GIF to emphasize that the requests are coming from a different machine.It also adds a menu entry with the service name if Network Discovery has been enabled.
Instructions for Testing
gh pr checkout https://github.com/jmorganca/ollama/pull/751
go generate ./...
go build .
cd ./app
npm install
OLLAMA_DISCOVERY=ENABLED npm start
Network Discovery Script