Skip to content
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

Linux support #45

Open
danpalmer opened this issue Feb 12, 2025 · 7 comments
Open

Linux support #45

danpalmer opened this issue Feb 12, 2025 · 7 comments

Comments

@danpalmer
Copy link

Hey! It would be great to get Linux support in OllamaKit.

Currently there's a dependency on Combine, which is an Apple OS proprietary framework, rather than a Swift framework. This means that it can only compile for Apple platforms, and not Linux or Windows.

With the increasing use of Swift on the server, Linux support in particular would be great to have. I'm working on a Swift web application that uses Ollama, and have so far used OllamaKit without realising it had this dependency (my own fault!).

How amenable is the project to dropping the Combine dependency? If that's a hard-no, no worries, I can look for alternatively or fork the library.

@pd95
Copy link
Contributor

pd95 commented Mar 5, 2025

Hi @danpalmer

I think this should be possible to do. As far as I have seen, the code provides both APIs natively.
I mean, it has implemented the logic twice: once using Combine and once using Swift async-await.
I do not have a Linux/Docker setup for testing, but I will quickly draft a version which uses #if canImport(Combine) everywhere where Combine is necessary. Then you can check if that's what you want and you can work with...

I will let you know when I have something to test...

Kind regards
Philipp

@pd95
Copy link
Contributor

pd95 commented Mar 5, 2025

OK... it is not that easy... Probably URLSession and URLRequest must be replaced too...

See my "work in progress PR" #48, where I use Github Actions for testing Swift on Linux 😉

@pd95
Copy link
Contributor

pd95 commented Mar 5, 2025

After looking more into details, I know that I had to use where those URLSession and URLRequest elements were missing.

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

Now I'm at a point where the async "convenience method" func bytes(for request: URLRequest) async throws -> (URLSession.AsyncBytes, URLResponse) is missing on Linux.
This seems to be a known limitation of the swift-corelibs-foundation library: swiftlang/swift-corelibs-foundation#3205

Tomorrow I will look into whether I can somehow "simulate" the same API using URLSession.dataTask using a delegate handler. The "shimming" approach shown in kishikawakatsumi/D1Kit@eef9fdb won't work for us, as we need a "streaming API": we want the partial responses from Ollama with continuous progress and not only the final complete response.


I've just found this: swiftlang/swift-corelibs-foundation#4972
But I'm not sure whether this addresses our problem.

@pd95
Copy link
Contributor

pd95 commented Mar 6, 2025

I think, I have a working solution... probably I need to clean it up some more.
But can you please checkout the version available in #48 ?

I would like to do some more testing, but I don't know how... I've only tested in on Mac and used it in an Ollamac for testing. The streaming did work properly. Using GitHub actions, I can confirm, that the package successfully builds on Linux... that's all I can do for the moment.

@danpalmer : Can you help out?

@danpalmer
Copy link
Author

Will give this a go, thanks!

To set expectations, I'm travelling for a few days and without stable internet, and my own Linux build is a day or so of work away from working, so between that and work it might be a little while until I can give this a go.

That said, if it builds and the test suite passes, it's probably all good!

@pd95
Copy link
Contributor

pd95 commented Mar 6, 2025

Test suite? You probably haven’t looked at https://github.com/kevinhermawan/OllamaKit/tree/main/Tests/OllamaKitTests yet 😜

@pd95
Copy link
Contributor

pd95 commented Mar 14, 2025

Great news: I made progress in debugging the Linux issues.
As documented in #48: Streaming responses works now on Linux too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy