From 55af3a4ddfd5d487729eeb8498b2513d7778ebf6 Mon Sep 17 00:00:00 2001 From: zhangxu0307 Date: Tue, 23 Jan 2024 14:47:44 +0800 Subject: [PATCH] fix exp bugs --- .../code_generator/code_generator.py | 11 +++++--- taskweaver/memory/experience.py | 5 ++-- taskweaver/planner/planner.py | 10 ++++--- taskweaver/planner/planner_exp_prompt.yaml | 27 ------------------- taskweaver/session/session.py | 4 +-- 5 files changed, 19 insertions(+), 38 deletions(-) delete mode 100644 taskweaver/planner/planner_exp_prompt.yaml diff --git a/taskweaver/code_interpreter/code_generator/code_generator.py b/taskweaver/code_interpreter/code_generator/code_generator.py index 9b4fdebc..1c9a092c 100644 --- a/taskweaver/code_interpreter/code_generator/code_generator.py +++ b/taskweaver/code_interpreter/code_generator/code_generator.py @@ -143,10 +143,15 @@ def compose_prompt( plugins: List[PluginEntry], selected_experiences: Optional[List[Experience]] = None, ) -> List[ChatMessageType]: - experiences = self.experience_generator.format_experience_in_prompt( - self.prompt_data["experience_instruction"], - selected_experiences, + experiences = ( + self.experience_generator.format_experience_in_prompt( + self.prompt_data["experience_instruction"], + selected_experiences, + ) + if self.config.use_experience + else "" ) + chat_history = [format_chat_message(role="system", message=f"{self.instruction}\n{experiences}")] if self.examples is None: diff --git a/taskweaver/memory/experience.py b/taskweaver/memory/experience.py index 5cdce8ac..cfdc9523 100644 --- a/taskweaver/memory/experience.py +++ b/taskweaver/memory/experience.py @@ -1,6 +1,5 @@ import json import os -import warnings from dataclasses import dataclass, field from typing import Any, Dict, List, Literal, Optional, Tuple @@ -147,7 +146,7 @@ def refresh( exp_ids = raw_exp_ids + handcrafted_exp_ids if len(exp_ids) == 0: - warnings.warn( + self.logger.warning( "No raw experience found. " "Please type /save in the chat window to save raw experience" "or write handcrafted experience.", @@ -219,7 +218,7 @@ def load_experience( ] exp_ids = [os.path.splitext(os.path.basename(exp_file))[0].split("_")[2] for exp_file in original_exp_files] if len(exp_ids) == 0: - warnings.warn( + self.logger.warning( f"No experience found for {target_role}." f"Please type /save in the chat window to save raw experience or write handcrafted experience." + self.exception_message_for_refresh, diff --git a/taskweaver/planner/planner.py b/taskweaver/planner/planner.py index 3d24339f..379f9f95 100644 --- a/taskweaver/planner/planner.py +++ b/taskweaver/planner/planner.py @@ -196,9 +196,13 @@ def compose_prompt( rounds: List[Round], selected_experiences: Optional[List[Experience]] = None, ) -> List[ChatMessageType]: - experiences = self.experience_generator.format_experience_in_prompt( - self.prompt_data["experience_instruction"], - selected_experiences, + experiences = ( + self.experience_generator.format_experience_in_prompt( + self.prompt_data["experience_instruction"], + selected_experiences, + ) + if self.config.use_experience + else "" ) chat_history = [format_chat_message(role="system", message=f"{self.instruction}\n{experiences}")] diff --git a/taskweaver/planner/planner_exp_prompt.yaml b/taskweaver/planner/planner_exp_prompt.yaml deleted file mode 100644 index 588bccce..00000000 --- a/taskweaver/planner/planner_exp_prompt.yaml +++ /dev/null @@ -1,27 +0,0 @@ -version: 0.1 -content: |- - You are provided with a chat history between User, Planner, and CodeInterpreter. - User send a request to Planner, and Planner asks CodeInterpreter to fulfill the request. - You need to summarize the experience and lessons learned from the chat history. - The extracted experience and lessons learned will be used to improve the performance, or avoid the same mistakes, when the similar task is requested in the future. - - # About Input - The chat history is a list of JSON objects. - The full chat history consists of multiple rounds of conversation. - Each round of conversation starts with a user query, and contains a post list, recording the conversation between Planner and CodeInterpreter. - There are multiple attachments in each post, describing the additional information related to the conversation. - - # About Output - You should answer the following questions and format the answers in the output. - - User Query: The user query/task/request for the given conversation. - - Best Practice: - - How should Planner make a plan to finish the User query/task/request correctly, bypassing the mistakes made by Planner/CodeInterpreter in the chat history? - - What additional information or guidance did User provide to help the Planner make the correct and clear plan? - - How should Planner instruct CodeInterpreter to execute the plan, bypassing the mistakes made by CodeInterpreter in the chat history? - - Mistakes to Avoid: - - What's the mistakes should be avoided in the future planning? - - Is there any additional information or guidance that should be provided by Planner to make CodeInterpreter generate the correct code in one time? - - Critical Information: If there are critical information for planning, please include them in the output. - - - DO NOT add the results of this conversation in the output. - - Generate only one experience from the given conversation. diff --git a/taskweaver/session/session.py b/taskweaver/session/session.py index aef2909a..261d3c60 100644 --- a/taskweaver/session/session.py +++ b/taskweaver/session/session.py @@ -48,6 +48,8 @@ def __init__( self.workspace = workspace.get_session_dir(self.session_id) self.execution_cwd = os.path.join(self.workspace, "cwd") + self.init() + self.round_index = 0 self.memory = Memory(session_id=self.session_id) @@ -79,8 +81,6 @@ def __init__( self.max_internal_chat_round_num = self.config.max_internal_chat_round_num self.internal_chat_num = 0 - self.init() - self.logger.dump_log_file( self, file_path=os.path.join(self.workspace, f"{self.session_id}.json"),