Skip to content

add base method for summarization; #1530

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 1 commit into from
May 31, 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
49 changes: 46 additions & 3 deletions qlib/finco/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,54 @@ def execute(self) -> Literal["fail", "success"]:


class SummarizeTask(Task):
__DEFAULT_OUTPUT_PATH = "./"

__DEFAULT_WORKFLOW_SYSTEM_PROMPT = """
Your task is to help user to analysis the output of qlib, your information including the strategy's backtest index
and runtime log. You may receive some scripts of the code as well, you can use them to analysis the output.
If there are any abnormal areas in the log or scripts, please also point them out.

Example output 1:
The backtest indexes show that your strategy's max draw down is a bit large,
You can try diversifying your positions across different assets.
"""
__DEFAULT_WORKFLOW_USER_PROMPT = "Here is my information: '{{information}}'\n{{user_prompt}}"
__DEFAULT_USER_PROMPT = "Please summarize them and give me some advice."

def __init__(self):
super().__init__()

def execution(self) -> Any:
output_path = ''
user_prompt = self._context_manager.get_context("user_prompt")
user_prompt = user_prompt if user_prompt is not None else self.__DEFAULT_USER_PROMPT
system_prompt = self.__DEFAULT_WORKFLOW_SYSTEM_PROMPT
output_path = self._context_manager.get_context("output_path")
output_path = output_path if output_path is not None else self.__DEFAULT_OUTPUT_PATH
information = self.parse2txt(output_path)

def parse2txt(self, path) -> List:
prompt_workflow_selection = Template(self.__DEFAULT_WORKFLOW_USER_PROMPT).render(information=information,
user_prompt=user_prompt)
messages = [
{
"role": "system",
"content": system_prompt,
},
{
"role": "user",
"content": prompt_workflow_selection,
},
]
response = try_create_chat_completion(messages=messages)
return response

def summarize(self) -> str:
return ''

def interact(self) -> Any:
return

@staticmethod
def parse2txt(path) -> List:
file_list = []
path = Path.cwd().joinpath(path)
for root, dirs, files in os.walk(path):
Expand All @@ -189,4 +233,3 @@ def parse2txt(self, path) -> List:
print(content)
result.append({'postfix': postfix, 'content': content})
return result

11 changes: 11 additions & 0 deletions qlib/finco/test_sumarize.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import unittest
from dotenv import load_dotenv

from qlib.finco.task import SummarizeTask
from qlib.finco.workflow import WorkflowContextManager

load_dotenv(verbose=True, override=True)


class TestSummarize(unittest.TestCase):

def test_execution(self):
task = SummarizeTask()
task.assign_context_manager(WorkflowContextManager())
resp = task.execution()
print(resp)

def test_parse2txt(self):
task = SummarizeTask()
resp = task.parse2txt('')
Expand Down