From a68361bb5602b37829ec47b9a6f771a3d3fd6e52 Mon Sep 17 00:00:00 2001 From: Manuel <58395553+cr4yfish@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:44:42 +0100 Subject: [PATCH] feat(ollama): Add support for optional headers (#7052) Co-authored-by: jacoblee93 --- libs/langchain-ollama/package.json | 2 +- libs/langchain-ollama/src/chat_models.ts | 5 +++++ libs/langchain-ollama/src/embeddings.ts | 8 +++++++- libs/langchain-ollama/src/llms.ts | 7 +++++++ yarn.lock | 10 +++++----- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/libs/langchain-ollama/package.json b/libs/langchain-ollama/package.json index 5df996b61191..52ba69a2e33f 100644 --- a/libs/langchain-ollama/package.json +++ b/libs/langchain-ollama/package.json @@ -32,7 +32,7 @@ "author": "LangChain", "license": "MIT", "dependencies": { - "ollama": "^0.5.6", + "ollama": "^0.5.9", "uuid": "^10.0.0" }, "peerDependencies": { diff --git a/libs/langchain-ollama/src/chat_models.ts b/libs/langchain-ollama/src/chat_models.ts index f016f80d3b16..4bb1c7a1a4e7 100644 --- a/libs/langchain-ollama/src/chat_models.ts +++ b/libs/langchain-ollama/src/chat_models.ts @@ -70,6 +70,10 @@ export interface ChatOllamaInput * @default "http://127.0.0.1:11434" */ baseUrl?: string; + /** + * Optional HTTP Headers to include in the request. + */ + headers?: Headers; /** * Whether or not to check the model exists on the local machine before * invoking it. If set to `true`, the model will be pulled if it does not @@ -464,6 +468,7 @@ export class ChatOllama this.client = new Ollama({ host: fields?.baseUrl, + headers: fields?.headers, }); this.baseUrl = fields?.baseUrl ?? this.baseUrl; diff --git a/libs/langchain-ollama/src/embeddings.ts b/libs/langchain-ollama/src/embeddings.ts index afdba456c108..5e878322a6d9 100644 --- a/libs/langchain-ollama/src/embeddings.ts +++ b/libs/langchain-ollama/src/embeddings.ts @@ -32,9 +32,14 @@ interface OllamaEmbeddingsParams extends EmbeddingsParams { */ truncate?: boolean; + /** + * Optional HTTP Headers to include in the request. + */ + headers?: Headers; + /** * Advanced Ollama API request parameters in camelCase, see - * https://github.com/jmorganca/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values + * https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values * for details of the available parameters. */ requestOptions?: OllamaCamelCaseOptions; @@ -58,6 +63,7 @@ export class OllamaEmbeddings extends Embeddings { this.client = new Ollama({ host: fields?.baseUrl, + headers: fields?.headers, }); this.baseUrl = fields?.baseUrl ?? this.baseUrl; diff --git a/libs/langchain-ollama/src/llms.ts b/libs/langchain-ollama/src/llms.ts index bbcd9edf8bc8..b560bc4682ff 100644 --- a/libs/langchain-ollama/src/llms.ts +++ b/libs/langchain-ollama/src/llms.ts @@ -23,7 +23,13 @@ export interface OllamaInput extends BaseLLMParams, OllamaCamelCaseOptions { * @default "http://localhost:11434" */ baseUrl?: string; + format?: string; + + /** + * Optional HTTP Headers to include in the request. + */ + headers?: Headers; } /** @@ -130,6 +136,7 @@ export class Ollama extends LLM implements OllamaInput { : fields?.baseUrl ?? this.baseUrl; this.client = new OllamaClient({ host: this.baseUrl, + headers: fields?.headers, }); this.keepAlive = fields?.keepAlive ?? this.keepAlive; diff --git a/yarn.lock b/yarn.lock index e8e3b962c8ff..8c11df3598a7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12509,7 +12509,7 @@ __metadata: eslint-plugin-prettier: ^4.2.1 jest: ^29.5.0 jest-environment-node: ^29.6.4 - ollama: ^0.5.6 + ollama: ^0.5.9 prettier: ^2.8.3 release-it: ^17.6.0 rollup: ^4.5.2 @@ -35517,12 +35517,12 @@ __metadata: languageName: node linkType: hard -"ollama@npm:^0.5.6": - version: 0.5.6 - resolution: "ollama@npm:0.5.6" +"ollama@npm:^0.5.9": + version: 0.5.9 + resolution: "ollama@npm:0.5.9" dependencies: whatwg-fetch: ^3.6.20 - checksum: f7aafe4f0cf5e3fee9f5be7501733d3ab4ea0b02e0aafacdae90cb5a8babfa4bb4543d47fab152b5424084d3331185a09e584a5d3c74e2cefcf017dc5964f520 + checksum: bfaadcec6273d86fcc7c94e5e9e571a7b6b84b852b407a473f3bac7dc69b7b11815a163ae549b5318267a00f192d39696225309812319d2edc8a98a079ace475 languageName: node linkType: hard