ParisNeo commited on
Commit
1e89d2a
·
1 Parent(s): b3badb1

Fixed missing imports bug and fixed linting

Browse files
.gitignore CHANGED
@@ -23,4 +23,4 @@ examples/input/
23
  examples/output/
24
  .DS_Store
25
  #Remove config.ini from repo
26
- *.ini
 
23
  examples/output/
24
  .DS_Store
25
  #Remove config.ini from repo
26
+ *.ini
lightrag/api/lightrag_server.py CHANGED
@@ -684,7 +684,9 @@ def create_app(args):
684
  trace_exception(e)
685
  logging.error(f"Error indexing file {file_path}: {str(e)}")
686
 
687
- ASCIIColors.info(f"Indexed {len(new_files)} documents from {args.input_dir}")
 
 
688
  except Exception as e:
689
  logging.error(f"Error during startup indexing: {str(e)}")
690
  yield
@@ -917,7 +919,6 @@ def create_app(args):
917
  else:
918
  logging.warning(f"No content extracted from file: {file_path}")
919
 
920
-
921
  @app.post("/documents/scan", dependencies=[Depends(optional_api_key)])
922
  async def scan_for_new_documents():
923
  """
 
684
  trace_exception(e)
685
  logging.error(f"Error indexing file {file_path}: {str(e)}")
686
 
687
+ ASCIIColors.info(
688
+ f"Indexed {len(new_files)} documents from {args.input_dir}"
689
+ )
690
  except Exception as e:
691
  logging.error(f"Error during startup indexing: {str(e)}")
692
  yield
 
919
  else:
920
  logging.warning(f"No content extracted from file: {file_path}")
921
 
 
922
  @app.post("/documents/scan", dependencies=[Depends(optional_api_key)])
923
  async def scan_for_new_documents():
924
  """
lightrag/api/static/index.html CHANGED
@@ -622,7 +622,7 @@
622
  const data = await response.json();
623
  // Convert indexed_files to array if it's not already
624
  const files = Array.isArray(data.indexed_files) ? data.indexed_files : data.indexed_files.split(',');
625
-
626
  healthInfo.innerHTML = `
627
  <div class="space-y-4">
628
  <div class="flex items-center">
 
622
  const data = await response.json();
623
  // Convert indexed_files to array if it's not already
624
  const files = Array.isArray(data.indexed_files) ? data.indexed_files : data.indexed_files.split(',');
625
+
626
  healthInfo.innerHTML = `
627
  <div class="space-y-4">
628
  <div class="flex items-center">
lightrag/exceptions.py CHANGED
@@ -1,6 +1,7 @@
1
  import httpx
2
  from typing import Literal
3
 
 
4
  class APIStatusError(Exception):
5
  """Raised when an API response has a status code of 4xx or 5xx."""
6
 
@@ -8,14 +9,19 @@ class APIStatusError(Exception):
8
  status_code: int
9
  request_id: str | None
10
 
11
- def __init__(self, message: str, *, response: httpx.Response, body: object | None) -> None:
 
 
12
  super().__init__(message, response.request, body=body)
13
  self.response = response
14
  self.status_code = response.status_code
15
  self.request_id = response.headers.get("x-request-id")
16
 
 
17
  class APIConnectionError(Exception):
18
- def __init__(self, *, message: str = "Connection error.", request: httpx.Request) -> None:
 
 
19
  super().__init__(message, request, body=None)
20
 
21
 
@@ -46,10 +52,7 @@ class UnprocessableEntityError(APIStatusError):
46
  class RateLimitError(APIStatusError):
47
  status_code: Literal[429] = 429 # pyright: ignore[reportIncompatibleVariableOverride]
48
 
 
49
  class APITimeoutError(APIConnectionError):
50
  def __init__(self, request: httpx.Request) -> None:
51
  super().__init__(message="Request timed out.", request=request)
52
-
53
-
54
- class BadRequestError(APIStatusError):
55
- status_code: Literal[400] = 400 # pyright: ignore[reportIncompatibleVariableOverride]
 
1
  import httpx
2
  from typing import Literal
3
 
4
+
5
  class APIStatusError(Exception):
6
  """Raised when an API response has a status code of 4xx or 5xx."""
7
 
 
9
  status_code: int
10
  request_id: str | None
11
 
12
+ def __init__(
13
+ self, message: str, *, response: httpx.Response, body: object | None
14
+ ) -> None:
15
  super().__init__(message, response.request, body=body)
16
  self.response = response
17
  self.status_code = response.status_code
18
  self.request_id = response.headers.get("x-request-id")
19
 
20
+
21
  class APIConnectionError(Exception):
22
+ def __init__(
23
+ self, *, message: str = "Connection error.", request: httpx.Request
24
+ ) -> None:
25
  super().__init__(message, request, body=None)
26
 
27
 
 
52
  class RateLimitError(APIStatusError):
53
  status_code: Literal[429] = 429 # pyright: ignore[reportIncompatibleVariableOverride]
54
 
55
+
56
  class APITimeoutError(APIConnectionError):
57
  def __init__(self, request: httpx.Request) -> None:
58
  super().__init__(message="Request timed out.", request=request)
 
 
 
 
lightrag/kg/redis_impl.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  from tqdm.asyncio import tqdm as tqdm_async
3
  from dataclasses import dataclass
 
4
  # aioredis is a depricated library, replaced with redis
5
  from redis.asyncio import Redis
6
  from lightrag.utils import logger
 
1
  import os
2
  from tqdm.asyncio import tqdm as tqdm_async
3
  from dataclasses import dataclass
4
+
5
  # aioredis is a depricated library, replaced with redis
6
  from redis.asyncio import Redis
7
  from lightrag.utils import logger
lightrag/llm/azure_openai.py CHANGED
@@ -42,7 +42,7 @@ __status__ = "Production"
42
 
43
 
44
  import os
45
- import pipmaster as pm # Pipmaster for dynamic library install
46
 
47
  # install specific modules
48
  if not pm.is_installed("openai"):
@@ -71,6 +71,7 @@ from lightrag.utils import (
71
 
72
  import numpy as np
73
 
 
74
  @retry(
75
  stop=stop_after_attempt(3),
76
  wait=wait_exponential(multiplier=1, min=4, max=10),
@@ -153,6 +154,7 @@ async def azure_openai_complete(
153
  return locate_json_string_body_from_string(result)
154
  return result
155
 
 
156
  @wrap_embedding_func_with_attrs(embedding_dim=1536, max_token_size=8191)
157
  @retry(
158
  stop=stop_after_attempt(3),
@@ -185,4 +187,3 @@ async def azure_openai_embed(
185
  model=model, input=texts, encoding_format="float"
186
  )
187
  return np.array([dp.embedding for dp in response.data])
188
-
 
42
 
43
 
44
  import os
45
+ import pipmaster as pm # Pipmaster for dynamic library install
46
 
47
  # install specific modules
48
  if not pm.is_installed("openai"):
 
71
 
72
  import numpy as np
73
 
74
+
75
  @retry(
76
  stop=stop_after_attempt(3),
77
  wait=wait_exponential(multiplier=1, min=4, max=10),
 
154
  return locate_json_string_body_from_string(result)
155
  return result
156
 
157
+
158
  @wrap_embedding_func_with_attrs(embedding_dim=1536, max_token_size=8191)
159
  @retry(
160
  stop=stop_after_attempt(3),
 
187
  model=model, input=texts, encoding_format="float"
188
  )
189
  return np.array([dp.embedding for dp in response.data])
 
lightrag/llm/bedrock.py CHANGED
@@ -41,12 +41,12 @@ __author__ = "lightrag Team"
41
  __status__ = "Production"
42
 
43
 
44
- import sys
45
  import copy
46
  import os
47
  import json
48
 
49
- import pipmaster as pm # Pipmaster for dynamic library install
 
50
  if not pm.is_installed("aioboto3"):
51
  pm.install("aioboto3")
52
  if not pm.is_installed("tenacity"):
@@ -60,15 +60,11 @@ from tenacity import (
60
  retry_if_exception_type,
61
  )
62
 
63
- from lightrag.exceptions import (
64
- APIConnectionError,
65
- RateLimitError,
66
- APITimeoutError,
67
- )
68
  from lightrag.utils import (
69
  locate_json_string_body_from_string,
70
  )
71
 
 
72
  class BedrockError(Exception):
73
  """Generic error for issues related to Amazon Bedrock"""
74
 
 
41
  __status__ = "Production"
42
 
43
 
 
44
  import copy
45
  import os
46
  import json
47
 
48
+ import pipmaster as pm # Pipmaster for dynamic library install
49
+
50
  if not pm.is_installed("aioboto3"):
51
  pm.install("aioboto3")
52
  if not pm.is_installed("tenacity"):
 
60
  retry_if_exception_type,
61
  )
62
 
 
 
 
 
 
63
  from lightrag.utils import (
64
  locate_json_string_body_from_string,
65
  )
66
 
67
+
68
  class BedrockError(Exception):
69
  """Generic error for issues related to Amazon Bedrock"""
70
 
lightrag/llm/hf.py CHANGED
@@ -42,7 +42,7 @@ __status__ = "Production"
42
 
43
  import copy
44
  import os
45
- import pipmaster as pm # Pipmaster for dynamic library install
46
 
47
  # install specific modules
48
  if not pm.is_installed("transformers"):
@@ -69,9 +69,11 @@ from lightrag.utils import (
69
  locate_json_string_body_from_string,
70
  )
71
  import torch
 
72
 
73
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
74
 
 
75
  @lru_cache(maxsize=1)
76
  def initialize_hf_model(model_name):
77
  hf_tokenizer = AutoTokenizer.from_pretrained(
@@ -155,7 +157,6 @@ async def hf_model_if_cache(
155
  return response_text
156
 
157
 
158
-
159
  async def hf_model_complete(
160
  prompt, system_prompt=None, history_messages=[], keyword_extraction=False, **kwargs
161
  ) -> str:
 
42
 
43
  import copy
44
  import os
45
+ import pipmaster as pm # Pipmaster for dynamic library install
46
 
47
  # install specific modules
48
  if not pm.is_installed("transformers"):
 
69
  locate_json_string_body_from_string,
70
  )
71
  import torch
72
+ import numpy as np
73
 
74
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
75
 
76
+
77
  @lru_cache(maxsize=1)
78
  def initialize_hf_model(model_name):
79
  hf_tokenizer = AutoTokenizer.from_pretrained(
 
157
  return response_text
158
 
159
 
 
160
  async def hf_model_complete(
161
  prompt, system_prompt=None, history_messages=[], keyword_extraction=False, **kwargs
162
  ) -> str:
lightrag/llm/jina.py CHANGED
@@ -39,7 +39,7 @@ __author__ = "lightrag Team"
39
  __status__ = "Production"
40
 
41
  import os
42
- import pipmaster as pm # Pipmaster for dynamic library install
43
 
44
  # install specific modules
45
  if not pm.is_installed("lmdeploy"):
@@ -47,25 +47,8 @@ if not pm.is_installed("lmdeploy"):
47
  if not pm.is_installed("tenacity"):
48
  pm.install("tenacity")
49
 
50
- from tenacity import (
51
- retry,
52
- stop_after_attempt,
53
- wait_exponential,
54
- retry_if_exception_type,
55
- )
56
-
57
- from lightrag.utils import (
58
- wrap_embedding_func_with_attrs,
59
- locate_json_string_body_from_string,
60
- safe_unicode_decode,
61
- logger,
62
- )
63
-
64
- from lightrag.types import GPTKeywordExtractionFormat
65
- from functools import lru_cache
66
 
67
  import numpy as np
68
- from typing import Union
69
  import aiohttp
70
 
71
 
@@ -101,4 +84,3 @@ async def jina_embed(
101
  }
102
  data_list = await fetch_data(url, headers, data)
103
  return np.array([dp["embedding"] for dp in data_list])
104
-
 
39
  __status__ = "Production"
40
 
41
  import os
42
+ import pipmaster as pm # Pipmaster for dynamic library install
43
 
44
  # install specific modules
45
  if not pm.is_installed("lmdeploy"):
 
47
  if not pm.is_installed("tenacity"):
48
  pm.install("tenacity")
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  import numpy as np
 
52
  import aiohttp
53
 
54
 
 
84
  }
85
  data_list = await fetch_data(url, headers, data)
86
  return np.array([dp["embedding"] for dp in data_list])
 
lightrag/llm/lmdeploy.py CHANGED
@@ -40,7 +40,7 @@ __version__ = "1.0.0"
40
  __author__ = "lightrag Team"
41
  __status__ = "Production"
42
 
43
- import pipmaster as pm # Pipmaster for dynamic library install
44
 
45
  # install specific modules
46
  if not pm.is_installed("lmdeploy"):
@@ -63,6 +63,7 @@ from tenacity import (
63
 
64
  from functools import lru_cache
65
 
 
66
  @lru_cache(maxsize=1)
67
  def initialize_lmdeploy_pipeline(
68
  model,
@@ -187,4 +188,4 @@ async def lmdeploy_model_if_cache(
187
  session_id=1,
188
  ):
189
  response += res.response
190
- return response
 
40
  __author__ = "lightrag Team"
41
  __status__ = "Production"
42
 
43
+ import pipmaster as pm # Pipmaster for dynamic library install
44
 
45
  # install specific modules
46
  if not pm.is_installed("lmdeploy"):
 
63
 
64
  from functools import lru_cache
65
 
66
+
67
  @lru_cache(maxsize=1)
68
  def initialize_lmdeploy_pipeline(
69
  model,
 
188
  session_id=1,
189
  ):
190
  response += res.response
191
+ return response
lightrag/llm/lollms.py CHANGED
@@ -62,11 +62,13 @@ __status__ = "Production"
62
  __project_url__ = "https://github.com/ParisNeo/lollms"
63
  __doc_url__ = "https://github.com/ParisNeo/lollms/docs"
64
  import sys
 
65
  if sys.version_info < (3, 9):
66
  from typing import AsyncIterator
67
  else:
68
  from collections.abc import AsyncIterator
69
- import pipmaster as pm # Pipmaster for dynamic library install
 
70
  if not pm.is_installed("aiohttp"):
71
  pm.install("aiohttp")
72
  if not pm.is_installed("tenacity"):
@@ -89,6 +91,7 @@ from lightrag.exceptions import (
89
  from typing import Union, List
90
  import numpy as np
91
 
 
92
  @retry(
93
  stop=stop_after_attempt(3),
94
  wait=wait_exponential(multiplier=1, min=4, max=10),
@@ -185,7 +188,6 @@ async def lollms_model_complete(
185
  )
186
 
187
 
188
-
189
  async def lollms_embed(
190
  texts: List[str], embed_model=None, base_url="http://localhost:9600", **kwargs
191
  ) -> np.ndarray:
@@ -219,4 +221,4 @@ async def lollms_embed(
219
  result = await response.json()
220
  embeddings.append(result["vector"])
221
 
222
- return np.array(embeddings)
 
62
  __project_url__ = "https://github.com/ParisNeo/lollms"
63
  __doc_url__ = "https://github.com/ParisNeo/lollms/docs"
64
  import sys
65
+
66
  if sys.version_info < (3, 9):
67
  from typing import AsyncIterator
68
  else:
69
  from collections.abc import AsyncIterator
70
+ import pipmaster as pm # Pipmaster for dynamic library install
71
+
72
  if not pm.is_installed("aiohttp"):
73
  pm.install("aiohttp")
74
  if not pm.is_installed("tenacity"):
 
91
  from typing import Union, List
92
  import numpy as np
93
 
94
+
95
  @retry(
96
  stop=stop_after_attempt(3),
97
  wait=wait_exponential(multiplier=1, min=4, max=10),
 
188
  )
189
 
190
 
 
191
  async def lollms_embed(
192
  texts: List[str], embed_model=None, base_url="http://localhost:9600", **kwargs
193
  ) -> np.ndarray:
 
221
  result = await response.json()
222
  embeddings.append(result["vector"])
223
 
224
+ return np.array(embeddings)
lightrag/llm/nvidia_openai.py CHANGED
@@ -41,15 +41,14 @@ __author__ = "lightrag Team"
41
  __status__ = "Production"
42
 
43
 
44
-
45
  import sys
46
  import os
47
 
48
  if sys.version_info < (3, 9):
49
- from typing import AsyncIterator
50
  else:
51
- from collections.abc import AsyncIterator
52
- import pipmaster as pm # Pipmaster for dynamic library install
53
 
54
  # install specific modules
55
  if not pm.is_installed("openai"):
@@ -70,15 +69,12 @@ from tenacity import (
70
 
71
  from lightrag.utils import (
72
  wrap_embedding_func_with_attrs,
73
- locate_json_string_body_from_string,
74
- safe_unicode_decode,
75
- logger,
76
  )
77
 
78
- from lightrag.types import GPTKeywordExtractionFormat
79
 
80
  import numpy as np
81
 
 
82
  @wrap_embedding_func_with_attrs(embedding_dim=2048, max_token_size=512)
83
  @retry(
84
  stop=stop_after_attempt(3),
 
41
  __status__ = "Production"
42
 
43
 
 
44
  import sys
45
  import os
46
 
47
  if sys.version_info < (3, 9):
48
+ pass
49
  else:
50
+ pass
51
+ import pipmaster as pm # Pipmaster for dynamic library install
52
 
53
  # install specific modules
54
  if not pm.is_installed("openai"):
 
69
 
70
  from lightrag.utils import (
71
  wrap_embedding_func_with_attrs,
 
 
 
72
  )
73
 
 
74
 
75
  import numpy as np
76
 
77
+
78
  @wrap_embedding_func_with_attrs(embedding_dim=2048, max_token_size=512)
79
  @retry(
80
  stop=stop_after_attempt(3),
lightrag/llm/ollama.py CHANGED
@@ -41,11 +41,12 @@ __author__ = "lightrag Team"
41
  __status__ = "Production"
42
 
43
  import sys
 
44
  if sys.version_info < (3, 9):
45
  from typing import AsyncIterator
46
  else:
47
  from collections.abc import AsyncIterator
48
- import pipmaster as pm # Pipmaster for dynamic library install
49
 
50
  # install specific modules
51
  if not pm.is_installed("ollama"):
@@ -114,6 +115,7 @@ async def ollama_model_if_cache(
114
  else:
115
  return response["message"]["content"]
116
 
 
117
  async def ollama_model_complete(
118
  prompt, system_prompt=None, history_messages=[], keyword_extraction=False, **kwargs
119
  ) -> Union[str, AsyncIterator[str]]:
@@ -129,6 +131,7 @@ async def ollama_model_complete(
129
  **kwargs,
130
  )
131
 
 
132
  async def ollama_embedding(texts: list[str], embed_model, **kwargs) -> np.ndarray:
133
  """
134
  Deprecated in favor of `embed`.
@@ -152,4 +155,4 @@ async def ollama_embed(texts: list[str], embed_model, **kwargs) -> np.ndarray:
152
  kwargs["headers"] = headers
153
  ollama_client = ollama.Client(**kwargs)
154
  data = ollama_client.embed(model=embed_model, input=texts)
155
- return data["embeddings"]
 
41
  __status__ = "Production"
42
 
43
  import sys
44
+
45
  if sys.version_info < (3, 9):
46
  from typing import AsyncIterator
47
  else:
48
  from collections.abc import AsyncIterator
49
+ import pipmaster as pm # Pipmaster for dynamic library install
50
 
51
  # install specific modules
52
  if not pm.is_installed("ollama"):
 
115
  else:
116
  return response["message"]["content"]
117
 
118
+
119
  async def ollama_model_complete(
120
  prompt, system_prompt=None, history_messages=[], keyword_extraction=False, **kwargs
121
  ) -> Union[str, AsyncIterator[str]]:
 
131
  **kwargs,
132
  )
133
 
134
+
135
  async def ollama_embedding(texts: list[str], embed_model, **kwargs) -> np.ndarray:
136
  """
137
  Deprecated in favor of `embed`.
 
155
  kwargs["headers"] = headers
156
  ollama_client = ollama.Client(**kwargs)
157
  data = ollama_client.embed(model=embed_model, input=texts)
158
+ return data["embeddings"]
lightrag/llm/openai.py CHANGED
@@ -41,7 +41,6 @@ __author__ = "lightrag Team"
41
  __status__ = "Production"
42
 
43
 
44
-
45
  import sys
46
  import os
47
 
@@ -49,7 +48,7 @@ if sys.version_info < (3, 9):
49
  from typing import AsyncIterator
50
  else:
51
  from collections.abc import AsyncIterator
52
- import pipmaster as pm # Pipmaster for dynamic library install
53
 
54
  # install specific modules
55
  if not pm.is_installed("openai"):
@@ -78,6 +77,7 @@ from lightrag.types import GPTKeywordExtractionFormat
78
  import numpy as np
79
  from typing import Union
80
 
 
81
  @retry(
82
  stop=stop_after_attempt(3),
83
  wait=wait_exponential(multiplier=1, min=4, max=10),
@@ -141,7 +141,6 @@ async def openai_complete_if_cache(
141
  return content
142
 
143
 
144
-
145
  async def openai_complete(
146
  prompt, system_prompt=None, history_messages=[], keyword_extraction=False, **kwargs
147
  ) -> Union[str, AsyncIterator[str]]:
@@ -205,7 +204,6 @@ async def nvidia_openai_complete(
205
  return result
206
 
207
 
208
-
209
  @wrap_embedding_func_with_attrs(embedding_dim=1536, max_token_size=8192)
210
  @retry(
211
  stop=stop_after_attempt(3),
 
41
  __status__ = "Production"
42
 
43
 
 
44
  import sys
45
  import os
46
 
 
48
  from typing import AsyncIterator
49
  else:
50
  from collections.abc import AsyncIterator
51
+ import pipmaster as pm # Pipmaster for dynamic library install
52
 
53
  # install specific modules
54
  if not pm.is_installed("openai"):
 
77
  import numpy as np
78
  from typing import Union
79
 
80
+
81
  @retry(
82
  stop=stop_after_attempt(3),
83
  wait=wait_exponential(multiplier=1, min=4, max=10),
 
141
  return content
142
 
143
 
 
144
  async def openai_complete(
145
  prompt, system_prompt=None, history_messages=[], keyword_extraction=False, **kwargs
146
  ) -> Union[str, AsyncIterator[str]]:
 
204
  return result
205
 
206
 
 
207
  @wrap_embedding_func_with_attrs(embedding_dim=1536, max_token_size=8192)
208
  @retry(
209
  stop=stop_after_attempt(3),
lightrag/llm/siliconcloud.py CHANGED
@@ -39,23 +39,18 @@ __author__ = "lightrag Team"
39
  __status__ = "Production"
40
 
41
  import sys
42
- import copy
43
- import os
44
- import json
45
 
46
  if sys.version_info < (3, 9):
47
- from typing import AsyncIterator
48
  else:
49
- from collections.abc import AsyncIterator
50
- import pipmaster as pm # Pipmaster for dynamic library install
51
 
52
  # install specific modules
53
  if not pm.is_installed("lmdeploy"):
54
  pm.install("lmdeploy")
55
 
56
  from openai import (
57
- AsyncOpenAI,
58
- AsyncAzureOpenAI,
59
  APIConnectionError,
60
  RateLimitError,
61
  APITimeoutError,
@@ -67,19 +62,12 @@ from tenacity import (
67
  retry_if_exception_type,
68
  )
69
 
70
- from lightrag.utils import (
71
- wrap_embedding_func_with_attrs,
72
- locate_json_string_body_from_string,
73
- safe_unicode_decode,
74
- logger,
75
- )
76
-
77
- from lightrag.types import GPTKeywordExtractionFormat
78
- from functools import lru_cache
79
 
80
  import numpy as np
81
- from typing import Union
82
  import aiohttp
 
 
 
83
 
84
  @retry(
85
  stop=stop_after_attempt(3),
 
39
  __status__ = "Production"
40
 
41
  import sys
 
 
 
42
 
43
  if sys.version_info < (3, 9):
44
+ pass
45
  else:
46
+ pass
47
+ import pipmaster as pm # Pipmaster for dynamic library install
48
 
49
  # install specific modules
50
  if not pm.is_installed("lmdeploy"):
51
  pm.install("lmdeploy")
52
 
53
  from openai import (
 
 
54
  APIConnectionError,
55
  RateLimitError,
56
  APITimeoutError,
 
62
  retry_if_exception_type,
63
  )
64
 
 
 
 
 
 
 
 
 
 
65
 
66
  import numpy as np
 
67
  import aiohttp
68
+ import base64
69
+ import struct
70
+
71
 
72
  @retry(
73
  stop=stop_after_attempt(3),
lightrag/llm/zhipu.py CHANGED
@@ -45,18 +45,16 @@ import re
45
  import json
46
 
47
  if sys.version_info < (3, 9):
48
- from typing import AsyncIterator
49
  else:
50
- from collections.abc import AsyncIterator
51
- import pipmaster as pm # Pipmaster for dynamic library install
52
 
53
  # install specific modules
54
  if not pm.is_installed("zhipuai"):
55
  pm.install("zhipuai")
56
 
57
  from openai import (
58
- AsyncOpenAI,
59
- AsyncAzureOpenAI,
60
  APIConnectionError,
61
  RateLimitError,
62
  APITimeoutError,
@@ -70,17 +68,15 @@ from tenacity import (
70
 
71
  from lightrag.utils import (
72
  wrap_embedding_func_with_attrs,
73
- locate_json_string_body_from_string,
74
- safe_unicode_decode,
75
  logger,
76
  )
77
 
78
  from lightrag.types import GPTKeywordExtractionFormat
79
- from functools import lru_cache
80
 
81
  import numpy as np
82
  from typing import Union, List, Optional, Dict
83
 
 
84
  @retry(
85
  stop=stop_after_attempt(3),
86
  wait=wait_exponential(multiplier=1, min=4, max=10),
@@ -247,4 +243,4 @@ async def zhipu_embedding(
247
  except Exception as e:
248
  raise Exception(f"Error calling ChatGLM Embedding API: {str(e)}")
249
 
250
- return np.array(embeddings)
 
45
  import json
46
 
47
  if sys.version_info < (3, 9):
48
+ pass
49
  else:
50
+ pass
51
+ import pipmaster as pm # Pipmaster for dynamic library install
52
 
53
  # install specific modules
54
  if not pm.is_installed("zhipuai"):
55
  pm.install("zhipuai")
56
 
57
  from openai import (
 
 
58
  APIConnectionError,
59
  RateLimitError,
60
  APITimeoutError,
 
68
 
69
  from lightrag.utils import (
70
  wrap_embedding_func_with_attrs,
 
 
71
  logger,
72
  )
73
 
74
  from lightrag.types import GPTKeywordExtractionFormat
 
75
 
76
  import numpy as np
77
  from typing import Union, List, Optional, Dict
78
 
79
+
80
  @retry(
81
  stop=stop_after_attempt(3),
82
  wait=wait_exponential(multiplier=1, min=4, max=10),
 
243
  except Exception as e:
244
  raise Exception(f"Error calling ChatGLM Embedding API: {str(e)}")
245
 
246
+ return np.array(embeddings)
lightrag/storage.py CHANGED
@@ -6,7 +6,6 @@ from dataclasses import dataclass
6
  from typing import Any, Union, cast, Dict
7
  import networkx as nx
8
  import numpy as np
9
- import pipmaster as pm
10
 
11
  from nano_vectordb import NanoVectorDB
12
  import time
 
6
  from typing import Any, Union, cast, Dict
7
  import networkx as nx
8
  import numpy as np
 
9
 
10
  from nano_vectordb import NanoVectorDB
11
  import time
lightrag/types.py CHANGED
@@ -1,6 +1,7 @@
1
  from pydantic import BaseModel
2
  from typing import List
3
 
 
4
  class GPTKeywordExtractionFormat(BaseModel):
5
  high_level_keywords: List[str]
6
  low_level_keywords: List[str]
 
1
  from pydantic import BaseModel
2
  from typing import List
3
 
4
+
5
  class GPTKeywordExtractionFormat(BaseModel):
6
  high_level_keywords: List[str]
7
  low_level_keywords: List[str]
lightrag/utils.py CHANGED
@@ -535,7 +535,8 @@ class CacheData:
535
  min_val: Optional[float] = None
536
  max_val: Optional[float] = None
537
  mode: str = "default"
538
- cache_type: str ="query"
 
539
 
540
  async def save_to_cache(hashing_kv, cache_data: CacheData):
541
  if hashing_kv is None or hasattr(cache_data.content, "__aiter__"):
 
535
  min_val: Optional[float] = None
536
  max_val: Optional[float] = None
537
  mode: str = "default"
538
+ cache_type: str = "query"
539
+
540
 
541
  async def save_to_cache(hashing_kv, cache_data: CacheData):
542
  if hashing_kv is None or hasattr(cache_data.content, "__aiter__"):
requirements.txt CHANGED
@@ -1,7 +1,6 @@
1
  accelerate
2
  aiofiles
3
  aiohttp
4
- redis
5
  asyncpg
6
  configparser
7
 
@@ -30,6 +29,7 @@ python-docx
30
  python-dotenv
31
  python-pptx
32
  pyvis
 
33
  setuptools
34
  sqlalchemy
35
  tenacity
@@ -39,4 +39,3 @@ tenacity
39
  tiktoken
40
  tqdm
41
  xxhash
42
-
 
1
  accelerate
2
  aiofiles
3
  aiohttp
 
4
  asyncpg
5
  configparser
6
 
 
29
  python-dotenv
30
  python-pptx
31
  pyvis
32
+ redis
33
  setuptools
34
  sqlalchemy
35
  tenacity
 
39
  tiktoken
40
  tqdm
41
  xxhash