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

Custom headers for Ollama / ChatOllama #4465

Closed
alvarosevilla95 opened this issue Feb 20, 2024 · 1 comment · Fixed by #4466
Closed

Custom headers for Ollama / ChatOllama #4465

alvarosevilla95 opened this issue Feb 20, 2024 · 1 comment · Fixed by #4466
Labels
auto:improvement Medium size change to existing code to handle new use-cases

Comments

@alvarosevilla95
Copy link
Contributor

alvarosevilla95 commented Feb 20, 2024

It seems there is no way to pass custom http headers to a (Chat)Ollama llm. This can be useful in certain cases, and it is possible on the python implementation.

It could be an additional argument passed in the llm instance construction containing the extra headers that should be added to the requests

Copy link

dosubot bot commented Feb 20, 2024

🤖

In the langchainjs framework, you can pass custom HTTP headers to a (Chat)Ollama llm by providing a headers object in the APIChainInput when creating a new APIChain instance. This headers object should be a record of string keys and values, representing the header names and their corresponding values.

Here is an example of how you can do this:

const headers = {
  'Custom-Header-1': 'Value1',
  'Custom-Header-2': 'Value2',
  // Add more headers as needed
};

const apiChain = new APIChain({
  apiAnswerChain: answerChain,
  apiRequestChain: requestChain,
  apiDocs: 'Your API documentation',
  headers: headers, // Pass the headers here
});

In the above code, replace answerChain and requestChain with your actual LLMChain instances, and replace 'Your API documentation' with your actual API documentation.

This is supported by the APIChain class in the provided context, which accepts an APIChainInput object in its constructor. The APIChainInput interface includes an optional headers field of type Record<string, string>. This headers object is then used in the _call method of the APIChain class when making the fetch request.

You can find more details in the APIChain class source code.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases
Projects
None yet
1 participant