Skip to content

Commit e7cd93a

Browse files
authored
add base method for summarization; (#1530)
1 parent 3919678 commit e7cd93a

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

qlib/finco/task.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,54 @@ def execute(self) -> Literal["fail", "success"]:
168168

169169

170170
class SummarizeTask(Task):
171+
__DEFAULT_OUTPUT_PATH = "./"
172+
173+
__DEFAULT_WORKFLOW_SYSTEM_PROMPT = """
174+
Your task is to help user to analysis the output of qlib, your information including the strategy's backtest index
175+
and runtime log. You may receive some scripts of the code as well, you can use them to analysis the output.
176+
If there are any abnormal areas in the log or scripts, please also point them out.
177+
178+
Example output 1:
179+
The backtest indexes show that your strategy's max draw down is a bit large,
180+
You can try diversifying your positions across different assets.
181+
"""
182+
__DEFAULT_WORKFLOW_USER_PROMPT = "Here is my information: '{{information}}'\n{{user_prompt}}"
183+
__DEFAULT_USER_PROMPT = "Please summarize them and give me some advice."
184+
185+
def __init__(self):
186+
super().__init__()
187+
171188
def execution(self) -> Any:
172-
output_path = ''
189+
user_prompt = self._context_manager.get_context("user_prompt")
190+
user_prompt = user_prompt if user_prompt is not None else self.__DEFAULT_USER_PROMPT
191+
system_prompt = self.__DEFAULT_WORKFLOW_SYSTEM_PROMPT
192+
output_path = self._context_manager.get_context("output_path")
193+
output_path = output_path if output_path is not None else self.__DEFAULT_OUTPUT_PATH
194+
information = self.parse2txt(output_path)
173195

174-
def parse2txt(self, path) -> List:
196+
prompt_workflow_selection = Template(self.__DEFAULT_WORKFLOW_USER_PROMPT).render(information=information,
197+
user_prompt=user_prompt)
198+
messages = [
199+
{
200+
"role": "system",
201+
"content": system_prompt,
202+
},
203+
{
204+
"role": "user",
205+
"content": prompt_workflow_selection,
206+
},
207+
]
208+
response = try_create_chat_completion(messages=messages)
209+
return response
210+
211+
def summarize(self) -> str:
212+
return ''
213+
214+
def interact(self) -> Any:
215+
return
216+
217+
@staticmethod
218+
def parse2txt(path) -> List:
175219
file_list = []
176220
path = Path.cwd().joinpath(path)
177221
for root, dirs, files in os.walk(path):
@@ -189,4 +233,3 @@ def parse2txt(self, path) -> List:
189233
print(content)
190234
result.append({'postfix': postfix, 'content': content})
191235
return result
192-

qlib/finco/test_sumarize.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import unittest
2+
from dotenv import load_dotenv
23

34
from qlib.finco.task import SummarizeTask
5+
from qlib.finco.workflow import WorkflowContextManager
6+
7+
load_dotenv(verbose=True, override=True)
48

59

610
class TestSummarize(unittest.TestCase):
11+
12+
def test_execution(self):
13+
task = SummarizeTask()
14+
task.assign_context_manager(WorkflowContextManager())
15+
resp = task.execution()
16+
print(resp)
17+
718
def test_parse2txt(self):
819
task = SummarizeTask()
920
resp = task.parse2txt('')

0 commit comments

Comments
 (0)