Переглянути джерело

Added optional headers to Ollama initialisation (#138)

Ronnel Davis 8 місяців тому
батько
коміт
3a9d651dca
3 змінених файлів з 7 додано та 2 видалено
  1. 4 1
      src/browser.ts
  2. 1 0
      src/interfaces.ts
  3. 2 1
      src/utils.ts

+ 4 - 1
src/browser.ts

@@ -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) {
@@ -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()
   }
 

+ 1 - 0
src/interfaces.ts

@@ -4,6 +4,7 @@ export interface Config {
   host: string
   fetch?: Fetch
   proxy?: boolean
+  headers?: Headers
 }
 
 // request types

+ 2 - 1
src/utils.ts

@@ -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)
@@ -181,6 +181,7 @@ export const post = async (
     method: 'POST',
     body: formattedData,
     signal: options?.signal,
+    headers: options?.headers
   })
 
   await checkOk(response)