XiangJinYu commited on
Commit
52c3dce
·
verified ·
1 Parent(s): 8f2f282

add user workspace

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -5,12 +5,33 @@ from typing import Dict
5
  import streamlit as st
6
  import yaml
7
  from loguru import logger as _logger
 
 
8
 
9
  from metagpt.const import METAGPT_ROOT
10
  from metagpt.ext.spo.components.optimizer import PromptOptimizer
11
  from metagpt.ext.spo.utils.llm_client import SPO_LLM, RequestType
12
 
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  def load_yaml_template(template_path: Path) -> Dict:
15
  if template_path.exists():
16
  with open(template_path, "r", encoding="utf-8") as f:
@@ -76,6 +97,8 @@ def main():
76
  if "optimization_results" not in st.session_state:
77
  st.session_state.optimization_results = []
78
 
 
 
79
  st.title("SPO | Self-Supervised Prompt Optimization 🤖")
80
 
81
  # Sidebar for configurations
@@ -213,7 +236,7 @@ def main():
213
 
214
  # Create optimizer instance
215
  optimizer = PromptOptimizer(
216
- optimized_path="workspace",
217
  initial_round=initial_round,
218
  max_rounds=max_rounds,
219
  template=f"{template_name}.yaml",
 
5
  import streamlit as st
6
  import yaml
7
  from loguru import logger as _logger
8
+ import shutil
9
+ import uuid
10
 
11
  from metagpt.const import METAGPT_ROOT
12
  from metagpt.ext.spo.components.optimizer import PromptOptimizer
13
  from metagpt.ext.spo.utils.llm_client import SPO_LLM, RequestType
14
 
15
 
16
+
17
+ def get_user_workspace():
18
+ if "user_id" not in st.session_state:
19
+ st.session_state.user_id = str(uuid.uuid4())
20
+
21
+ workspace_dir = Path("workspace") / st.session_state.user_id
22
+ workspace_dir.mkdir(parents=True, exist_ok=True)
23
+ return workspace_dir
24
+
25
+ def cleanup_workspace(workspace_dir: Path) -> None:
26
+ try:
27
+ if workspace_dir.exists():
28
+ shutil.rmtree(workspace_dir)
29
+ _logger.info(f"Cleaned up workspace directory: {workspace_dir}")
30
+ except Exception as e:
31
+ _logger.error(f"Error cleaning up workspace: {e}")
32
+
33
+
34
+
35
  def load_yaml_template(template_path: Path) -> Dict:
36
  if template_path.exists():
37
  with open(template_path, "r", encoding="utf-8") as f:
 
97
  if "optimization_results" not in st.session_state:
98
  st.session_state.optimization_results = []
99
 
100
+ workspace_dir = get_user_workspace()
101
+
102
  st.title("SPO | Self-Supervised Prompt Optimization 🤖")
103
 
104
  # Sidebar for configurations
 
236
 
237
  # Create optimizer instance
238
  optimizer = PromptOptimizer(
239
+ optimized_path=str(workspace_dir),
240
  initial_round=initial_round,
241
  max_rounds=max_rounds,
242
  template=f"{template_name}.yaml",