Add Auth Token to Ollama Embedding Client (#4766)
* Enhance OllamaEmbedder to support authentication by adding an authorization token in headers for client initialization. * Add optional Auth Token input for Ollama embedding options * move info elements --------- Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
parent
8aa78c2b75
commit
7faee90ecc
@ -14,6 +14,8 @@ export default function OllamaEmbeddingOptions({ settings }) {
|
||||
showAdvancedControls,
|
||||
setShowAdvancedControls,
|
||||
handleAutoDetectClick,
|
||||
authToken,
|
||||
authTokenValue,
|
||||
} = useProviderEndpointAutoDiscovery({
|
||||
provider: "ollama",
|
||||
initialBasePath: settings?.EmbeddingBasePath,
|
||||
@ -48,13 +50,13 @@ export default function OllamaEmbeddingOptions({ settings }) {
|
||||
data-tooltip-id="max-embedding-chunk-length-tooltip"
|
||||
className="flex gap-x-1 items-center mb-3"
|
||||
>
|
||||
<label className="text-white text-sm font-semibold block">
|
||||
Max embedding chunk length
|
||||
</label>
|
||||
<Info
|
||||
size={16}
|
||||
className="text-theme-text-secondary cursor-pointer"
|
||||
/>
|
||||
<label className="text-white text-sm font-semibold block">
|
||||
Max embedding chunk length
|
||||
</label>
|
||||
<Tooltip id="max-embedding-chunk-length-tooltip">
|
||||
Maximum length of text chunks, in characters, for embedding.
|
||||
</Tooltip>
|
||||
@ -134,13 +136,13 @@ export default function OllamaEmbeddingOptions({ settings }) {
|
||||
data-tooltip-id="ollama-batch-size-tooltip"
|
||||
className="flex gap-x-1 items-center mb-3"
|
||||
>
|
||||
<label className="text-white text-sm font-semibold block">
|
||||
Embedding batch size
|
||||
</label>
|
||||
<Info
|
||||
size={16}
|
||||
className="text-theme-text-secondary cursor-pointer"
|
||||
/>
|
||||
<label className="text-white text-sm font-semibold block">
|
||||
Embedding batch size
|
||||
</label>
|
||||
<Tooltip id="ollama-batch-size-tooltip">
|
||||
Number of text chunks to embed in parallel. Higher values
|
||||
improve speed but use more memory. Default is 1.
|
||||
@ -163,6 +165,31 @@ export default function OllamaEmbeddingOptions({ settings }) {
|
||||
faster embedding.
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-white font-semibold block mb-3 text-sm">
|
||||
Auth Token (optional)
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
name="OllamaLLMAuthToken"
|
||||
className="border-none bg-theme-settings-input-bg text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"
|
||||
placeholder="Enter your Auth Token"
|
||||
defaultValue={settings?.OllamaLLMAuthToken ? "*".repeat(20) : ""}
|
||||
value={authTokenValue.value}
|
||||
onChange={authToken.onChange}
|
||||
onBlur={authToken.onBlur}
|
||||
required={false}
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
/>
|
||||
<p className="text-xs leading-[18px] font-base text-white text-opacity-60 mt-2">
|
||||
Enter a <code>Bearer</code> Auth Token for interacting with your
|
||||
Ollama server.
|
||||
<br />
|
||||
Used <b>only</b> if running Ollama behind an authentication
|
||||
server.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -15,7 +15,11 @@ class OllamaEmbedder {
|
||||
? Number(process.env.OLLAMA_EMBEDDING_BATCH_SIZE)
|
||||
: 1;
|
||||
this.embeddingMaxChunkLength = maximumChunkLength();
|
||||
this.client = new Ollama({ host: this.basePath });
|
||||
this.authToken = process.env.OLLAMA_AUTH_TOKEN;
|
||||
const headers = this.authToken
|
||||
? { Authorization: `Bearer ${this.authToken}` }
|
||||
: {};
|
||||
this.client = new Ollama({ host: this.basePath, headers });
|
||||
this.log(
|
||||
`initialized with model ${this.model} at ${this.basePath}. Batch size: ${this.maxConcurrentChunks}, num_ctx: ${this.embeddingMaxChunkLength}`
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user