Skip to content

Commit

Permalink
Added optional headers to Ollama initialisation (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronneldavis authored Sep 3, 2024
1 parent 218bede commit 3a9d651
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class Ollama {
const abortController = new AbortController()
const response = await post(this.fetch, host, request, {
signal: abortController.signal,
headers: this.config.headers
})

if (!response.body) {
Expand All @@ -94,7 +95,9 @@ export class Ollama {
this.ongoingStreamedRequests.push(abortableAsyncIterator)
return abortableAsyncIterator
}
const response = await utils.post(this.fetch, host, request)
const response = await utils.post(this.fetch, host, request, {
headers: this.config.headers
})
return await response.json()
}

Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Config {
host: string
fetch?: Fetch
proxy?: boolean
headers?: Headers
}

// request types
Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const post = async (
fetch: Fetch,
host: string,
data?: Record<string, unknown> | BodyInit,
options?: { signal: AbortSignal },
options?: { signal?: AbortSignal, headers?: Headers },
): Promise<Response> => {
const isRecord = (input: any): input is Record<string, unknown> => {
return input !== null && typeof input === 'object' && !Array.isArray(input)
Expand All @@ -181,6 +181,7 @@ export const post = async (
method: 'POST',
body: formattedData,
signal: options?.signal,
headers: options?.headers
})

await checkOk(response)
Expand Down

0 comments on commit 3a9d651

Please sign in to comment.