YanSte commited on
Commit
ef85051
·
1 Parent(s): 826eedf

removed never used method

Browse files
Files changed (2) hide show
  1. lightrag/llm/ollama.py +8 -10
  2. lightrag/utils.py +0 -36
lightrag/llm/ollama.py CHANGED
@@ -13,7 +13,9 @@ if not pm.is_installed("ollama"):
13
  if not pm.is_installed("tenacity"):
14
  pm.install("tenacity")
15
 
 
16
  import ollama
 
17
  from tenacity import (
18
  retry,
19
  stop_after_attempt,
@@ -26,7 +28,7 @@ from lightrag.exceptions import (
26
  APITimeoutError,
27
  )
28
  from lightrag.api import __api_version__
29
- from lightrag.utils import extract_reasoning
30
  import numpy as np
31
  from typing import Union
32
 
@@ -38,7 +40,7 @@ from typing import Union
38
  (RateLimitError, APIConnectionError, APITimeoutError)
39
  ),
40
  )
41
- async def ollama_model_if_cache(
42
  model,
43
  prompt,
44
  system_prompt=None,
@@ -46,7 +48,7 @@ async def ollama_model_if_cache(
46
  **kwargs,
47
  ) -> Union[str, AsyncIterator[str]]:
48
  stream = True if kwargs.get("stream") else False
49
- reasoning_tag = kwargs.pop("reasoning_tag", None)
50
  kwargs.pop("max_tokens", None)
51
  # kwargs.pop("response_format", None) # allow json
52
  host = kwargs.pop("host", None)
@@ -84,11 +86,7 @@ async def ollama_model_if_cache(
84
  response and can simply be trimmed.
85
  """
86
 
87
- return (
88
- model_response
89
- if reasoning_tag is None
90
- else extract_reasoning(model_response, reasoning_tag).response_content
91
- )
92
 
93
 
94
  async def ollama_model_complete(
@@ -98,7 +96,7 @@ async def ollama_model_complete(
98
  if keyword_extraction:
99
  kwargs["format"] = "json"
100
  model_name = kwargs["hashing_kv"].global_config["llm_model_name"]
101
- return await ollama_model_if_cache(
102
  model_name,
103
  prompt,
104
  system_prompt=system_prompt,
@@ -131,4 +129,4 @@ async def ollama_embed(texts: list[str], embed_model, **kwargs) -> np.ndarray:
131
  kwargs["headers"] = headers
132
  ollama_client = ollama.Client(**kwargs)
133
  data = ollama_client.embed(model=embed_model, input=texts)
134
- return data["embeddings"]
 
13
  if not pm.is_installed("tenacity"):
14
  pm.install("tenacity")
15
 
16
+
17
  import ollama
18
+
19
  from tenacity import (
20
  retry,
21
  stop_after_attempt,
 
28
  APITimeoutError,
29
  )
30
  from lightrag.api import __api_version__
31
+
32
  import numpy as np
33
  from typing import Union
34
 
 
40
  (RateLimitError, APIConnectionError, APITimeoutError)
41
  ),
42
  )
43
+ async def _ollama_model_if_cache(
44
  model,
45
  prompt,
46
  system_prompt=None,
 
48
  **kwargs,
49
  ) -> Union[str, AsyncIterator[str]]:
50
  stream = True if kwargs.get("stream") else False
51
+
52
  kwargs.pop("max_tokens", None)
53
  # kwargs.pop("response_format", None) # allow json
54
  host = kwargs.pop("host", None)
 
86
  response and can simply be trimmed.
87
  """
88
 
89
+ return model_response
 
 
 
 
90
 
91
 
92
  async def ollama_model_complete(
 
96
  if keyword_extraction:
97
  kwargs["format"] = "json"
98
  model_name = kwargs["hashing_kv"].global_config["llm_model_name"]
99
+ return await _ollama_model_if_cache(
100
  model_name,
101
  prompt,
102
  system_prompt=system_prompt,
 
129
  kwargs["headers"] = headers
130
  ollama_client = ollama.Client(**kwargs)
131
  data = ollama_client.embed(model=embed_model, input=texts)
132
+ return data["embeddings"]
lightrag/utils.py CHANGED
@@ -18,13 +18,7 @@ import tiktoken
18
 
19
  from lightrag.prompt import PROMPTS
20
 
21
- import pipmaster as pm # Pipmaster for dynamic library install
22
 
23
- # install specific modules
24
- if not pm.is_installed("bs4"):
25
- pm.install("bs4")
26
-
27
- import bs4
28
 
29
  VERBOSE_DEBUG = os.getenv("VERBOSE", "false").lower() == "true"
30
 
@@ -90,12 +84,6 @@ class EmbeddingFunc:
90
  return await self.func(*args, **kwargs)
91
 
92
 
93
- @dataclass
94
- class ReasoningResponse:
95
- reasoning_content: str | None
96
- response_content: str
97
- tag: str
98
-
99
 
100
  def locate_json_string_body_from_string(content: str) -> str | None:
101
  """Locate the JSON string body from a string"""
@@ -728,27 +716,3 @@ def get_conversation_turns(
728
 
729
  return "\n".join(formatted_turns)
730
 
731
-
732
- def extract_reasoning(response: str, tag: str) -> ReasoningResponse:
733
- """Extract the reasoning section and the following section from the LLM response.
734
-
735
- Args:
736
- response: LLM response
737
- tag: Tag to extract
738
- Returns:
739
- ReasoningResponse: Reasoning section and following section
740
-
741
- """
742
- soup = bs4.BeautifulSoup(response, "html.parser")
743
-
744
- reasoning_section = soup.find(tag)
745
- if reasoning_section is None:
746
- return ReasoningResponse(None, response, tag)
747
- reasoning_content = reasoning_section.get_text().strip()
748
-
749
- after_reasoning_section = reasoning_section.next_sibling
750
- if after_reasoning_section is None:
751
- return ReasoningResponse(reasoning_content, "", tag)
752
- after_reasoning_content = after_reasoning_section.get_text().strip()
753
-
754
- return ReasoningResponse(reasoning_content, after_reasoning_content, tag)
 
18
 
19
  from lightrag.prompt import PROMPTS
20
 
 
21
 
 
 
 
 
 
22
 
23
  VERBOSE_DEBUG = os.getenv("VERBOSE", "false").lower() == "true"
24
 
 
84
  return await self.func(*args, **kwargs)
85
 
86
 
 
 
 
 
 
 
87
 
88
  def locate_json_string_body_from_string(content: str) -> str | None:
89
  """Locate the JSON string body from a string"""
 
716
 
717
  return "\n".join(formatted_turns)
718