mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-27 15:37:44 +00:00
c8f1c5364a
* change_log_object * lint code * delete comments * change_log_object * change_log_object * fix import test error * update code * update code * fix bugs * skip mypy error * skip mypy error * skip mypy error * Start the flask server before running the demo. * achieve front and back interaction * fix github-advanced-security comments * fix github-advanced-security comments * tmp ignore * fix CI * move some logic * change format * adjust logic * log2json changes * tmp * fix * fix bug * refine log2json between 5 scenarios * fix * refine codes * fix logic * use localhost * add loop & all_duration param for old scenario startup * merge control logic * add README for server ui api * update README * reuse code in logger * add loop_n and all_duration param * fix upload * ui server now use port in setting * fix port setting * fix port setting * fix mypy check * refine logger and log storage * fix ruff error * fix CI * refine logger, loop, storage * bind one FileStorage with one logger * not truncate log storage * refine LoopBase.load(), use `checkout` instead of `output_path` and `do_truncate` * clear session folder when loading loop to run * move component info init step to ExpGen Class * Update rdagent/utils/workflow.py * move truncate_session function to LoopBase class * add checkout param for other scenarios * fix bug * move WebStorage to UI * change web_storage name * add randomname to requirements * add typer * fix requirements --------- Co-authored-by: WinstonLiyte <1957922024@qq.com> Co-authored-by: Bowen Xian <xianbowen@outlook.com> Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
104 lines
2.6 KiB
Python
104 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from abc import abstractmethod
|
|
from collections.abc import Generator
|
|
from dataclasses import dataclass
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
from typing import Literal, Optional
|
|
|
|
|
|
@dataclass
|
|
class Message:
|
|
"""The info unit of the storage"""
|
|
|
|
tag: str # namespace like like a.b.c
|
|
level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] # The level of the logging
|
|
timestamp: datetime # The time when the message is generated
|
|
caller: Optional[
|
|
str
|
|
] # The caller of the logging like `rdagent.oai.llm_utils:_create_chat_completion_inner_function:55`(file:func:line)
|
|
pid_trace: Optional[str] # The process id trace; A-B-C represents A create B, B create C
|
|
content: object # The content
|
|
|
|
|
|
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,
|
|
tag: str = "",
|
|
timestamp: datetime | None = None,
|
|
) -> 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.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
def iter_msg(self) -> Generator[Message, None, None]:
|
|
"""
|
|
Iterate the message in the storage.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
def truncate(self, time: datetime) -> None:
|
|
"""
|
|
Remove all log entries after the specified time.
|
|
"""
|
|
...
|
|
|
|
def __str__(self) -> str:
|
|
return self.__class__.__name__
|
|
|
|
|
|
class View:
|
|
"""
|
|
Motivation:
|
|
|
|
Display the content in the storage
|
|
"""
|
|
|
|
# TODO: pleas fix me
|
|
@abstractmethod
|
|
def display(self, s: Storage, watch: bool = False) -> None:
|
|
"""
|
|
|
|
Parameters
|
|
----------
|
|
s : Storage
|
|
|
|
watch : bool
|
|
should we watch the new content and display them
|
|
"""
|
|
...
|