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

ollama not using api key #530

Closed
theoden8 opened this issue May 3, 2024 · 13 comments · Fixed by #556
Closed

ollama not using api key #530

theoden8 opened this issue May 3, 2024 · 13 comments · Fixed by #556

Comments

@theoden8
Copy link
Contributor

theoden8 commented May 3, 2024

Good afternoon,

First of all, thank you for a great project. It's by far the only F-Droid app that allows me to use self-hosted LLMs.

It seems that authentication with ollama using api key is not implemented at all, making the app recieve 403 when connecting to my authenticated endpoint.

I believe the parent class of ollama has token, while the child does not use it:

https://github.com/Mobile-Artificial-Intelligence/maid/blob/main/lib/classes/ollama_model.dart (search for "header")

Adding it to the header could be done like this:

davidmigloz/langchain_dart#399

@danemadsen
Copy link
Member

Ahh yes I was aware of this but I forgot to fix it as I didn't think anyone was actually using ollama with a key. Its an easy fix.

@theoden8
Copy link
Contributor Author

theoden8 commented May 3, 2024

I wanted to use ollama on mobile, so ssh -L isn't an option, but running without auth is a bit too much.

I'm using https://github.com/ParisNeo/ollama_proxy_server, which uses bearer token for api key. Not sure if it's compatible but openai client seems to get through.

@danemadsen
Copy link
Member

I'm using langchain dart for ollama so I'll have to look if auth is an option for that.

@davidmigloz
Copy link
Contributor

davidmigloz commented May 5, 2024

When instantiating ChatOllama:

chat = ChatOllama(
baseUrl: '$uri/api',
defaultOptions: ChatOllamaOptions(
model: name,
seed: seed
),
);

You can add custom headers using the headers field. E.g:

final chat = ChatOllama(
  baseUrl: '$uri/api',
  headers: { 'Authorization': 'Bearer: <token>' },
  defaultOptions: ChatOllamaOptions(
    model: name,
    seed: seed
  ),
);

@danemadsen
Copy link
Member

OK this should work

https://github.com/Mobile-Artificial-Intelligence/maid/actions/runs/8966774761

Can't test it myself because I'm out of town and I don't have my laptop

@theoden8
Copy link
Contributor Author

theoden8 commented May 6, 2024

The authentication seems to be missing from the headers. I've installed the version from the link you've provided. I think I'm supposed to see it? Or is it sent separately? As per doc.

danemadsen added a commit to danemadsen/maid that referenced this issue May 11, 2024
danemadsen added a commit that referenced this issue May 11, 2024
@danemadsen
Copy link
Member

@theoden8
Copy link
Contributor Author

Sorry for the delay, had trouble downloading the APK due to some DNS resolution thing.

127.0.0.1 - - [12/May/2024 12:12:45] "GET /api/tags HTTP/1.0" - -
User is not authorized
127.0.0.1 - - [12/May/2024 12:12:45] "GET /api/tags HTTP/1.0" 403 -
127.0.0.1 - - [12/May/2024 12:13:58] "GET /api/tags HTTP/1.0" - -
User is not authorized
127.0.0.1 - - [12/May/2024 12:13:58] "GET /api/tags HTTP/1.0" 403 -

@danemadsen
Copy link
Member

danemadsen commented May 12, 2024 via email

@theoden8
Copy link
Contributor Author

Let me try and print what's being sent and what's being received.

@theoden8
Copy link
Contributor Author

theoden8 commented May 12, 2024

@theoden8
Copy link
Contributor Author

Another problem is that "Bearer: " is incorrect as per https://datatracker.ietf.org/doc/html/rfc6750.

@bartolli
Copy link

bartolli commented Jun 8, 2024

Check out my repo, it’s a simple, secure way to manage API key authentication for your Ollama apps with a Caddy server.

https://github.com/bartolli/ollama-bearer-auth-caddy

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

Successfully merging a pull request may close this issue.

4 participants