Skip to content

Init workspace and CMDTask #1537

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

Merged
merged 7 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions qlib/contrib/data/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
fit_end_time=None,
filter_pipe=None,
inst_processors=None,
data_loader: Optional[dict]=None,
data_loader: Optional[dict] = None,
**kwargs
):
infer_processors = check_transform_proc(infer_processors, fit_start_time, fit_end_time)
Expand Down Expand Up @@ -158,7 +158,7 @@ def __init__(
process_type=DataHandlerLP.PTYPE_A,
filter_pipe=None,
inst_processors=None,
data_loader: Optional[dict]=None,
data_loader: Optional[dict] = None,
**kwargs
):
infer_processors = check_transform_proc(infer_processors, fit_start_time, fit_end_time)
Expand Down
17 changes: 13 additions & 4 deletions qlib/finco/conf.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# TODO: use pydantic for other modules in Qlib
from pydantic import (BaseSettings)
from pydantic import BaseSettings
from qlib.finco.utils import Singleton

import os


class Config(Singleton):
"""
This config is for fast demo purpose.
Please use BaseSettings insetead in the future
"""

def __init__(self):
self.use_azure = os.getenv("USE_AZURE") == "True"
self.temperature = 0.5 if os.getenv("TEMPERATURE") is None else float(os.getenv("TEMPERATURE"))
self.max_tokens = 800 if os.getenv("MAX_TOKENS") is None else int(os.getenv("MAX_TOKENS"))

self.openai_api_key = os.getenv("OPENAI_API_KEY")
self.use_azure = os.getenv("USE_AZURE") == "True"
self.azure_api_base = os.getenv("AZURE_API_BASE")
Expand All @@ -18,5 +24,8 @@ def __init__(self):

self.max_retry = int(os.getenv("MAX_RETRY")) if os.getenv("MAX_RETRY") is not None else None

self.continous_mode = os.getenv("CONTINOUS_MODE") == "True" if os.getenv("CONTINOUS_MODE") is not None else False
self.debug_mode = os.getenv("DEBUG_MODE") == "True" if os.getenv("DEBUG_MODE") is not None else False
self.continous_mode = (
os.getenv("CONTINOUS_MODE") == "True" if os.getenv("CONTINOUS_MODE") is not None else False
)
self.debug_mode = os.getenv("DEBUG_MODE") == "True" if os.getenv("DEBUG_MODE") is not None else False
self.workspace = os.getenv("WORKSPACE") if os.getenv("WORKSPACE") is not None else "./finco_workspace"
12 changes: 7 additions & 5 deletions qlib/finco/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def __init__(self):
self.debug_mode = True
cwd = os.getcwd()
self.cache_file_location = os.path.join(cwd, "prompt_cache.json")
self.cache = json.load(open(self.cache_file_location, "r")) if os.path.exists(self.cache_file_location) else {}

self.cache = (
json.load(open(self.cache_file_location, "r")) if os.path.exists(self.cache_file_location) else {}
)

def build_messages_and_create_chat_completion(self, user_prompt, system_prompt=None):
"""build the messages to avoid implementing several redundant lines of code"""
cfg = Config()
Expand Down Expand Up @@ -64,11 +66,11 @@ def try_create_chat_completion(self, max_retry=10, **kwargs):
def create_chat_completion(
self,
messages,
model = None,
model=None,
temperature: float = None,
max_tokens: Optional[int] = None,
) -> str:

if self.debug_mode:
if messages[1]["content"] in self.cache:
return self.cache[messages[1]["content"]]
Expand All @@ -77,7 +79,7 @@ def create_chat_completion(
temperature = self.cfg.temperature
if max_tokens is None:
max_tokens = self.cfg.max_tokens

if self.cfg.use_azure:
response = openai.ChatCompletion.create(
engine=self.cfg.model,
Expand Down
Loading