diff --git a/src/browser.ts b/src/browser.ts index dc61e71..1ea64f7 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -25,6 +25,7 @@ import type { ShowResponse, StatusResponse, } from './interfaces.js' +import { defaultHost } from './defaultHost.js' export class Ollama { protected readonly config: Config @@ -38,7 +39,7 @@ export class Ollama { } if (!config?.proxy) { - this.config.host = utils.formatHost(config?.host ?? 'http://127.0.0.1:11434') + this.config.host = utils.formatHost(config?.host ?? defaultHost) } this.fetch = config?.fetch ?? fetch diff --git a/src/defaultHost.ts b/src/defaultHost.ts new file mode 100644 index 0000000..fc5a587 --- /dev/null +++ b/src/defaultHost.ts @@ -0,0 +1,2 @@ +export const defaulPort = '11434'; +export const defaultHost = `http://127.0.0.1:${defaulPort}`; \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 76976bf..ed21fbd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ import { version } from './version.js' import type { ErrorResponse, Fetch } from './interfaces.js' +import { defaulPort, defaultHost } from './defaultHost.js' /** * An error class for response errors. @@ -268,7 +269,7 @@ export const parseJSON = async function* ( */ export const formatHost = (host: string): string => { if (!host) { - return 'http://127.0.0.1:11434' + return defaultHost } let isExplicitProtocol = host.includes('://') @@ -288,7 +289,7 @@ export const formatHost = (host: string): string => { let port = url.port if (!port) { if (!isExplicitProtocol) { - port = '11434' + port = defaulPort } else { // Assign default ports based on the protocol port = url.protocol === 'https:' ? '443' : '80' diff --git a/test/index.test.ts b/test/index.test.ts index 8413dc0..6ea9e87 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1,9 +1,10 @@ import { describe, it, expect } from 'vitest' import { formatHost } from '../src/utils' +import { defaultHost } from '../src/defaultHost' describe('formatHost Function Tests', () => { it('should return default URL for empty string', () => { - expect(formatHost('')).toBe('http://127.0.0.1:11434') + expect(formatHost('')).toBe(defaultHost) }) it('should parse plain IP address', () => {