refactor: Parse keepAlive value in OllamaEmbeddingsPageAssist
This commit is contained in:
parent
b3a455382c
commit
fadf736f70
@ -15,6 +15,7 @@ import type { StringWithAutocomplete } from "@langchain/core/utils/types";
|
|||||||
import {
|
import {
|
||||||
createOllamaChatStream,
|
createOllamaChatStream,
|
||||||
createOllamaGenerateStream,
|
createOllamaGenerateStream,
|
||||||
|
parseKeepAlive,
|
||||||
type OllamaInput,
|
type OllamaInput,
|
||||||
type OllamaMessage,
|
type OllamaMessage,
|
||||||
} from "./utils/ollama";
|
} from "./utils/ollama";
|
||||||
@ -112,7 +113,7 @@ export class ChatOllama
|
|||||||
this.baseUrl = fields.baseUrl?.endsWith("/")
|
this.baseUrl = fields.baseUrl?.endsWith("/")
|
||||||
? fields.baseUrl.slice(0, -1)
|
? fields.baseUrl.slice(0, -1)
|
||||||
: fields.baseUrl ?? this.baseUrl;
|
: fields.baseUrl ?? this.baseUrl;
|
||||||
this.keepAlive = fields.keepAlive ?? this.keepAlive;
|
this.keepAlive = parseKeepAlive(fields.keepAlive) ?? this.keepAlive;
|
||||||
this.embeddingOnly = fields.embeddingOnly;
|
this.embeddingOnly = fields.embeddingOnly;
|
||||||
this.f16KV = fields.f16KV;
|
this.f16KV = fields.f16KV;
|
||||||
this.frequencyPenalty = fields.frequencyPenalty;
|
this.frequencyPenalty = fields.frequencyPenalty;
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import { Embeddings, EmbeddingsParams } from "@langchain/core/embeddings"
|
import { Embeddings, EmbeddingsParams } from "@langchain/core/embeddings"
|
||||||
import type { StringWithAutocomplete } from "@langchain/core/utils/types"
|
import type { StringWithAutocomplete } from "@langchain/core/utils/types"
|
||||||
|
import { parseKeepAlive } from "./utils/ollama"
|
||||||
|
|
||||||
export interface OllamaInput {
|
export interface OllamaInput {
|
||||||
embeddingOnly?: boolean
|
embeddingOnly?: boolean
|
||||||
f16KV?: boolean
|
f16KV?: boolean
|
||||||
frequencyPenalty?: number
|
frequencyPenalty?: number
|
||||||
headers?: Record<string, string>
|
headers?: Record<string, string>
|
||||||
keepAlive?: string
|
keepAlive?: any
|
||||||
logitsAll?: boolean
|
logitsAll?: boolean
|
||||||
lowVram?: boolean
|
lowVram?: boolean
|
||||||
mainGpu?: number
|
mainGpu?: number
|
||||||
@ -98,7 +99,7 @@ interface OllamaEmbeddingsParams extends EmbeddingsParams {
|
|||||||
headers?: Record<string, string>
|
headers?: Record<string, string>
|
||||||
|
|
||||||
/** Defaults to "5m" */
|
/** Defaults to "5m" */
|
||||||
keepAlive?: string
|
keepAlive?: any
|
||||||
|
|
||||||
/** Advanced Ollama API request parameters in camelCase, see
|
/** 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/jmorganca/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values
|
||||||
@ -138,7 +139,7 @@ export class OllamaEmbeddingsPageAssist extends Embeddings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (params?.keepAlive) {
|
if (params?.keepAlive) {
|
||||||
this.keepAlive = params.keepAlive
|
this.keepAlive = parseKeepAlive(params.keepAlive)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params?.requestOptions) {
|
if (params?.requestOptions) {
|
||||||
|
@ -7,7 +7,7 @@ export interface OllamaInput {
|
|||||||
f16KV?: boolean;
|
f16KV?: boolean;
|
||||||
frequencyPenalty?: number;
|
frequencyPenalty?: number;
|
||||||
headers?: Record<string, string>;
|
headers?: Record<string, string>;
|
||||||
keepAlive?: string;
|
keepAlive?: any;
|
||||||
logitsAll?: boolean;
|
logitsAll?: boolean;
|
||||||
lowVram?: boolean;
|
lowVram?: boolean;
|
||||||
mainGpu?: number;
|
mainGpu?: number;
|
||||||
@ -199,3 +199,11 @@ export async function* createOllamaChatStream(
|
|||||||
): AsyncGenerator<OllamaChatGenerationChunk> {
|
): AsyncGenerator<OllamaChatGenerationChunk> {
|
||||||
yield* createOllamaStream(`${baseUrl}/api/chat`, params, options);
|
yield* createOllamaStream(`${baseUrl}/api/chat`, params, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const parseKeepAlive = (keepAlive: any) => {
|
||||||
|
if (keepAlive === "-1") {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return keepAlive
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user