Skip to content

Commit

Permalink
Remove duplicate logger from PaiPDFReader (#263)
Browse files Browse the repository at this point in the history
* Remove duplicate logger from PaiPDFReader

* Add ModelScopeDownloader

* Use logger from loguru not logging

* Remove ak sk info
  • Loading branch information
wwxxzz authored Nov 6, 2024
1 parent a449340 commit 7170851
Show file tree
Hide file tree
Showing 80 changed files with 202 additions and 368 deletions.
4 changes: 1 addition & 3 deletions docs/agentic_rag.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ Python代码工具分为两个部分:代码和函数定义。
```python
import requests
import os
import logging

logger = logging.getLogger(__name__)
from loguru import logger


def get_place_weather(city: str) -> str:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import requests
import os
import logging

logger = logging.getLogger(__name__)
from loguru import logger


def get_place_weather(city: str) -> str:
Expand Down
3 changes: 0 additions & 3 deletions src/pai_rag/app/api/agent_demo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from datetime import datetime
from fastapi import APIRouter
import logging

from pydantic import BaseModel

logger = logging.getLogger(__name__)

demo_router = APIRouter()


Expand Down
4 changes: 1 addition & 3 deletions src/pai_rag/app/api/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from starlette.middleware.base import BaseHTTPMiddleware
from asgi_correlation_id import CorrelationIdMiddleware
import time
import logging

logger = logging.getLogger(__name__)
from loguru import logger


class CustomMiddleWare(BaseHTTPMiddleware):
Expand Down
4 changes: 1 addition & 3 deletions src/pai_rag/app/api/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
RetrievalQuery,
)
from fastapi.responses import StreamingResponse
import logging
from loguru import logger

from pai_rag.integrations.nodeparsers.pai.pai_node_parser import (
COMMON_FILE_PATH_FODER_NAME,
)

logger = logging.getLogger(__name__)

router = APIRouter()


Expand Down
5 changes: 3 additions & 2 deletions src/pai_rag/app/web/event_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
HuggingFaceEmbeddingConfig,
)
from pai_rag.integrations.index.pai.vector_store_config import FaissVectorStoreConfig
from loguru import logger


def add_index(*components):
component_args = dict(zip(index_related_component_keys, components))
index_entry = components_to_index(**component_args)
rag_client.add_index(index_entry)
index_map = get_index_map()
print(f"Add index {index_entry.index_name} successfully")
logger.info(f"Add index {index_entry.index_name} successfully")
return [
gr.update(
choices=list(index_map.indexes.keys()) + ["NEW"],
Expand All @@ -44,7 +45,7 @@ def update_index(*components):
index_entry = components_to_index(**component_args)
rag_client.update_index(index_entry)
index_map = get_index_map()
print(f"Update index {index_entry.index_name} successfully")
logger.info(f"Update index {index_entry.index_name} successfully")
return [
gr.update(
choices=list(index_map.indexes.keys()) + ["NEW"],
Expand Down
1 change: 0 additions & 1 deletion src/pai_rag/app/web/index_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ def index_to_components(
component_settings = index_to_components_settings(
index_entry, index_list, is_new_index
)
print("+++", index_entry.index_name)
return [gr.update(**setting) for setting in component_settings.values()] + [
gr.update(choices=index_list, value=index_entry.index_name),
gr.update(choices=index_list, value=index_entry.index_name),
Expand Down
3 changes: 2 additions & 1 deletion src/pai_rag/app/web/rag_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import html
import mimetypes
from http import HTTPStatus
from loguru import logger
from pai_rag.app.web.view_model import ViewModel
from pai_rag.app.web.ui_constants import EMPTY_KNOWLEDGEBASE_MESSAGE
from pai_rag.core.rag_config import RagConfig
Expand Down Expand Up @@ -425,7 +426,7 @@ def add_datasheet(
if r.status_code != HTTPStatus.OK:
raise RagApiError(code=r.status_code, msg=response.message)
except Exception as e:
print(f"add_datasheet failed: {e}")
logger.exception(f"add_datasheet failed: {e}")
finally:
file_obj.close()

Expand Down
3 changes: 0 additions & 3 deletions src/pai_rag/app/web/tabs/settings_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
from pai_rag.app.web.utils import components_to_dict
from pai_rag.app.web.index_utils import index_related_component_keys
from pai_rag.app.web.tabs.vector_db_panel import create_vector_db_panel
import logging
import os
import pai_rag.app.web.event_listeners as ev_listeners

logger = logging.getLogger(__name__)

DEFAULT_IS_INTERACTIVE = os.environ.get("PAIRAG_RAG__SETTING__interactive", "true")


Expand Down
6 changes: 2 additions & 4 deletions src/pai_rag/app/web/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
)
from pai_rag.app.web.tabs.model.index_info import get_index_map

import logging
from loguru import logger

DEFAULT_IS_INTERACTIVE = os.environ.get("PAIRAG_RAG__SETTING__interactive", "true")

logger = logging.getLogger("WebUILogger")


def resume_ui():
outputs = {}
Expand Down Expand Up @@ -131,6 +129,6 @@ def configure_webapp(app: FastAPI, web_url, rag_url=DEFAULT_LOCAL_URL) -> gr.Blo
home = make_homepage()
home.queue(concurrency_count=1, max_size=64)
home._queue.set_url(web_url)
print(web_url)
logger.info(f"web_url: {web_url}")
gr.mount_gradio_app(app, home, path="")
return home
12 changes: 5 additions & 7 deletions src/pai_rag/core/rag_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
ImageNode,
)
import json
import logging
from loguru import logger
import os
from enum import Enum
from uuid import uuid4

DEFAULT_EMPTY_RESPONSE_GEN = "Empty Response"
DEFAULT_RAG_INDEX_FILE = "localdata/default_rag_indexes.json"
logger = logging.getLogger(__name__)


def uuid_generator() -> str:
Expand Down Expand Up @@ -74,7 +73,6 @@ async def event_generator_async(
class RagApplication:
def __init__(self, config: RagConfig):
self.name = "RagApplication"
self.logger = logging.getLogger(__name__)
self.config = config
index_manager.add_default_index(self.config)

Expand Down Expand Up @@ -147,7 +145,7 @@ async def aretrieve(self, query: RetrievalQuery) -> RetrievalResponse:

async def aquery(self, query: RagQuery, chat_type: RagChatType = RagChatType.RAG):
session_id = query.session_id or uuid_generator()
self.logger.debug(f"Get session ID: {session_id}.")
logger.debug(f"Get session ID: {session_id}.")
session_config = self.config.model_copy()
index_entry = index_manager.get_index_by_name(query.index_name)
session_config.embedding = index_entry.embedding_config
Expand All @@ -168,12 +166,12 @@ async def aquery(self, query: RagQuery, chat_type: RagChatType = RagChatType.RAG
chat_history=query.chat_history,
)
new_question = new_query_bundle.query_str
self.logger.info(f"Querying with question '{new_question}'.")
logger.info(f"Querying with question '{new_question}'.")

if query.with_intent:
intent_router = resolve_intent_router(session_config)
intent = await intent_router.aselect(str_or_query_bundle=new_question)
self.logger.info(f"[IntentDetection] Routing query to {intent}.")
logger.info(f"[IntentDetection] Routing query to {intent}.")
if intent == Intents.TOOL:
return await self.aquery_agent(query)
elif intent == Intents.WEBSEARCH:
Expand Down Expand Up @@ -295,7 +293,7 @@ async def aquery_analysis(self, query: RagQuery):
RagResponse
"""
session_id = query.session_id or uuid_generator()
self.logger.debug(f"Get session ID: {session_id}.")
logger.debug(f"Get session ID: {session_id}.")
if not query.question:
return RagResponse(
answer="Empty query. Please input your question.", session_id=session_id
Expand Down
10 changes: 6 additions & 4 deletions src/pai_rag/core/rag_config_manager.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from dynaconf import Dynaconf, loaders
from dynaconf.utils.boxing import DynaBox

import logging
from loguru import logger
import os

from pai_rag.core.rag_config import RagConfig
from pai_rag.utils.oss_utils import check_and_set_oss_auth

# store config file generated from ui.
GENERATED_CONFIG_FILE_NAME = "localdata/settings.snapshot.toml"
Expand All @@ -26,7 +27,7 @@ def from_snapshot(cls):
)
return cls(config)
except Exception as error:
logging.critical("Read config file failed.")
logger.critical("Read config file failed.")
raise error

@classmethod
Expand All @@ -51,7 +52,7 @@ def from_file(cls, config_file):
# `envvar_prefix` = export envvars with `export PAIRAG_FOO=bar`.
# `settings_files` = Load these files in the order.
except Exception as error:
logging.critical("Read config file failed.")
logger.critical("Read config file failed.")
raise error

def get_value(self) -> RagConfig:
Expand All @@ -61,6 +62,7 @@ def get_value(self) -> RagConfig:
def update(self, new_value: Dynaconf):
if self.config.get("rag", None):
self.config.rag.update(new_value, merge=True)
check_and_set_oss_auth(self.config.rag)

def persist(self):
"""Save configuration to file."""
Expand All @@ -72,5 +74,5 @@ def get_config_mtime(self):
try:
return os.path.getmtime(GENERATED_CONFIG_FILE_NAME)
except Exception as ex:
print(f"Fail to read config mtime {ex}")
logger.critical(f"Fail to read config mtime {ex}")
return -1
4 changes: 1 addition & 3 deletions src/pai_rag/core/rag_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from llama_index.core.ingestion import IngestionPipeline
from pai_rag.integrations.nodeparsers.pai.pai_node_parser import PaiNodeParser
from pai_rag.integrations.readers.pai.pai_data_reader import PaiDataReader
import logging

logger = logging.getLogger(__name__)
from loguru import logger


class RagDataLoader:
Expand Down
4 changes: 1 addition & 3 deletions src/pai_rag/core/rag_index_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
PaiBaseEmbeddingConfig,
)
from pai_rag.integrations.index.pai.vector_store_config import BaseVectorStoreConfig
import logging

logger = logging.getLogger(__name__)
from loguru import logger

DEFAULT_INDEX_FILE = "localdata/default__rag__index.json"
DEFAULT_INDEX_NAME = "default_index"
Expand Down
3 changes: 0 additions & 3 deletions src/pai_rag/core/rag_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
from pai_rag.integrations.llms.pai.pai_llm import PaiLlm
from pai_rag.integrations.llms.pai.pai_multi_modal_llm import PaiMultiModalLlm
from pai_rag.utils.oss_client import OssClient
import logging

logger = logging.getLogger(__name__)

cls_cache = {}

Expand Down
3 changes: 1 addition & 2 deletions src/pai_rag/core/rag_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
)
from openinference.instrumentation import using_attributes
from typing import Dict, List
import logging
from loguru import logger

TASK_STATUS_FILE = "__upload_task_status.tmp"
logger = logging.getLogger(__name__)


def trace_correlation_id(function):
Expand Down
Loading

0 comments on commit 7170851

Please sign in to comment.