Compare commits

...

1 Commits

Author SHA1 Message Date
abeatrix 9adecab90c ollama provider configuration
- Fixes: Ensures ollamaBaseUrl falls back to the default ollama endpoint if undefined.
- Enhancements:
  - Updates the model context window to use the configured value from settings.
2025-07-09 12:21:09 -07:00
3 changed files with 13 additions and 8 deletions
+8 -6
View File
@@ -6,18 +6,22 @@ import { convertToOllamaMessages } from "../transform/ollama-format"
import { ApiStream } from "../transform/stream"
import { withRetry } from "../retry"
const DEFAULT_CONTEXT_WINDOW = 32768
export class OllamaHandler implements ApiHandler {
private options: ApiHandlerOptions
private client: Ollama | undefined
constructor(options: ApiHandlerOptions) {
this.options = options
const ollamaApiOptionsCtxNum = (options.ollamaApiOptionsCtxNum ?? DEFAULT_CONTEXT_WINDOW).toString()
this.options = { ...options, ollamaApiOptionsCtxNum }
}
private ensureClient(): Ollama {
if (!this.client) {
try {
this.client = new Ollama({ host: this.options.ollamaBaseUrl || "http://localhost:11434" })
// If ollamaBaseUrl is undefineded, it'd fallback to use the default ollama endpoint.
this.client = new Ollama({ host: this.options.ollamaBaseUrl })
} catch (error) {
throw new Error(`Error creating Ollama client: ${error.message}`)
}
@@ -43,7 +47,7 @@ export class OllamaHandler implements ApiHandler {
messages: ollamaMessages,
stream: true,
options: {
num_ctx: Number(this.options.ollamaApiOptionsCtxNum) || 32768,
num_ctx: Number(this.options.ollamaApiOptionsCtxNum),
},
})
@@ -91,9 +95,7 @@ export class OllamaHandler implements ApiHandler {
getModel(): { id: string; info: ModelInfo } {
return {
id: this.options.ollamaModelId || "",
info: this.options.ollamaApiOptionsCtxNum
? { ...openAiModelInfoSaneDefaults, contextWindow: Number(this.options.ollamaApiOptionsCtxNum) || 32768 }
: openAiModelInfoSaneDefaults,
info: { ...openAiModelInfoSaneDefaults, contextWindow: Number(this.options.ollamaApiOptionsCtxNum) },
}
}
}
@@ -87,7 +87,7 @@ export const OllamaProvider = ({ showModelOptions, isPopup }: OllamaProviderProp
<DebouncedTextField
initialValue={apiConfiguration?.ollamaApiOptionsCtxNum || "32768"}
onChange={(value) => handleFieldChange("ollamaApiOptionsCtxNum", value)}
onChange={(value) => Number(value) > 0 && handleFieldChange("ollamaApiOptionsCtxNum", value)}
style={{ width: "100%" }}
placeholder={"e.g. 32768"}>
<span style={{ fontWeight: 500 }}>Model Context Window</span>
@@ -141,7 +141,10 @@ export function normalizeApiConfiguration(apiConfiguration?: ApiConfiguration):
return {
selectedProvider: provider,
selectedModelId: apiConfiguration?.ollamaModelId || "",
selectedModelInfo: openAiModelInfoSaneDefaults,
selectedModelInfo: {
...openAiModelInfoSaneDefaults,
contextWindow: Number(apiConfiguration?.ollamaApiOptionsCtxNum ?? 32768),
},
}
case "lmstudio":
return {