From 24ae083284d5979f71942a7c363555e5a18abb97 Mon Sep 17 00:00:00 2001 From: Yannick Stephan Date: Tue, 18 Feb 2025 19:38:04 +0100 Subject: [PATCH] removed never used method --- lightrag/llm/ollama.py | 18 ++++++++---------- lightrag/utils.py | 36 ------------------------------------ 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/lightrag/llm/ollama.py b/lightrag/llm/ollama.py index f62386e4..0e663201 100644 --- a/lightrag/llm/ollama.py +++ b/lightrag/llm/ollama.py @@ -13,7 +13,9 @@ if not pm.is_installed("ollama"): if not pm.is_installed("tenacity"): pm.install("tenacity") + import ollama + from tenacity import ( retry, stop_after_attempt, @@ -26,7 +28,7 @@ from lightrag.exceptions import ( APITimeoutError, ) from lightrag.api import __api_version__ -from lightrag.utils import extract_reasoning + import numpy as np from typing import Union @@ -38,7 +40,7 @@ from typing import Union (RateLimitError, APIConnectionError, APITimeoutError) ), ) -async def ollama_model_if_cache( +async def _ollama_model_if_cache( model, prompt, system_prompt=None, @@ -46,7 +48,7 @@ async def ollama_model_if_cache( **kwargs, ) -> Union[str, AsyncIterator[str]]: stream = True if kwargs.get("stream") else False - reasoning_tag = kwargs.pop("reasoning_tag", None) + kwargs.pop("max_tokens", None) # kwargs.pop("response_format", None) # allow json host = kwargs.pop("host", None) @@ -84,11 +86,7 @@ async def ollama_model_if_cache( response and can simply be trimmed. """ - return ( - model_response - if reasoning_tag is None - else extract_reasoning(model_response, reasoning_tag).response_content - ) + return model_response async def ollama_model_complete( @@ -98,7 +96,7 @@ async def ollama_model_complete( if keyword_extraction: kwargs["format"] = "json" model_name = kwargs["hashing_kv"].global_config["llm_model_name"] - return await ollama_model_if_cache( + return await _ollama_model_if_cache( model_name, prompt, system_prompt=system_prompt, @@ -131,4 +129,4 @@ async def ollama_embed(texts: list[str], embed_model, **kwargs) -> np.ndarray: kwargs["headers"] = headers ollama_client = ollama.Client(**kwargs) data = ollama_client.embed(model=embed_model, input=texts) - return data["embeddings"] + return data["embeddings"] \ No newline at end of file diff --git a/lightrag/utils.py b/lightrag/utils.py index 680adf7a..3ca93f85 100644 --- a/lightrag/utils.py +++ b/lightrag/utils.py @@ -18,13 +18,7 @@ import tiktoken from lightrag.prompt import PROMPTS -import pipmaster as pm # Pipmaster for dynamic library install -# install specific modules -if not pm.is_installed("bs4"): - pm.install("bs4") - -import bs4 VERBOSE_DEBUG = os.getenv("VERBOSE", "false").lower() == "true" @@ -90,12 +84,6 @@ class EmbeddingFunc: return await self.func(*args, **kwargs) -@dataclass -class ReasoningResponse: - reasoning_content: str | None - response_content: str - tag: str - def locate_json_string_body_from_string(content: str) -> str | None: """Locate the JSON string body from a string""" @@ -728,27 +716,3 @@ def get_conversation_turns( return "\n".join(formatted_turns) - -def extract_reasoning(response: str, tag: str) -> ReasoningResponse: - """Extract the reasoning section and the following section from the LLM response. - - Args: - response: LLM response - tag: Tag to extract - Returns: - ReasoningResponse: Reasoning section and following section - - """ - soup = bs4.BeautifulSoup(response, "html.parser") - - reasoning_section = soup.find(tag) - if reasoning_section is None: - return ReasoningResponse(None, response, tag) - reasoning_content = reasoning_section.get_text().strip() - - after_reasoning_section = reasoning_section.next_sibling - if after_reasoning_section is None: - return ReasoningResponse(reasoning_content, "", tag) - after_reasoning_content = after_reasoning_section.get_text().strip() - - return ReasoningResponse(reasoning_content, after_reasoning_content, tag)