From f18f484a87b5360b076756b5015f57b0c230a321 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 20 Jan 2025 08:54:18 +0100 Subject: [PATCH 1/4] Update llm.py --- lightrag/llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lightrag/llm.py b/lightrag/llm.py index b6d7a2a8..daba06dd 100644 --- a/lightrag/llm.py +++ b/lightrag/llm.py @@ -350,7 +350,7 @@ async def ollama_model_if_cache( timeout = kwargs.pop("timeout", None) kwargs.pop("hashing_kv", None) api_key = kwargs.pop("api_key", None) - headers = {"Authorization": f"Bearer {api_key}"} if api_key else None + headers = {"Authorization": f"Bearer {api_key}"} if api_key else {} ollama_client = ollama.AsyncClient(host=host, timeout=timeout, headers=headers) messages = [] if system_prompt: @@ -383,7 +383,7 @@ async def lollms_model_if_cache( stream = True if kwargs.get("stream") else False api_key = kwargs.pop("api_key", None) - headers = {"Authorization": f"Bearer {api_key}"} if api_key else None + headers = {"Authorization": f"Bearer {api_key}"} if api_key else {} # Extract lollms specific parameters request_data = { From e4945c9653fff1b3b40ab20aeb17f6372157b517 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 20 Jan 2025 08:58:08 +0100 Subject: [PATCH 2/4] Update llm.py --- lightrag/llm.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lightrag/llm.py b/lightrag/llm.py index daba06dd..682c42f9 100644 --- a/lightrag/llm.py +++ b/lightrag/llm.py @@ -350,7 +350,10 @@ async def ollama_model_if_cache( timeout = kwargs.pop("timeout", None) kwargs.pop("hashing_kv", None) api_key = kwargs.pop("api_key", None) - headers = {"Authorization": f"Bearer {api_key}"} if api_key else {} + headers = { + "Content-Type": "application/json", + "Authorization": f"Bearer {api_key}" + } if api_key else {"Content-Type": "application/json"} ollama_client = ollama.AsyncClient(host=host, timeout=timeout, headers=headers) messages = [] if system_prompt: @@ -383,7 +386,10 @@ async def lollms_model_if_cache( stream = True if kwargs.get("stream") else False api_key = kwargs.pop("api_key", None) - headers = {"Authorization": f"Bearer {api_key}"} if api_key else {} + headers = { + "Content-Type": "application/json", + "Authorization": f"Bearer {api_key}" + } if api_key else {"Content-Type": "application/json"} # Extract lollms specific parameters request_data = { From a557878e4e1c505ec7cc638705f6083e0624f910 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 20 Jan 2025 09:04:32 +0100 Subject: [PATCH 3/4] Update llm.py --- lightrag/llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lightrag/llm.py b/lightrag/llm.py index 682c42f9..7682e12a 100644 --- a/lightrag/llm.py +++ b/lightrag/llm.py @@ -354,7 +354,7 @@ async def ollama_model_if_cache( "Content-Type": "application/json", "Authorization": f"Bearer {api_key}" } if api_key else {"Content-Type": "application/json"} - ollama_client = ollama.AsyncClient(host=host, timeout=timeout, headers=headers) + ollama_client = ollama.AsyncClient(host=host, timeout=timeout)# temporary fix: (TODO: rewrite this with better compatibility), headers=headers) messages = [] if system_prompt: messages.append({"role": "system", "content": system_prompt}) @@ -418,7 +418,7 @@ async def lollms_model_if_cache( request_data["prompt"] = full_prompt timeout = aiohttp.ClientTimeout(total=kwargs.get("timeout", None)) - async with aiohttp.ClientSession(timeout=timeout, headers=headers) as session: + async with aiohttp.ClientSession(timeout=timeout) as session:# temporary fix: (TODO: rewrite this with better compatibility), headers=headers) as session: if stream: async def inner(): From 501610c603262c82023973da1c0995cc0d327ca2 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 20 Jan 2025 10:04:17 +0100 Subject: [PATCH 4/4] Update llm.py --- lightrag/llm.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lightrag/llm.py b/lightrag/llm.py index 7682e12a..5ba2cfd4 100644 --- a/lightrag/llm.py +++ b/lightrag/llm.py @@ -354,7 +354,7 @@ async def ollama_model_if_cache( "Content-Type": "application/json", "Authorization": f"Bearer {api_key}" } if api_key else {"Content-Type": "application/json"} - ollama_client = ollama.AsyncClient(host=host, timeout=timeout)# temporary fix: (TODO: rewrite this with better compatibility), headers=headers) + ollama_client = ollama.AsyncClient(host=host, timeout=timeout, headers=headers) messages = [] if system_prompt: messages.append({"role": "system", "content": system_prompt}) @@ -418,7 +418,7 @@ async def lollms_model_if_cache( request_data["prompt"] = full_prompt timeout = aiohttp.ClientTimeout(total=kwargs.get("timeout", None)) - async with aiohttp.ClientSession(timeout=timeout) as session:# temporary fix: (TODO: rewrite this with better compatibility), headers=headers) as session: + async with aiohttp.ClientSession(timeout=timeout, headers=headers) as session: if stream: async def inner(): @@ -1160,9 +1160,9 @@ async def ollama_embedding(texts: list[str], embed_model, **kwargs) -> np.ndarra async def ollama_embed(texts: list[str], embed_model, **kwargs) -> np.ndarray: api_key = kwargs.pop("api_key", None) headers = ( - {"Authorization": api_key, "Content-Type": "application/json"} + {"Content-Type": "application/json", "Authorization": api_key} if api_key - else None + else {"Content-Type": "application/json"} ) kwargs["headers"] = headers ollama_client = ollama.Client(**kwargs) @@ -1187,9 +1187,9 @@ async def lollms_embed( """ api_key = kwargs.pop("api_key", None) headers = ( - {"Authorization": api_key, "Content-Type": "application/json"} + {"Content-Type": "application/json", "Authorization": api_key} if api_key - else None + else {"Content-Type": "application/json"} ) async with aiohttp.ClientSession(headers=headers) as session: embeddings = []