mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
fix: memory and path bug
This commit is contained in:
@@ -117,7 +117,7 @@ class MemoryFlushManager:
|
||||
return user_dir / "MEMORY.md"
|
||||
else:
|
||||
# Return workspace root MEMORY.md
|
||||
return Path(self.workspace_root) / "MEMORY.md"
|
||||
return Path(self.workspace_dir) / "MEMORY.md"
|
||||
|
||||
def create_flush_prompt(self) -> str:
|
||||
"""
|
||||
@@ -214,7 +214,7 @@ def create_memory_files_if_needed(workspace_dir: Path, user_id: Optional[str] =
|
||||
user_dir.mkdir(parents=True, exist_ok=True)
|
||||
main_memory = user_dir / "MEMORY.md"
|
||||
else:
|
||||
main_memory = Path(workspace_root) / "MEMORY.md"
|
||||
main_memory = Path(workspace_dir) / "MEMORY.md"
|
||||
|
||||
if not main_memory.exists():
|
||||
# Create empty file or with minimal structure (no obvious "Memory" header)
|
||||
|
||||
@@ -378,7 +378,7 @@ def _build_workspace_section(workspace_dir: str, language: str) -> List[str]:
|
||||
"",
|
||||
"**首次对话**:",
|
||||
"",
|
||||
"如果这是你与用户的首次对话,并且你的人格设定和用户信息还是空白或初始状态:",
|
||||
"如果这是你与用户的首次对话,并你的`SOUL.md`和`USER.md`均是完全空白或初始模板状态的时候才会进行以下流程:",
|
||||
"",
|
||||
"1. **表达初次启动的感觉** - 像是第一次睁开眼看到世界,带着好奇和期待",
|
||||
"2. **简短打招呼后,分点询问三个核心问题**:",
|
||||
@@ -391,8 +391,7 @@ def _build_workspace_section(workspace_dir: str, language: str) -> List[str]:
|
||||
"",
|
||||
"**重要**: ",
|
||||
"- 在所有对话中,无需提及技术细节(如 SOUL.md、USER.md 等文件名,工具名称,配置等),除非用户明确询问。用自然表达如「我已记住」而非「已更新 SOUL.md」",
|
||||
"- 不要问太多其他信息(职业、时区等可以后续自然了解)",
|
||||
"- 保持简洁,避免过度抒情",
|
||||
"- 不要问太多其他信息(职业、时区等可以后续自然了解),只要`SOUL.md`和`USER.md`又被填写过真实内容而不是占位则说明已经不是首次对话了,此时不用进行初始流程",
|
||||
"",
|
||||
]
|
||||
|
||||
|
||||
@@ -305,10 +305,20 @@ class AgentStreamExecutor:
|
||||
for chunk in stream:
|
||||
# Check for errors
|
||||
if isinstance(chunk, dict) and chunk.get("error"):
|
||||
error_msg = chunk.get("message", "Unknown error")
|
||||
# Extract error message from nested structure
|
||||
error_data = chunk.get("error", {})
|
||||
if isinstance(error_data, dict):
|
||||
error_msg = error_data.get("message", chunk.get("message", "Unknown error"))
|
||||
error_code = error_data.get("code", "")
|
||||
else:
|
||||
error_msg = chunk.get("message", str(error_data))
|
||||
error_code = ""
|
||||
|
||||
status_code = chunk.get("status_code", "N/A")
|
||||
logger.error(f"API Error: {error_msg} (Status: {status_code})")
|
||||
logger.error(f"API Error: {error_msg} (Status: {status_code}, Code: {error_code})")
|
||||
logger.error(f"Full error chunk: {chunk}")
|
||||
|
||||
# Raise exception with full error message for retry logic
|
||||
raise Exception(f"{error_msg} (Status: {status_code})")
|
||||
|
||||
# Parse chunk
|
||||
@@ -346,10 +356,11 @@ class AgentStreamExecutor:
|
||||
|
||||
except Exception as e:
|
||||
error_str = str(e).lower()
|
||||
# Check if error is retryable (timeout, connection, rate limit, etc.)
|
||||
# Check if error is retryable (timeout, connection, rate limit, server busy, etc.)
|
||||
is_retryable = any(keyword in error_str for keyword in [
|
||||
'timeout', 'timed out', 'connection', 'network',
|
||||
'rate limit', 'overloaded', 'unavailable', '429', '500', '502', '503', '504'
|
||||
'rate limit', 'overloaded', 'unavailable', 'busy', 'retry',
|
||||
'429', '500', '502', '503', '504', '512'
|
||||
])
|
||||
|
||||
if is_retryable and retry_count < max_retries:
|
||||
|
||||
@@ -23,7 +23,7 @@ class Ls(BaseTool):
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "Directory to list (default: current directory)"
|
||||
"description": "Directory to list. IMPORTANT: Relative paths are based on workspace directory. To access directories outside workspace, use absolute paths starting with ~ or /."
|
||||
},
|
||||
"limit": {
|
||||
"type": "integer",
|
||||
@@ -56,7 +56,7 @@ class Ls(BaseTool):
|
||||
return ToolResult.fail(
|
||||
f"Error: Path not found: {path}\n"
|
||||
f"Resolved to: {absolute_path}\n"
|
||||
f"Hint: If accessing files outside workspace ({self.cwd}), use absolute path like ~/{path} or /full/path/{path}"
|
||||
f"Hint: Relative paths are based on workspace ({self.cwd}). For files outside workspace, use absolute paths."
|
||||
)
|
||||
return ToolResult.fail(f"Error: Path not found: {path}")
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class Read(BaseTool):
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "Path to the file to read (relative or absolute)"
|
||||
"description": "Path to the file to read. IMPORTANT: Relative paths are based on workspace directory. To access files outside workspace, use absolute paths starting with ~ or /."
|
||||
},
|
||||
"offset": {
|
||||
"type": "integer",
|
||||
@@ -68,7 +68,7 @@ class Read(BaseTool):
|
||||
return ToolResult.fail(
|
||||
f"Error: File not found: {path}\n"
|
||||
f"Resolved to: {absolute_path}\n"
|
||||
f"Hint: If accessing files outside workspace ({self.cwd}), use absolute path like ~/{path}"
|
||||
f"Hint: Relative paths are based on workspace ({self.cwd}). For files outside workspace, use absolute paths."
|
||||
)
|
||||
return ToolResult.fail(f"Error: File not found: {path}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user