Skip to content

Commit 4d3a4f3

Browse files
committed
Update dev version
* Add CoT GUI * Move files
1 parent 268cf10 commit 4d3a4f3

File tree

21 files changed

+207
-46
lines changed

21 files changed

+207
-46
lines changed

automation_ide/automation_editor_ui/prompt_edit_gui/__init__.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/__init__.py

File renamed without changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.code_smell_detector import \
2+
CODE_SMELL_DETECTOR_TEMPLATE
3+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.first_code_review import \
4+
FIRST_CODE_REVIEW_TEMPLATE
5+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.first_summary_prompt import \
6+
FIRST_SUMMARY_TEMPLATE
7+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.global_rule import \
8+
GLOBAL_RULE_TEMPLATE
9+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.judge import \
10+
JUDGE_TEMPLATE
11+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.linter import \
12+
LINTER_TEMPLATE
13+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.total_summary import \
14+
TOTAL_SUMMARY_TEMPLATE
15+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.skills_prompt_templates.code_explainer import \
16+
CODE_EXPLAINER_TEMPLATE
17+
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.skills_prompt_templates.code_review import \
18+
CODE_REVIEW_SKILL_TEMPLATE
19+
20+
COT_TEMPLATE_FILES = [
21+
"global_rule.md",
22+
"first_summary_prompt.md",
23+
"first_code_review.md",
24+
"judge.md",
25+
"total_summary.md",
26+
"linter.md",
27+
"code_smell_detector.md",
28+
]
29+
30+
COT_TEMPLATE_RELATION = {
31+
"global_rule.md": GLOBAL_RULE_TEMPLATE,
32+
"first_summary_prompt.md": FIRST_SUMMARY_TEMPLATE,
33+
"first_code_review.md": FIRST_CODE_REVIEW_TEMPLATE,
34+
"judge.md": JUDGE_TEMPLATE,
35+
"total_summary.md": TOTAL_SUMMARY_TEMPLATE,
36+
"linter.md": LINTER_TEMPLATE,
37+
"code_smell_detector.md": CODE_SMELL_DETECTOR_TEMPLATE,
38+
}
39+
40+
SKILLS_TEMPLATE_FILES = [
41+
"code_review_skill.md",
42+
"code_explainer_skill.md",
43+
]
44+
45+
SKILLS_TEMPLATE_RELATION = {
46+
"code_review_skill.md": CODE_REVIEW_SKILL_TEMPLATE,
47+
"code_explainer_skill.md": CODE_EXPLAINER_TEMPLATE
48+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import sys
2+
3+
import requests
4+
from PySide6.QtCore import QThread, Signal
5+
from PySide6.QtWidgets import (
6+
QApplication, QWidget, QVBoxLayout, QHBoxLayout,
7+
QPushButton, QTextEdit, QLabel, QLineEdit, QComboBox
8+
)
9+
from je_editor import language_wrapper
10+
11+
from automation_ide.automation_editor_ui.extend_ai_gui.ai_gui_global_variable import COT_TEMPLATE_FILES
12+
13+
14+
# Worker Thread 負責傳送資料
15+
class SenderThread(QThread):
16+
update_response = Signal(str, str) # (filename, response)
17+
18+
def __init__(self, files, url):
19+
super().__init__()
20+
self.files = files
21+
self.url = url
22+
23+
def run(self):
24+
for file in self.files:
25+
try:
26+
with open(file, "r", encoding="utf-8") as f:
27+
content = f.read()
28+
# 傳送到指定 URL
29+
resp = requests.post(self.url, json={"prompt": content})
30+
reply_text = resp.text
31+
except Exception as e:
32+
reply_text = f"{language_wrapper.language_word_dict.get("cot_gui_error_sending")} {file} {e}"
33+
34+
# 發送訊號更新 UI
35+
self.update_response.emit(file, reply_text)
36+
37+
38+
class PromptSenderUI(QWidget):
39+
def __init__(self):
40+
super().__init__()
41+
self.setWindowTitle(language_wrapper.language_word_dict.get("cot_gui_window_title"))
42+
43+
# 檔案清單
44+
self.files = COT_TEMPLATE_FILES
45+
46+
# UI 元件
47+
layout = QVBoxLayout()
48+
49+
# URL 輸入框
50+
url_layout = QHBoxLayout()
51+
url_layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_api_url")))
52+
self.url_input = QLineEdit()
53+
self.url_input.setPlaceholderText(language_wrapper.language_word_dict.get("cot_gui_placeholder_api_url"))
54+
url_layout.addWidget(self.url_input)
55+
layout.addLayout(url_layout)
56+
57+
# 傳送資料區域
58+
self.prompt_view = QTextEdit()
59+
self.prompt_view.setPlaceholderText(language_wrapper.language_word_dict.get("cot_gui_placeholder_prompt_view"))
60+
layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_prompt_area")))
61+
layout.addWidget(self.prompt_view)
62+
63+
# 回傳區域
64+
self.response_selector = QComboBox() # 改用 ComboBox
65+
self.response_view = QTextEdit()
66+
self.response_view.setReadOnly(True) # 可複製但不可編輯
67+
68+
hbox_layout = QHBoxLayout()
69+
hbox_layout.addWidget(self.response_selector, 2)
70+
hbox_layout.addWidget(self.response_view, 5)
71+
72+
layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_response_area")))
73+
layout.addLayout(hbox_layout)
74+
75+
# 傳送按鈕
76+
self.send_button = QPushButton(language_wrapper.language_word_dict.get("cot_gui_button_send"))
77+
layout.addWidget(self.send_button)
78+
79+
self.setLayout(layout)
80+
81+
# 綁定事件
82+
self.response_selector.currentTextChanged.connect(self.show_response)
83+
self.send_button.clicked.connect(self.start_sending)
84+
85+
# 儲存回覆
86+
self.responses = {}
87+
88+
def show_response(self, filename):
89+
if filename in self.responses:
90+
self.response_view.setPlainText(self.responses[filename])
91+
92+
def start_sending(self):
93+
# 顯示第一個檔案內容
94+
if self.files:
95+
try:
96+
with open(self.files[0], "r", encoding="utf-8") as f:
97+
self.prompt_view.setPlainText(f.read())
98+
except Exception as e:
99+
self.prompt_view.setPlainText(
100+
f"{language_wrapper.language_word_dict.get("cot_gui_error_read_file")}: {e}")
101+
102+
# 取得 URL
103+
url = self.url_input.text().strip()
104+
if not url:
105+
self.prompt_view.setPlainText(language_wrapper.language_word_dict.get("cot_gui_error_no_url"))
106+
return
107+
108+
# 啟動傳送 Thread
109+
self.thread = SenderThread(self.files, url)
110+
self.thread.update_response.connect(self.handle_response)
111+
self.thread.start()
112+
113+
def handle_response(self, filename, response):
114+
self.responses[filename] = response
115+
self.response_selector.addItem(filename) # 加入 ComboBox
116+
# 自動顯示最新回覆
117+
self.response_selector.setCurrentText(filename)
118+
119+
120+
if __name__ == "__main__":
121+
app = QApplication(sys.argv)
122+
window = PromptSenderUI()
123+
window.show()
124+
sys.exit(app.exec())

automation_ide/automation_editor_ui/prompt_edit_gui/cot_code_review_prompt_templates/__init__.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/__init__.py

File renamed without changes.

automation_ide/automation_editor_ui/prompt_edit_gui/skills_prompt_templates/__init__.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/cot_code_review_prompt_templates/__init__.py

File renamed without changes.

automation_ide/automation_editor_ui/prompt_edit_gui/cot_code_review_prompt_templates/code_smell_detector.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/cot_code_review_prompt_templates/code_smell_detector.py

File renamed without changes.

automation_ide/automation_editor_ui/prompt_edit_gui/cot_code_review_prompt_templates/first_code_review.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/cot_code_review_prompt_templates/first_code_review.py

File renamed without changes.

automation_ide/automation_editor_ui/prompt_edit_gui/cot_code_review_prompt_templates/first_summary_prompt.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/cot_code_review_prompt_templates/first_summary_prompt.py

File renamed without changes.

automation_ide/automation_editor_ui/prompt_edit_gui/cot_code_review_prompt_templates/global_rule.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/cot_code_review_prompt_templates/global_rule.py

File renamed without changes.

automation_ide/automation_editor_ui/prompt_edit_gui/cot_code_review_prompt_templates/judge.py renamed to automation_ide/automation_editor_ui/extend_ai_gui/prompt_edit_gui/cot_code_review_prompt_templates/judge.py

File renamed without changes.

0 commit comments

Comments
 (0)