mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-03 02:50:58 +08:00
Merge pull request #1581 from microsoft/xuyang1/fix_singleton_bug
fix singleton bug
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
# TODO: use pydantic for other modules in Qlib
|
||||
from pydantic import BaseSettings
|
||||
from qlib.finco.utils import Singleton
|
||||
from qlib.finco.utils import SingletonBaseClass
|
||||
|
||||
import os
|
||||
|
||||
|
||||
class Config(Singleton):
|
||||
class Config(SingletonBaseClass):
|
||||
"""
|
||||
This config is for fast demo purpose.
|
||||
Please use BaseSettings insetead in the future
|
||||
|
||||
@@ -4,11 +4,11 @@ import openai
|
||||
import json
|
||||
from typing import Optional
|
||||
from qlib.finco.conf import Config
|
||||
from qlib.finco.utils import Singleton
|
||||
from qlib.finco.utils import SingletonBaseClass
|
||||
from qlib.finco.log import FinCoLog
|
||||
|
||||
|
||||
class APIBackend(Singleton):
|
||||
class APIBackend(SingletonBaseClass):
|
||||
def __init__(self):
|
||||
self.cfg = Config()
|
||||
openai.api_key = self.cfg.openai_api_key
|
||||
|
||||
@@ -4,7 +4,7 @@ This module will base on Qlib's logger module and provides some interactive func
|
||||
import logging
|
||||
|
||||
from typing import Dict, List
|
||||
from qlib.finco.utils import Singleton
|
||||
from qlib.finco.utils import SingletonBaseClass
|
||||
from contextlib import contextmanager
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ def formatting_log(logger, title="Info"):
|
||||
logger.info("")
|
||||
|
||||
|
||||
class FinCoLog(Singleton):
|
||||
class FinCoLog(SingletonBaseClass):
|
||||
# TODO:
|
||||
# - config to file logger and save it into workspace
|
||||
def __init__(self) -> None:
|
||||
|
||||
@@ -3,11 +3,11 @@ from pathlib import Path
|
||||
from jinja2 import Template
|
||||
import yaml
|
||||
|
||||
from qlib.finco.utils import Singleton
|
||||
from qlib.finco.utils import SingletonBaseClass
|
||||
from qlib.finco import get_finco_path
|
||||
|
||||
|
||||
class PromptTemplate(Singleton):
|
||||
class PromptTemplate(SingletonBaseClass):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
_template = yaml.load(open(Path.joinpath(get_finco_path(), "prompt_template.yaml"), "r"),
|
||||
|
||||
@@ -723,9 +723,9 @@ class YamlEditTask(ActionTask):
|
||||
# TODO hotfix for the bug that the record signalrecord config is not updated
|
||||
for record in target_config['task']['record']:
|
||||
if record['class'] == 'SignalRecord':
|
||||
if 'model' in record['kwargs']:
|
||||
if 'kwargs' in record and 'model' in record['kwargs']:
|
||||
del record['kwargs']["model"]
|
||||
if 'dataset' in record['kwargs']:
|
||||
if 'kwargs' in record and 'dataset' in record['kwargs']:
|
||||
del record['kwargs']["dataset"]
|
||||
|
||||
# 4) save the config file
|
||||
|
||||
@@ -3,14 +3,16 @@ import json
|
||||
from fuzzywuzzy import fuzz
|
||||
|
||||
|
||||
class Singleton:
|
||||
class Singleton(type):
|
||||
_instance = None
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
def __call__(cls, *args, **kwargs):
|
||||
if cls._instance is None:
|
||||
cls._instance = super().__new__(cls, *args, **kwargs)
|
||||
cls._instance = super(Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls._instance
|
||||
|
||||
class SingletonBaseClass(metaclass=Singleton):
|
||||
pass
|
||||
|
||||
def parse_json(response):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user