Merge pull request #7 from z060142/Refactoring

Enhance llm_debug_script.py to allow dynamic username input
This commit is contained in:
z060142 2025-04-27 23:36:18 +08:00 committed by GitHub
commit 74270aace7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View File

@ -436,6 +436,14 @@ Wolf Chat 是一個基於 MCP (Modular Capability Provider) 框架的聊天機
- 實現進程追蹤和按鈕狀態管理,確保在有腳本運行時禁用運行按鈕,啟用停止按鈕。
- **效果**:提高了 `Setup.py` 的易用性,方便使用者在調整設定後直接啟動腳本進行測試,並提供了便捷的終止方式。
### llm_debug_script.py 功能增強
- **目的**:讓用戶在啟動時能夠輸入自己的名字。
- **修改內容**
- 新增了一個 `get_username()` 函數來提示用戶輸入名字
- 在 `debug_loop()` 函數中,刪除了固定的 `user_name = "Debugger"` 行,並替換為從 `get_username()` 函數獲取名字的調用
- **效果**:修改後,腳本啟動時會提示用戶輸入自己的名字。如果用戶直接按 Enter 而不輸入任何名字,它將使用預設的 `Debugger` 作為用戶名。輸入完名字後,腳本會繼續執行原來的功能。
## 開發建議
### 優化方向

View File

@ -146,6 +146,16 @@ async def shutdown():
all_discovered_mcp_tools.clear()
print("Cleanup completed.")
# --- Get Username Function ---
async def get_username():
"""Prompt the user for their name and return it."""
print("\nPlease enter your name (or press Enter to use 'Debugger'): ", end="")
user_input = await asyncio.get_event_loop().run_in_executor(None, sys.stdin.readline)
user_name = user_input.strip()
if not user_name:
user_name = "Debugger" # Default name if nothing is entered
return user_name
# --- Main Debug Loop ---
async def debug_loop():
"""Main loop for interactive LLM debugging."""
@ -162,13 +172,15 @@ async def debug_loop():
if confirm.strip().lower() != 'y':
return
# 3. Get username
user_name = await get_username()
print(f"Debug session started as: {user_name}")
print("\n--- LLM Debug Interface ---")
print("Enter your message to the LLM.")
print("Type 'quit' or 'exit' to stop.")
print("-----------------------------")
user_name = "Debugger" # Fixed user name for this script
while not shutdown_requested:
try:
# Get user input asynchronously
@ -268,4 +280,4 @@ if __name__ == "__main__":
print("Running final shutdown...")
loop.run_until_complete(shutdown())
loop.close()
print("LLM Debug Script finished.")
print("LLM Debug Script finished.")