Skip to content

Commit

Permalink
feat(ollama): Add support for optional headers (#7052)
Browse files Browse the repository at this point in the history
Co-authored-by: jacoblee93 <[email protected]>
  • Loading branch information
cr4yfish and jacoblee93 authored Oct 29, 2024
1 parent 36e27f1 commit a68361b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libs/langchain-ollama/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"author": "LangChain",
"license": "MIT",
"dependencies": {
"ollama": "^0.5.6",
"ollama": "^0.5.9",
"uuid": "^10.0.0"
},
"peerDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions libs/langchain-ollama/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -464,6 +468,7 @@ export class ChatOllama

this.client = new Ollama({
host: fields?.baseUrl,
headers: fields?.headers,
});
this.baseUrl = fields?.baseUrl ?? this.baseUrl;

Expand Down
8 changes: 7 additions & 1 deletion libs/langchain-ollama/src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions libs/langchain-ollama/src/llms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -130,6 +136,7 @@ export class Ollama extends LLM<OllamaCallOptions> implements OllamaInput {
: fields?.baseUrl ?? this.baseUrl;
this.client = new OllamaClient({
host: this.baseUrl,
headers: fields?.headers,
});
this.keepAlive = fields?.keepAlive ?? this.keepAlive;

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a68361b

Please sign in to comment.