diff --git a/lightrag/llm/ollama.py b/lightrag/llm/ollama.py index c65954f1..9e38917a 100644 --- a/lightrag/llm/ollama.py +++ b/lightrag/llm/ollama.py @@ -94,7 +94,7 @@ async def ollama_model_if_cache( api_key = kwargs.pop("api_key", None) headers = { "Content-Type": "application/json", - "User-Agent": f"LightRAG/{__api_version__}" + "User-Agent": f"LightRAG/{__api_version__}", } if api_key: headers["Authorization"] = f"Bearer {api_key}" @@ -151,7 +151,7 @@ async def ollama_embed(texts: list[str], embed_model, **kwargs) -> np.ndarray: api_key = kwargs.pop("api_key", None) headers = { "Content-Type": "application/json", - "User-Agent": f"LightRAG/{__api_version__}" + "User-Agent": f"LightRAG/{__api_version__}", } if api_key: headers["Authorization"] = api_key diff --git a/lightrag/llm/openai.py b/lightrag/llm/openai.py index ca451bcf..535d665c 100644 --- a/lightrag/llm/openai.py +++ b/lightrag/llm/openai.py @@ -78,10 +78,13 @@ from lightrag.api import __api_version__ import numpy as np from typing import Union + class InvalidResponseError(Exception): """Custom exception class for triggering retry mechanism""" + pass + @retry( stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10), @@ -105,10 +108,11 @@ async def openai_complete_if_cache( default_headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_8) LightRAG/{__api_version__}", - "Content-Type": "application/json" + "Content-Type": "application/json", } openai_async_client = ( - AsyncOpenAI(default_headers=default_headers) if base_url is None + AsyncOpenAI(default_headers=default_headers) + if base_url is None else AsyncOpenAI(base_url=base_url, default_headers=default_headers) ) kwargs.pop("hashing_kv", None) @@ -295,10 +299,11 @@ async def openai_embed( default_headers = { "User-Agent": f"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_8) LightRAG/{__api_version__}", - "Content-Type": "application/json" + "Content-Type": "application/json", } openai_async_client = ( - AsyncOpenAI(default_headers=default_headers) if base_url is None + AsyncOpenAI(default_headers=default_headers) + if base_url is None else AsyncOpenAI(base_url=base_url, default_headers=default_headers) ) response = await openai_async_client.embeddings.create(