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

Added optional headers to Ollama initialisation #138

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

ronneldavis
Copy link
Contributor

This continues on the work done by @kpotter-m2 from this issue: #70

Usage example:

import {Ollama} from "ollama";

const myHeaders = new Headers();
myHeaders.append("Authorization", "basic");

const ollama = new Ollama({
  headers: myHeaders
}):

Copy link
Collaborator

@BruceMacD BruceMacD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. This is looking good, nice and simple. Just the one comment about removing the yarn.lock and we will get this in.

yarn.lock Outdated Show resolved Hide resolved
@ronneldavis
Copy link
Contributor Author

@BruceMacD is this good enough to be merged?

Copy link
Collaborator

@BruceMacD BruceMacD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks again for the contribution

@BruceMacD BruceMacD merged commit 3a9d651 into ollama:main Sep 3, 2024
@felixdrp
Copy link

how do you use the headers?
I'm using the version 0.5.9

Does it needs something like?
ollama-js/src
/browser.ts

  constructor(config?: Partial<Config>) {
    this.config = {
      host: '',
    }
    if (!config?.proxy) {
      this.config.host = utils.formatHost(config?.host ?? 'http://127.0.0.1:11434')
    }

+    if (!config?.headers {
+     this.config.headers = config.headers
+   }

    this.fetch = fetch
    if (config?.fetch != null) {
      this.fetch = config.fetch
    }
  }

@NeuroWhAI
Copy link

headers option is still not working.

@NeuroWhAI
Copy link

@felixdrp Here's my solution.

  return new Ollama({
    host: env.OLLAMA_URL,
    fetch: (
      input: string | URL | globalThis.Request,
      init?: RequestInit,
    ): Promise<Response> => {
      if (!init) {
        init = {};
      }
      if (!init.headers) {
        init.headers = {};
      }
      init.headers['Authorization'] = `Bearer ${env.OLLAMA_KEY}`;
      return fetch(input, init);
    },
  });

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 this pull request may close these issues.

4 participants