Skip to content

Commit

Permalink
feat(ollama): Allow passthrough of other options (#7159)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored Nov 5, 2024
1 parent 50eb6ec commit c75373a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions libs/langchain-community/src/embeddings/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export class OllamaEmbeddings extends Embeddings {
const snakeCasedOption = mapping[key as keyof CamelCasedRequestOptions];
if (snakeCasedOption) {
snakeCasedOptions[snakeCasedOption] = value;
} else {
// Just pass unknown options through
snakeCasedOptions[key] = value;
}
}
return snakeCasedOptions;
Expand Down
5 changes: 4 additions & 1 deletion libs/langchain-ollama/src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface OllamaEmbeddingsParams extends EmbeddingsParams {
* https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values
* for details of the available parameters.
*/
requestOptions?: OllamaCamelCaseOptions;
requestOptions?: OllamaCamelCaseOptions & Partial<OllamaOptions>;
}

export class OllamaEmbeddings extends Embeddings {
Expand Down Expand Up @@ -121,6 +121,9 @@ export class OllamaEmbeddings extends Embeddings {
const snakeCasedOption = mapping[key as keyof OllamaCamelCaseOptions];
if (snakeCasedOption) {
snakeCasedOptions[snakeCasedOption as keyof OllamaOptions] = value;
} else {
// Just pass unknown options through
snakeCasedOptions[key as keyof OllamaOptions] = value;
}
}
return snakeCasedOptions;
Expand Down
15 changes: 15 additions & 0 deletions libs/langchain-ollama/src/tests/embeddings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test, expect } from "@jest/globals";
import { OllamaEmbeddings } from "../embeddings.js";

test("Test OllamaEmbeddings allows passthrough of request options", async () => {
const embeddings = new OllamaEmbeddings({
requestOptions: {
num_ctx: 1234,
numPredict: 4321,
},
});
expect(embeddings.requestOptions).toEqual({
num_ctx: 1234,
num_predict: 4321,
});
});

0 comments on commit c75373a

Please sign in to comment.