Skip to content

Commit

Permalink
Merge pull request #608 from ParisNeo/main
Browse files Browse the repository at this point in the history
Temporary fix to introduced problem in ollama and lollm
  • Loading branch information
LarFii authored Jan 20, 2025
2 parents a2993ae + 501610c commit d9a2285
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lightrag/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 None
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:
Expand Down Expand Up @@ -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 None
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
} if api_key else {"Content-Type": "application/json"}

# Extract lollms specific parameters
request_data = {
Expand Down Expand Up @@ -1154,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)
Expand All @@ -1181,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 = []
Expand Down

0 comments on commit d9a2285

Please sign in to comment.