mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-04-27 19:36:13 +00:00
* add langchain * add langchain * Add files via upload * add langchain * fix style * fix style: remove extra space * add pytest; modified retriever * add pytest; modified retriever * add tests to build_on_pr.yml * fix build_on_pr.yml * fix build on pr; fix environ vars * seperate unit tests for colossalqa from build from pr * fix container setting; fix environ vars * commented dev code * add incremental update * remove stale code * fix style * change to sha3 224 * fix retriever; fix style; add unit test for document loader * fix ci workflow config * fix ci workflow config * add set cuda visible device script in ci * fix doc string * fix style; update readme; refactored * add force log info * change build on pr, ignore colossalqa * fix docstring, captitalize all initial letters * fix indexing; fix text-splitter * remove debug code, update reference * reset previous commit * update LICENSE update README add key-value mode, fix bugs * add files back * revert force push * remove junk file * add test files * fix retriever bug, add intent classification * change conversation chain design * rewrite prompt and conversation chain * add ui v1 * ui v1 * fix atavar * add header * Refactor the RAG Code and support Pangu * Refactor the ColossalQA chain to Object-Oriented Programming and the UI demo. * resolved conversation. tested scripts under examples. web demo still buggy * fix ci tests * Some modifications to add ChatGPT api * modify llm.py and remove unnecessary files * Delete applications/ColossalQA/examples/ui/test_frontend_input.json * Remove OpenAI api key * add colossalqa * move files * move files * move files * move files * fix style * Add Readme and fix some bugs. * Add something to readme and modify some code * modify a directory name for clarity * remove redundant directory * Correct a type in llm.py * fix AI prefix * fix test_memory.py * fix conversation * fix some erros and typos * Fix a missing import in RAG_ChatBot.py * add colossalcloud LLM wrapper, correct issues in code review --------- Co-authored-by: YeAnbang <anbangy2@outlook.com> Co-authored-by: Orion-Zheng <zheng_zian@u.nus.edu> Co-authored-by: Zian(Andy) Zheng <62330719+Orion-Zheng@users.noreply.github.com> Co-authored-by: Orion-Zheng <zhengzian@u.nus.edu>
93 lines
2.6 KiB
Python
93 lines
2.6 KiB
Python
"""
|
|
Class for logging with extra control for debugging
|
|
"""
|
|
import logging
|
|
|
|
|
|
class ColossalQALogger:
|
|
"""This is a distributed event logger class essentially based on :class:`logging`.
|
|
|
|
Args:
|
|
name (str): The name of the logger.
|
|
|
|
Note:
|
|
Logging types: ``info``, ``warning``, ``debug`` and ``error``
|
|
"""
|
|
|
|
__instances = dict()
|
|
|
|
def __init__(self, name):
|
|
if name in ColossalQALogger.__instances:
|
|
raise ValueError("Logger with the same name has been created")
|
|
else:
|
|
self._name = name
|
|
self._logger = logging.getLogger(name)
|
|
|
|
ColossalQALogger.__instances[name] = self
|
|
|
|
@staticmethod
|
|
def get_instance(name: str):
|
|
"""Get the unique single logger instance based on name.
|
|
|
|
Args:
|
|
name (str): The name of the logger.
|
|
|
|
Returns:
|
|
DistributedLogger: A DistributedLogger object
|
|
"""
|
|
if name in ColossalQALogger.__instances:
|
|
return ColossalQALogger.__instances[name]
|
|
else:
|
|
logger = ColossalQALogger(name=name)
|
|
return logger
|
|
|
|
def info(self, message: str, verbose: bool = False) -> None:
|
|
"""Log an info message.
|
|
|
|
Args:
|
|
message (str): The message to be logged.
|
|
verbose (bool): Whether to print the message to stdout.
|
|
"""
|
|
if verbose:
|
|
logging.basicConfig(level=logging.INFO)
|
|
self._logger.info(message)
|
|
|
|
def warning(self, message: str, verbose: bool = False) -> None:
|
|
"""Log a warning message.
|
|
|
|
Args:
|
|
message (str): The message to be logged.
|
|
verbose (bool): Whether to print the message to stdout.
|
|
"""
|
|
if verbose:
|
|
self._logger.warning(message)
|
|
|
|
def debug(self, message: str, verbose: bool = False) -> None:
|
|
"""Log a debug message.
|
|
|
|
Args:
|
|
message (str): The message to be logged.
|
|
verbose (bool): Whether to print the message to stdout.
|
|
"""
|
|
if verbose:
|
|
self._logger.debug(message)
|
|
|
|
def error(self, message: str) -> None:
|
|
"""Log an error message.
|
|
|
|
Args:
|
|
message (str): The message to be logged.
|
|
"""
|
|
self._logger.error(message)
|
|
|
|
|
|
def get_logger(name: str = None, level=logging.INFO) -> ColossalQALogger:
|
|
"""
|
|
Get the logger by name, if name is None, return the default logger
|
|
"""
|
|
if name:
|
|
logger = ColossalQALogger.get_instance(name=name)
|
|
else:
|
|
logger = ColossalQALogger.get_instance(name="colossalqa")
|
|
return logger
|