Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust logging system #51

Merged
merged 17 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ USE_EMBEDDING_CACHE=True
LOG_LLM_CHAT_CONTENT=False
CHAT_FREQUENCY_PENALTY=0.0
CHAT_PRESENCE_PENALTY=0.0
LOG_TRACE_PATH=log_traces

# embedding model configs:
EMBEDDING_OPENAI_API_KEY=your_api_key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rdagent.scenarios.qlib.factor_task_implementation import (
COSTEERFG_QUANT_FACTOR_IMPLEMENTATION,
)
from rdagent.log import rdagent_logger as logger

assert load_dotenv()

Expand All @@ -20,3 +21,5 @@ def extract_factors_and_implement(report_file_path: str) -> None:

if __name__ == "__main__":
extract_factors_and_implement("/home/xuyang1/workspace/report.pdf")

# %%
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
FileBasedFactorImplementation,
)
from rdagent.core.evolving_framework import EvolvableSubjects
from rdagent.core.log import RDAgentLog
from rdagent.log import rdagent_logger as logger


class FactorEvolvingItem(FactorExperiment, EvolvableSubjects):
Expand All @@ -23,7 +23,7 @@ def __init__(
sub_gt_implementations,
) != len(self.sub_tasks):
self.sub_gt_implementations = None
RDAgentLog().warning(
logger.warning(
"The length of sub_gt_implementations is not equal to the length of sub_tasks, set sub_gt_implementations to None",
)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
RAGStrategy,
)
from rdagent.core.experiment import Implementation
from rdagent.core.log import RDAgentLog
from rdagent.log import rdagent_logger as logger
from rdagent.core.prompts import Prompts
from rdagent.oai.llm_utils import (
APIBackend,
Expand Down Expand Up @@ -336,7 +336,7 @@ def analyze_component(
)["component_no_list"]
return [all_component_nodes[index - 1] for index in sorted(list(set(component_no_list)))]
except:
RDAgentLog().warning("Error when analyzing components.")
logger.warning("Error when analyzing components.")
analyze_component_user_prompt = "Your response is not a valid component index list."

return []
Expand Down Expand Up @@ -714,7 +714,7 @@ def __init__(self, init_component_list=None) -> None:
Load knowledge, offer brief information of knowledge and common handle interfaces
"""
self.graph: UndirectedGraph = UndirectedGraph.load(Path.cwd() / "graph.pkl")
RDAgentLog().info(f"Knowledge Graph loaded, size={self.graph.size()}")
logger.info(f"Knowledge Graph loaded, size={self.graph.size()}")

if init_component_list:
for component in init_component_list:
Expand Down
4 changes: 2 additions & 2 deletions rdagent/components/coder/factor_coder/CoSTEER/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)
from rdagent.components.coder.factor_coder.utils import get_data_folder_intro
from rdagent.core.conf import RD_AGENT_SETTINGS
from rdagent.core.log import RDAgentLog
from rdagent.log import rdagent_logger as logger
from rdagent.core.prompts import Prompts
from rdagent.core.scenario import Scenario
from rdagent.oai.llm_utils import APIBackend
Expand All @@ -25,7 +25,7 @@ def RandomSelect(to_be_finished_task_index, implementation_factors_per_round):
implementation_factors_per_round,
)

RDAgentLog().info(f"The random selection is: {to_be_finished_task_index}")
logger.info(f"The random selection is: {to_be_finished_task_index}")
return to_be_finished_task_index


Expand Down
4 changes: 2 additions & 2 deletions rdagent/components/coder/factor_coder/factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
RuntimeErrorException,
)
from rdagent.core.experiment import Experiment, FBImplementation, Task
from rdagent.core.log import RDAgentLog
from rdagent.log import rdagent_logger as logger
from rdagent.oai.llm_utils import md5_hash


Expand Down Expand Up @@ -74,7 +74,7 @@ def __init__(
) -> None:
super().__init__(*args, **kwargs)
self.executed_factor_value_dataframe = executed_factor_value_dataframe
self.logger = RDAgentLog()
self.logger = logger
self.raise_exception = raise_exception

@staticmethod
Expand Down
5 changes: 2 additions & 3 deletions rdagent/components/coder/model_coder/task_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
load_and_process_pdfs_by_langchain,
)
from rdagent.components.loader.task_loader import ModelTaskLoader
from rdagent.core.log import RDAgentLog
from rdagent.log import rdagent_logger as logger
from rdagent.core.prompts import Prompts
from rdagent.oai.llm_utils import APIBackend

document_process_prompts = Prompts(file_path=Path(__file__).parent / "prompts.yaml")


def extract_model_from_doc(doc_content: str) -> dict:
"""
Extract model information from document content.
Expand Down Expand Up @@ -62,7 +61,7 @@ def extract_model_from_doc(doc_content: str) -> dict:
else:
break

RDAgentLog().info(f"已经完成{len(model_dict)}个模型的提取")
logger.info(f"已经完成{len(model_dict)}个模型的提取")

return model_dict

Expand Down
7 changes: 3 additions & 4 deletions rdagent/components/knowledge_management/vector_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import pandas as pd
from scipy.spatial.distance import cosine

from rdagent.core.log import RDAgentLog
from rdagent.log import rdagent_logger as logger
from rdagent.oai.llm_utils import APIBackend


class KnowledgeMetaData:
def __init__(self, content: str = "", label: str = None, embedding=None, identity=None):
self.label = label
Expand Down Expand Up @@ -127,7 +126,7 @@ def __init__(self, vector_df_path: Union[str, Path] = None):
else:
self.vector_df = pd.DataFrame(columns=["id", "label", "content", "embedding"])

RDAgentLog().info(f"VectorBase loaded, shape={self.vector_df.shape}")
logger.info(f"VectorBase loaded, shape={self.vector_df.shape}")

def shape(self):
return self.vector_df.shape
Expand Down Expand Up @@ -205,4 +204,4 @@ def load(self, vector_df_path, **kwargs):

def save(self, vector_df_path, **kwargs):
self.vector_df.to_pickle(vector_df_path)
RDAgentLog().info(f"Save vectorBase vector_df to: {vector_df_path}")
logger.info(f"Save vectorBase vector_df to: {vector_df_path}")
6 changes: 5 additions & 1 deletion rdagent/core/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

class RDAgentSettings(BaseSettings):
# TODO: (xiao) I think most of the config should be in oai.config
# Log configs
# TODO: (xiao) think it can be a seperate config.
log_trace_path: str | None = None
you-n-g marked this conversation as resolved.
Show resolved Hide resolved
log_llm_chat_content: bool = True

use_azure: bool = True
use_azure_token_provider: bool = False
managed_identity_client_id: str | None = None
Expand All @@ -28,7 +33,6 @@ class RDAgentSettings(BaseSettings):
prompt_cache_path: str = str(Path.cwd() / "prompt_cache.db")
session_cache_folder_location: str = str(Path.cwd() / "session_cache_folder/")
max_past_message_include: int = 10
log_llm_chat_content: bool = True

# Chat configs
chat_openai_api_key: str = ""
Expand Down
141 changes: 0 additions & 141 deletions rdagent/core/log.py

This file was deleted.

5 changes: 4 additions & 1 deletion rdagent/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class RDAgentException(Exception): # noqa: N818


class SingletonMeta(type):
_instance_dict: ClassVar[dict] = {}
# _instance_dict: ClassVar[dict] = {}
def __init__(cls, *args, **kwargs):
cls._instance_dict = {} # 为每个类创建一个唯一的_instance_dict字典
you-n-g marked this conversation as resolved.
Show resolved Hide resolved
super().__init__(*args, **kwargs)

def __call__(cls, *args: Any, **kwargs: Any) -> Any:
# Since it's hard to align the difference call using args and kwargs, we strictly ask to use kwargs in Singleton
Expand Down
4 changes: 4 additions & 0 deletions rdagent/log/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .logger import RDAgentLog
from .utils import LogColors

rdagent_logger: RDAgentLog = RDAgentLog()
you-n-g marked this conversation as resolved.
Show resolved Hide resolved
62 changes: 62 additions & 0 deletions rdagent/log/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from __future__ import annotations

from abc import abstractmethod
from pathlib import Path


class Storage:
"""
Basic storage to support saving objects;

# Usage:

The storage has mainly two kind of users:
- The logging end: you can choose any of the following method to use the object
- We can use it directly with the native logging storage
- We can use it with other logging tools; For example, serve as a handler for loggers
- The view end:
- Mainly for the subclass of `logging.base.View`
- It should provide two kind of ways to provide content
- offline content provision.
- online content preovision.
"""

@abstractmethod
def log(self, obj: object, name: str = "", **kwargs: dict) -> str | Path:
"""

Parameters
----------
obj : object
The object for logging.
name : str
The name of the object. For example "a.b.c"
We may log a lot of objects to a same name

Returns
-------
str | Path
The storage identifier of the object.
"""
...


class View:
"""
Motivation:

Display the content in the storage
"""
# TODO: pleas fix me
@abstractmethod
def display(s: Storage, watch: bool=False):
"""

Parameters
----------
s : Storage

watch : bool
should we watch the new content and display them
"""
...
Loading
Loading