Skip to content
Merged

Dev #111

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
FIRST_CODE_REVIEW_TEMPLATE
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.first_summary_prompt import \
FIRST_SUMMARY_TEMPLATE
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.global_rule import \
GLOBAL_RULE_TEMPLATE
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.linter import \
LINTER_TEMPLATE
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.total_summary import \
Expand All @@ -16,7 +14,6 @@
CODE_REVIEW_SKILL_TEMPLATE

COT_TEMPLATE_FILES = [
"global_rule.md",
"first_summary_prompt.md",
"first_code_review.md",
"linter.md",
Expand All @@ -25,7 +22,6 @@
]

COT_TEMPLATE_RELATION = {
"global_rule.md": GLOBAL_RULE_TEMPLATE,
"first_summary_prompt.md": FIRST_SUMMARY_TEMPLATE,
"first_code_review.md": FIRST_CODE_REVIEW_TEMPLATE,
"linter.md": LINTER_TEMPLATE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import sys

# Worker Thread 負責傳送資料
import requests
from PySide6.QtCore import QThread, Signal
from PySide6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QHBoxLayout,
QPushButton, QTextEdit, QLabel, QLineEdit, QComboBox, QMessageBox
)
from je_editor import language_wrapper

from automation_ide.automation_editor_ui.extend_ai_gui.ai_gui_global_variable import COT_TEMPLATE_FILES, \
COT_TEMPLATE_RELATION
from automation_ide.automation_editor_ui.extend_ai_gui.ai_gui_global_variable import COT_TEMPLATE_RELATION
from automation_ide.automation_editor_ui.extend_ai_gui.prompt_edit_gui.cot_code_review_prompt_templates.global_rule import \
build_global_rule_template
from automation_ide.automation_editor_ui.extend_multi_language.update_language_dict import update_language_dict


# Worker Thread 負責傳送資料
class SenderThread(QThread):
update_response = Signal(str, str) # (filename, response)

Expand Down Expand Up @@ -86,80 +78,4 @@ def run(self):
reply_text = f"{language_wrapper.language_word_dict.get("cot_gui_error_sending")} {file} {e}"

# 發送訊號更新 UI
self.update_response.emit(file, reply_text)


class CoTCodeReviewGUI(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle(language_wrapper.language_word_dict.get("cot_gui_window_title"))

# 檔案清單
self.files = COT_TEMPLATE_FILES

# UI 元件
layout = QVBoxLayout()

# URL 輸入框
url_layout = QHBoxLayout()
url_layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_api_url")))
self.url_input = QLineEdit()
self.url_input.setPlaceholderText(language_wrapper.language_word_dict.get("cot_gui_placeholder_api_url"))
url_layout.addWidget(self.url_input)
layout.addLayout(url_layout)

# 傳送資料區域
self.code_paste_area = QTextEdit()
self.code_paste_area.setPlaceholderText(
language_wrapper.language_word_dict.get("cot_gui_placeholder_code_paste_area"))
layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_prompt_area")))
layout.addWidget(self.code_paste_area)

# 回傳區域
self.response_selector = QComboBox() # 改用 ComboBox
self.response_view = QTextEdit()
self.response_view.setReadOnly(True) # 可複製但不可編輯

hbox_layout = QHBoxLayout()
hbox_layout.addWidget(self.response_selector, 2)
hbox_layout.addWidget(self.response_view, 5)

layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_response_area")))
layout.addLayout(hbox_layout)

# 傳送按鈕
self.send_button = QPushButton(language_wrapper.language_word_dict.get("cot_gui_button_send"))
layout.addWidget(self.send_button)

self.setLayout(layout)

# 綁定事件
self.response_selector.currentTextChanged.connect(self.show_response)
self.send_button.clicked.connect(self.start_sending)

# 儲存回覆
self.responses = {}

def show_response(self, filename):
if filename in self.responses:
self.response_view.setPlainText(self.responses[filename])

def start_sending(self):
# 取得 URL
url = self.url_input.text().strip()
if not url:
message_box = QMessageBox()
message_box.warning(self, "Warning", language_wrapper.language_word_dict.get("cot_gui_error_no_url"))
message_box.exec_()
return

# 啟動傳送 Thread
self.thread = SenderThread(files=self.files, code=self.code_paste_area.toPlainText(), url=url)
self.thread.update_response.connect(self.handle_response)
self.thread.start()

def handle_response(self, filename, response):
self.responses[filename] = response
self.response_selector.addItem(filename) # 加入 ComboBox
# 自動顯示最新回覆
self.response_selector.setCurrentText(filename)
self.update_response.emit(file, reply_text)
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QTextEdit, QComboBox, QPushButton, \
QMessageBox
from je_editor import language_wrapper

from automation_ide.automation_editor_ui.extend_ai_gui.ai_gui_global_variable import COT_TEMPLATE_FILES
from automation_ide.automation_editor_ui.extend_ai_gui.code_review.code_review_thread import SenderThread


class CoTCodeReviewGUI(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle(language_wrapper.language_word_dict.get("cot_gui_window_title"))

# 檔案清單
self.files = COT_TEMPLATE_FILES

# UI 元件
layout = QVBoxLayout()

# URL 輸入框
url_layout = QHBoxLayout()
url_layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_api_url")))
self.url_input = QLineEdit()
self.url_input.setPlaceholderText(language_wrapper.language_word_dict.get("cot_gui_placeholder_api_url"))
url_layout.addWidget(self.url_input)
layout.addLayout(url_layout)

# 傳送資料區域
self.code_paste_area = QTextEdit()
self.code_paste_area.setPlaceholderText(
language_wrapper.language_word_dict.get("cot_gui_placeholder_code_paste_area"))
layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_prompt_area")))
layout.addWidget(self.code_paste_area)

# 回傳區域
self.response_selector = QComboBox() # 改用 ComboBox
self.response_view = QTextEdit()
self.response_view.setReadOnly(True) # 可複製但不可編輯

hbox_layout = QHBoxLayout()
hbox_layout.addWidget(self.response_selector, 2)
hbox_layout.addWidget(self.response_view, 5)

layout.addWidget(QLabel(language_wrapper.language_word_dict.get("cot_gui_label_response_area")))
layout.addLayout(hbox_layout)

# 傳送按鈕
self.send_button = QPushButton(language_wrapper.language_word_dict.get("cot_gui_button_send"))
layout.addWidget(self.send_button)

self.setLayout(layout)

# 綁定事件
self.response_selector.currentTextChanged.connect(self.show_response)
self.send_button.clicked.connect(self.start_sending)

# 儲存回覆
self.responses = {}

def show_response(self, filename):
if filename in self.responses:
self.response_view.setPlainText(self.responses[filename])

def start_sending(self):
# 取得 URL
url = self.url_input.text().strip()
if not url:
message_box = QMessageBox()
message_box.warning(self, "Warning", language_wrapper.language_word_dict.get("cot_gui_error_no_url"))
message_box.exec_()
return

# 啟動傳送 Thread
self.thread = SenderThread(files=self.files, code=self.code_paste_area.toPlainText(), url=url)
self.thread.update_response.connect(self.handle_response)
self.thread.start()

def handle_response(self, filename, response):
self.responses[filename] = response
self.response_selector.addItem(filename) # 加入 ComboBox
# 自動顯示最新回覆
self.response_selector.setCurrentText(filename)
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
JUDGE_TEMPLATE = """
# Code Review Comment Evaluation Template (Enhanced)

Please evaluate the review comments focusing on how well they address important issues in the code, especially leveraging code smell and linter messages.
The input may contain multiple independent review reports.

Score range: 1–100

Five evaluation dimensions:
### 1. Readability
- 1–20: Comments are very hard to understand, poorly structured, confusing language.
- 21–40: Some parts are readable, but many unclear sections remain.
- 41–60: Comments are generally clear, but structure or phrasing needs improvement.
- 61–80: Comments are well-structured, consistent, and easy to follow.
- 81–100: Comments are highly readable, elegantly phrased, and well-organized.

### 2. Constructiveness (Maintainability)
- 1–20: Comments lack constructive suggestions, no improvement direction.
- 21–40: Comments provide partial suggestions, but vague or impractical.
- 41–60: Comments offer basic improvement ideas, somewhat helpful.
- 61–80: Comments are specific and actionable, clearly guiding improvements.
- 81–100: Comments are highly constructive, offering clear and practical improvement paths.

### 3. Correctness
- 1–20: Comments contain errors or misleading advice.
- 21–40: Mostly correct, but important issues are overlooked.
- 41–60: Largely correct, with only minor gaps.
- 61–80: Correct and reasonable, with small room for refinement.
- 81–100: Fully correct, logically sound, and precise in identifying issues.

### 4. Multi-Review Coverage, Structural Independence & Extractability

> Evaluate how well the comments cover important issues across multiple review reports, and whether each comment block is structurally independent, self-contained, and understandable on its own.

#### Scoring Criteria

- **1–20**
Rarely addresses important issues; structure is disorganized; comments heavily depend on surrounding context; blocks cannot be read independently; unclear linkage to specific code smells or linter messages.

- **21–40**
Addresses some issues but misses many key points; unclear boundaries between sections; frequent cross-references required for understanding; difficult to isolate specific issue blocks.

- **41–60**
Covers many important issues; basic structure is present; some blocks can be read independently, but certain sections still rely on context or lack completeness.

- **61–80**
Most key issues are addressed; comment blocks are clearly structured with defined themes; most sections can be independently read and understood (problem + reasoning + suggestion); code smell / linter-related blocks are reasonably extractable.

- **81–100**
Thoroughly addresses key issues; each comment block is **independent, complete, and self-contained** (including problem description, impact explanation, and actionable improvement suggestions);
clearly segmented structure; any block can be extracted without losing meaning;
strongly aligned with specific code smells or linter messages; highly readable and maintainable.
---
### Additional Evaluation Criteria

When scoring this dimension, explicitly check whether each comment block:
- Has a clear title or thematic focus
- Clearly identifies the issue source (e.g., specific code smell or linter message)
- Explains impact or risk
- Provides concrete and actionable improvement suggestions
- Does not rely on other sections for comprehension

Also assess whether:
- A single comment block can be extracted and shared independently without losing clarity
- Code smell or linter-related sections can be isolated for structured analysis
- Summary sections and detailed comments are clearly distinguished

### 5. Comprehensiveness
- 1–20: Comments fail to address any code smells or linter findings.
- 21–40: Comments mention at least one code smell or linter warning.
- 41–60: Comments cover some code smells or linter findings.
- 61–80: Comments cover most code smells and linter findings.
- 81–100: Comments comprehensively address all code smells and linter findings, with improvement suggestions.

Reviewers should:
- Assign a score (1–100) for each dimension.
- Provide brief reasoning for each score.
- Conclude with an average score and overall recommendation.

## Review Comment:
{review_comment}

## Code Smells:
{code_smell_detector_messages}

## Linter Messages:
{linter_messages}

## Origin code
{code_diff}
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
JUDGE_SINGLE_REVIEW_TEMPLATE = """
# Code Review Comment Evaluation Template (Enhanced)

Please evaluate the review comments focusing on how well they address important issues in the code, especially leveraging code smell and linter messages.
The input may contain multiple independent review reports.

Score range: 1–100

Five evaluation dimensions:
### 1. Readability
- 1–20: Comments are very hard to understand, poorly structured, confusing language.
- 21–40: Some parts are readable, but many unclear sections remain.
- 41–60: Comments are generally clear, but structure or phrasing needs improvement.
- 61–80: Comments are well-structured, consistent, and easy to follow.
- 81–100: Comments are highly readable, elegantly phrased, and well-organized.

### 2. Constructiveness (Maintainability)
- 1–20: Comments lack constructive suggestions, no improvement direction.
- 21–40: Comments provide partial suggestions, but vague or impractical.
- 41–60: Comments offer basic improvement ideas, somewhat helpful.
- 61–80: Comments are specific and actionable, clearly guiding improvements.
- 81–100: Comments are highly constructive, offering clear and practical improvement paths.

### 3. Correctness
- 1–20: Comments contain errors or misleading advice.
- 21–40: Mostly correct, but important issues are overlooked.
- 41–60: Largely correct, with only minor gaps.
- 61–80: Correct and reasonable, with small room for refinement.
- 81–100: Fully correct, logically sound, and precise in identifying issues.

### 4. Multi-Review Coverage, Structural Independence & Extractability

> Evaluate how well the comments cover important issues across multiple review reports, and whether each comment block is structurally independent, self-contained, and understandable on its own.

#### Scoring Criteria

- **1–20**
Rarely addresses important issues; structure is disorganized; comments heavily depend on surrounding context; blocks cannot be read independently; unclear linkage to specific code smells or linter messages.

- **21–40**
Addresses some issues but misses many key points; unclear boundaries between sections; frequent cross-references required for understanding; difficult to isolate specific issue blocks.

- **41–60**
Covers many important issues; basic structure is present; some blocks can be read independently, but certain sections still rely on context or lack completeness.

- **61–80**
Most key issues are addressed; comment blocks are clearly structured with defined themes; most sections can be independently read and understood (problem + reasoning + suggestion); code smell / linter-related blocks are reasonably extractable.

- **81–100**
Thoroughly addresses key issues; each comment block is **independent, complete, and self-contained** (including problem description, impact explanation, and actionable improvement suggestions);
clearly segmented structure; any block can be extracted without losing meaning;
strongly aligned with specific code smells or linter messages; highly readable and maintainable.
---
### Additional Evaluation Criteria

When scoring this dimension, explicitly check whether each comment block:
- Has a clear title or thematic focus
- Clearly identifies the issue source (e.g., specific code smell or linter message)
- Explains impact or risk
- Provides concrete and actionable improvement suggestions
- Does not rely on other sections for comprehension

Also assess whether:
- A single comment block can be extracted and shared independently without losing clarity
- Code smell or linter-related sections can be isolated for structured analysis
- Summary sections and detailed comments are clearly distinguished

### 5. Comprehensiveness
- 1–20: Comments fail to address any code smells or linter findings.
- 21–40: Comments mention at least one code smell or linter warning.
- 41–60: Comments cover some code smells or linter findings.
- 61–80: Comments cover most code smells and linter findings.
- 81–100: Comments comprehensively address all code smells and linter findings, with improvement suggestions.

Reviewers should:
- Assign a score (1–100) for each dimension.
- Provide brief reasoning for each score.
- Conclude with an average score and overall recommendation.

## Review Comment:
{review_comment}

## Origin code
{code_diff}
"""
Loading
Loading