def find_ollama_executable():
if os.name == 'nt': # Windows
direct_path = "C:\Users\Admin\AppData\Local\Programs\Ollama\ollama.exe"
if os.path.exists(direct_path):
return direct_path
def create_table(self):
with self.conn:
self.conn.execute('''
CREATE TABLE IF NOT EXISTS context (
id INTEGER PRIMARY KEY AUTOINCREMENT,
sender TEXT NOT NULL,
message TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
''')
def add_message(self, sender, message):
with self.conn:
self.conn.execute("INSERT INTO context (sender, message) VALUES (?, ?)", (sender, message))
self.ensure_context_limit()
def get_context(self, max_length=None):
if max_length is None:
max_length = self.max_context_length
cursor = self.conn.cursor()
cursor.execute("SELECT sender, message FROM context ORDER BY id DESC")
rows = cursor.fetchall()
context = []
current_length = 0
for row in reversed(rows):
msg = f"{row[0]}: {row[1]}"
msg_length = len(msg)
if current_length + msg_length > max_length:
break
context.insert(0, msg)
current_length += msg_length
return "\n".join(context)
def clear_context(self):
with self.conn:
self.conn.execute("DELETE FROM context")
def ensure_context_limit(self):
cursor = self.conn.cursor()
cursor.execute("SELECT SUM(LENGTH(message)) FROM context")
total_length = cursor.fetchone()[0] or 0
if total_length > self.max_context_length:
cursor.execute("DELETE FROM context WHERE id IN (SELECT id FROM context ORDER BY id ASC LIMIT 100)")
self.conn.commit()
def close_connection(self):
if self.conn:
self.conn.close()
Assistant
TaskWidget for visual representation of tasks
class TaskWidget(QWidget):
def init(self, task_name, goal, status="Pending"):
super().init()
self.task_name = task_name
self.goal = goal
self.status = status
self.dependencies = [] # List of task names this task depends on
self.init_ui()
def init_ui(self):
layout = QVBoxLayout()
self.name_label = QLabel(f"Task: {self.task_name}")
self.goal_label = QLabel(f"Goal: {self.goal}")
self.status_label = QLabel(f"Status: {self.status}")
layout.addWidget(self.name_label)
layout.addWidget(self.goal_label)
layout.addWidget(self.status_label)
self.setLayout(layout)
def set_status(self, status):
self.status = status
self.status_label.setText(f"Status: {self.status}")
self.update()
def add_dependency(self, task_name):
if task_name not in self.dependencies:
self.dependencies.append(task_name)
def highlightBlock(self, text):
for pattern, format in self.highlightingRules:
match_iterator = pattern.globalMatch(text)
while match_iterator.hasNext():
match = match_iterator.next()
self.setFormat(match.capturedStart(), match.capturedLength(), format)
def __init__(self, ollama_controller, context_manager):
super().__init__()
self.ollama = ollama_controller
self.context_manager = context_manager
self.tasks = {} # task_name: TaskWidget
self.task_queue = []
self.completed_tasks = []
self.failed_tasks = []
self.current_task = None
self.total_tasks = 0
self.completed_count = 0
self.finalizing = False
self.ollama.response_received.connect(self.handle_response)
self.ollama.error_occurred.connect(self.on_error)
def add_task(self, user_request):
try:
planning_prompt = (
"Please create a detailed plan to break down the following request into meaningful subtasks. "
"Each subtask should be a clear, independent step that can be completed in one go. "
"Return the steps in a numbered list format with a summary at the end. Use '__END__' to mark the end of the response."
"\n\n"
f"Request: {user_request}"
)
self.current_user_request = user_request
# Assuming planning uses the Planning LLM
self.ollama.set_selected_llm(self.get_planning_llm())
self.ollama.send_request("/api/generate", {
"model": self.get_planning_llm(),
"prompt": planning_prompt,
"options": {
"temperature": 0.5,
"max_new_tokens": 1500,
"stream": True, # Enable streaming for planning
"format": "json"
}
})
self.total_tasks = 0
self.completed_count = 0
self.task_queue.clear()
self.completed_tasks.clear()
self.failed_tasks.clear()
self.current_task = None
self.finalizing = False
self.progress_updated.emit(self.completed_count, self.total_tasks)
except requests.exceptions.RequestException as e:
self.message_sent.emit("System", f"Error creating plan: {e}", "error")
logging.error(f"Error creating plan: {e}")
def handle_response(self, response):
if self.finalizing:
if "response" in response:
final_answer = response["response"]
if "__END__" in final_answer:
final_answer = final_answer.replace("__END__", "")
self.final_answer_ready.emit(final_answer)
return
if self.current_task:
# Handling subtask response
if "response" in response:
result = response["response"].strip()
self.append_subtask_result(result)
else:
# Handling planning response
if "response" in response:
chunk = response["response"]
if "__END__" in chunk:
chunk = chunk.replace("__END__", "")
steps, summary = self.parse_planning(chunk)
if steps:
self.task_queue.extend(steps)
self.total_tasks += len(steps)
self.progress_updated.emit(self.completed_count, self.total_tasks)
self.process_next_task()
if summary:
self.context_manager.add_message("System", f"Summary: {summary}")
elif "__CONTINUE__" in chunk:
# Await more chunks
pass
else:
steps, summary = self.parse_planning(chunk)
if steps:
self.task_queue.extend(steps)
self.total_tasks += len(steps)
self.progress_updated.emit(self.completed_count, self.total_tasks)
self.process_next_task()
if summary:
self.context_manager.add_message("System", f"Summary: {summary}")
else:
self.task_failed.emit("No response from LLM.")
def parse_planning(self, planning_text):
"""
Parses the planning response to extract subtasks and summary.
Expects a numbered list of subtasks followed by a summary.
"""
steps = re.findall(r'^\d+\.\s+(.*)', planning_text, re.MULTILINE)
summary_match = re.search(r'Summary:\s*(.*)', planning_text, re.IGNORECASE)
summary = summary_match.group(1).strip() if summary_match else ""
return steps, summary
def process_next_task(self):
if self.current_task is not None:
return
if not self.task_queue:
if not self.finalizing:
self.finalize()
return
self.current_task = self.task_queue.pop(0)
subtask = self.current_task
task_prompt = (
f"Please execute the following task in one step and provide the result. "
f"Use '__END__' to mark the end of your response.\n\n{subtask}\n\nResult:"
)
# Reset context for subtask processing
self.context_manager.clear_context()
self.context_manager.add_message("System", f"Executing subtask: {subtask}")
# Assuming processing uses the Processing LLM
self.ollama.set_selected_llm(self.get_processing_llm())
self.ollama.send_request("/api/generate", {
"model": self.get_processing_llm(),
"prompt": task_prompt,
"options": {
"temperature": 0.5,
"max_new_tokens": 1500,
"stream": False, # No streaming for subtasks
"format": "json"
}
})
self.start_typing_animation()
def append_subtask_result(self, result):
"""
Append the result of a subtask, verify goals, and save if appropriate.
"""
# Append result to completed tasks
self.completed_tasks.append(self.current_task)
self.message_sent.emit("System", f"Task '{self.current_task}' completed with result: {result}", "info")
self.completed_count += 1
self.progress_updated.emit(self.completed_count, self.total_tasks)
self.current_task = None
self.process_next_task()
def finalize(self):
if self.finalizing:
return
self.finalizing = True
results = "\n".join([f"{i+1}. {task}" for i, task in enumerate(self.completed_tasks)])
verification_prompt = (
f"Please verify that the following tasks have achieved all their goals. "
f"Respond with 'Ok to save' if all goals are met, or provide detailed feedback otherwise."
f"\n\nTasks:\n{results}"
f"\n\nVerification Result:"
)
# Assuming verification uses the Final Answer LLM
self.ollama.set_selected_llm(self.get_final_llm())
self.ollama.send_request("/api/generate", {
"model": self.get_final_llm(),
"prompt": verification_prompt,
"options": {
"temperature": 0.3,
"max_new_tokens": 500,
"stream": False, # No streaming for verification
"format": "json"
}
})
self.start_typing_animation()
def save_summaries(self):
# Summarize the results
summary_prompt = (
f"Please summarize the results of the following tasks without losing critical information:\n\n"
f"{chr(10).join([f'Task {i+1}: {task}' for i, task in enumerate(self.completed_tasks)])}\n\nSummary:"
)
# Assuming summarization uses the Final Answer LLM
self.ollama.set_selected_llm(self.get_final_llm())
self.ollama.send_request("/api/generate", {
"model": self.get_final_llm(),
"prompt": summary_prompt,
"options": {
"temperature": 0.5,
"max_new_tokens": 1000,
"stream": False, # No streaming for summarization
"format": "json"
}
})
self.start_typing_animation()
def handle_verification_response(self, response):
if "response" in response:
verification_result = response["response"].strip()
if verification_result.lower() == "ok to save":
# Proceed to save summarized results
self.save_summaries()
else:
self.task_failed.emit(f"Verification failed: {verification_result}")
else:
self.task_failed.emit("No verification response from LLM.")
self.stop_typing_animation()
def handle_summarization_response(self, response):
if "response" in response:
summary = response["response"].strip()
if summary:
self.context_manager.add_message("System", f"Summary: {summary}")
self.message_sent.emit("System", "Ok to save", "info")
self.final_answer_ready.emit("All tasks verified and summaries saved.")
else:
self.task_failed.emit("No summarization response from LLM.")
self.stop_typing_animation()
def on_error(self, error_message):
if self.finalizing:
# Handle verification or summarization errors
if "save" in error_message.lower():
self.task_failed.emit(f"Error during saving summaries: {error_message}")
elif self.current_task:
self.failed_tasks.append(self.current_task)
self.completed_count += 1
self.progress_updated.emit(self.completed_count, self.total_tasks)
self.task_failed.emit(f"Error in task '{self.current_task}': {error_message}")
self.current_task = None
self.process_next_task()
else:
self.task_failed.emit(f"Error: {error_message}")
def interrupt_processing(self):
try:
self.ollama.interrupt_event.set()
self.message_sent.emit("System", "LLM processing has been interrupted.", "warning")
logging.info("LLM processing has been interrupted.")
except Exception as e:
self.message_sent.emit("System", f"Error interrupting process: {e}", "error")
logging.error(f"Error interrupting process: {e}")
# Helper methods to get selected LLMs
def get_planning_llm(self):
return self.planning_llm_combo.currentText()
def get_processing_llm(self):
return self.processing_llm_combo.currentText()
def get_final_llm(self):
return self.final_llm_combo.currentText()
Context Manager
class ContextManager(QObject):
summarization_requested = pyqtSignal(str)
def __init__(self, ollama_controller):
super().__init__()
self.db = DatabaseManager()
self.summary = ""
self.ollama = ollama_controller
self.ollama.summarization_received.connect(self.handle_summarization_response)
self.summarization_requested.connect(self.summarize_context)
self.summarize_request_event = threading.Event()
self.summarization_result = ""
self.lock = threading.Lock()
def add_message(self, sender, message):
self.db.add_message(sender, message)
self.check_and_summarize_context()
def get_context(self):
with self.lock:
if self.summary:
return self.summary + "\n" + self.db.get_context()
return self.db.get_context()
def clear_context(self):
self.db.clear_context()
with self.lock:
self.summary = ""
def check_and_summarize_context(self):
context = self.db.get_context()
if len(context) > self.db.max_context_length * 0.8:
self.summarization_requested.emit(context)
def summarize_context(self, context_text):
summary_prompt = (
"Please summarize the following context to make room for new information. "
"Keep all important details and key points:\n\n"
f"{context_text}"
)
self.summarization_result = ""
self.summarize_request_event.clear()
self.ollama.send_request("/api/generate", {
"model": self.ollama.selected_llm,
"prompt": summary_prompt,
"options": {
"temperature": 0.5,
"max_new_tokens": 1000,
"stream": False,
"format": "json"
}
})
threading.Thread(target=self.wait_for_summary, daemon=True).start()
def wait_for_summary(self):
if self.summarize_request_event.wait(timeout=60):
if self.summarization_result:
with self.lock:
self.summary = self.summarization_result
self.db.clear_context()
self.db.add_message("System", f"Summary of previous context:\n{self.summary}")
else:
logging.error("Timeout during context summarization.")
self.summarize_request_event.set()
def handle_summarization_response(self, response):
if "response" in response:
summary = response["response"].strip()
if summary:
with self.lock:
self.summarization_result = summary
else:
logging.error("No response received for summarization.")
self.summarize_request_event.set()
Settings Dialog
class SettingsDialog(QDialog):
settings_updated = pyqtSignal(dict)
Connection Widget to draw lines between tasks based on dependencies
class ConnectionWidget(QWidget):
def init(self, task_widgets):
super().init()
self.task_widgets = task_widgets # Dictionary mapping task_name to TaskWidget
self.setMinimumWidth(400) # Adjust as needed
def update_connections(self):
self.update() # Trigger paintEvent
def paintEvent(self, event):
painter = QPainter(self)
pen = QPen(QColor("white"), 2, Qt.SolidLine)
painter.setPen(pen)
# Example: Traverse through all tasks and draw lines from dependencies
for task_name, widget in self.task_widgets.items():
for dep in widget.dependencies:
if dep in self.task_widgets:
start_widget = self.task_widgets[dep]
end_widget = widget
# Calculate positions relative to the ConnectionWidget
parent_widget = self.parent()
if parent_widget:
# Map widget positions to the coordinate system of the ConnectionWidget
start_pos = parent_widget.mapTo(self, start_widget.pos()) + start_widget.rect().bottomRight()
end_pos = parent_widget.mapTo(self, end_widget.pos()) + end_widget.rect().topLeft()
painter.drawLine(start_pos, end_pos)
painter.end()
AutoLLM App
class AutoLLMApp(QWidget):
loading_signal = pyqtSignal(bool) # Loading signal for process indication
def __init__(self):
super().__init__()
self.setWindowTitle("AutoLLM")
self.resize(1600, 1000) # Larger window size for better overview
self.ollama = OllamaController()
self.context_manager = ContextManager(self.ollama)
self.current_parameters = {"temperature": 0.5, "max_new_tokens": 1500, "additional_options": {}}
# Initialize UI
self.init_ui()
self.ollama.start_server()
self.enable_ui(False)
# Task Manager
self.task_manager = TaskManager(self.ollama, self.context_manager)
self.task_manager.task_completed.connect(self.on_task_completed_step)
self.task_manager.task_failed.connect(self.on_task_failed_step)
self.task_manager.progress_updated.connect(self.update_progress)
self.task_manager.final_answer_ready.connect(self.display_final_answer)
self.task_manager.message_sent.connect(self.display_message)
self.ollama.server_status_changed.connect(self.update_server_status)
self.ollama.error_occurred.connect(self.show_error)
self.ollama.llm_list_updated.connect(self.update_llm_list)
# Initialize Code Highlighter
self.highlighter = CodeHighlighter(self.chat_area.document())
# For blinking "..."
self.blink_timer = QTimer()
self.blink_timer.timeout.connect(self.toggle_ellipsis)
self.ellipsis_visible = True
# Connect message_sent signal
self.task_manager.message_sent.connect(self.display_message)
def init_ui(self):
main_layout = QHBoxLayout()
left_layout = QVBoxLayout()
# Chat area with scrollbar using QTextEdit for HTML support
self.chat_area = QTextEdit()
self.chat_area.setReadOnly(True)
self.chat_area.setFont(QFont("Courier", 10))
self.chat_area.setStyleSheet("""
QTextEdit {
background-color: #2b2b2b;
color: #ffffff;
border: 1px solid #5c5c5c;
padding: 5px;
}
""")
chat_scroll_area = QScrollArea()
chat_scroll_area.setWidgetResizable(True)
chat_scroll_area.setWidget(self.chat_area)
left_layout.addWidget(chat_scroll_area)
# Input field and send button
input_layout = QHBoxLayout()
self.input_field = QLineEdit()
self.input_field.setPlaceholderText("Enter your message here...")
self.input_field.returnPressed.connect(self.send_message)
self.send_button = QPushButton("Send")
self.send_button.clicked.connect(self.send_message)
input_layout.addWidget(self.input_field)
input_layout.addWidget(self.send_button)
left_layout.addLayout(input_layout)
# Interrupt button
self.interrupt_button = QPushButton("Interrupt")
self.interrupt_button.clicked.connect(self.interrupt_processing)
left_layout.addWidget(self.interrupt_button)
# Server monitoring area
server_layout = QHBoxLayout()
self.server_status = QLabel("🔴 Server Stopped")
self.server_button = QPushButton("Start Server")
self.server_button.clicked.connect(self.toggle_server)
server_layout.addWidget(self.server_status)
server_layout.addWidget(self.server_button)
left_layout.addLayout(server_layout)
# LLM selection for Planning, Processing, and Final Answer
llm_selection_layout = QFormLayout()
self.planning_llm_combo = QComboBox()
self.planning_llm_combo.setEnabled(False)
self.planning_llm_combo.setToolTip("Select LLM for Planning")
llm_selection_layout.addRow("Planning LLM:", self.planning_llm_combo)
self.processing_llm_combo = QComboBox()
self.processing_llm_combo.setEnabled(False)
self.processing_llm_combo.setToolTip("Select LLM for Processing Subtasks")
llm_selection_layout.addRow("Processing LLM:", self.processing_llm_combo)
self.final_llm_combo = QComboBox()
self.final_llm_combo.setEnabled(False)
self.final_llm_combo.setToolTip("Select LLM for Final Answer")
llm_selection_layout.addRow("Final Answer LLM:", self.final_llm_combo)
left_layout.addLayout(llm_selection_layout)
# Settings button
self.settings_button = QPushButton("Settings")
self.settings_button.clicked.connect(self.open_settings)
left_layout.addWidget(self.settings_button)
# Progress area
progress_layout = QVBoxLayout()
self.progress_bar_planning = QProgressBar()
self.progress_bar_planning.setValue(0)
self.progress_label_planning = QLabel("Planning Progress:")
self.progress_bar_processing = QProgressBar()
self.progress_bar_processing.setValue(0)
self.progress_label_processing = QLabel("Processing Progress:")
progress_layout.addWidget(self.progress_label_planning)
progress_layout.addWidget(self.progress_bar_planning)
progress_layout.addWidget(self.progress_label_processing)
progress_layout.addWidget(self.progress_bar_processing)
left_layout.addLayout(progress_layout)
# Plan and steps area with TaskWidget
self.task_area = QVBoxLayout()
self.task_area.setSpacing(10)
self.task_area.setContentsMargins(10, 10, 10, 10)
self.task_widgets = {} # Mapping from task_name to TaskWidget
self.task_scroll_area = QScrollArea()
self.task_scroll_area.setWidgetResizable(True)
task_container = QWidget()
task_container.setLayout(self.task_area)
self.task_scroll_area.setWidget(task_container)
left_layout.addWidget(self.task_scroll_area)
main_layout.addLayout(left_layout, 3)
# Right layout for visual connections between tasks
right_layout = QVBoxLayout()
self.connection_widget = ConnectionWidget(self.task_widgets)
self.connection_widget.setMinimumWidth(400)
right_layout.addWidget(self.connection_widget)
main_layout.addLayout(right_layout, 1)
# Add loading indicator to the main layout
self.loading_indicator = QLabel("Loading...")
self.loading_indicator.setVisible(False) # Initially hidden
self.loading_indicator.setStyleSheet("color: yellow; font-weight: bold;")
main_layout.addWidget(self.loading_indicator)
self.setLayout(main_layout)
def classify_message(self, message):
"""
Determine if the message is simple or requires planning.
Returns 'simple' or 'complex'.
"""
# Simple heuristic: if message length is short or contains certain keywords
simple_keywords = ['hello', 'hi', 'whats up', 'how are you', 'bye']
if len(message) < 20:
for keyword in simple_keywords:
if keyword.lower() in message.lower():
return 'simple'
return 'complex'
def send_message(self):
user_message = self.input_field.text().strip()
if user_message:
self.context_manager.add_message("User", user_message)
self.append_message("User", user_message)
self.input_field.clear()
message_type = self.classify_message(user_message)
if message_type == 'simple':
self.handle_simple_message(user_message)
else:
self.task_manager.add_task(user_message)
self.start_typing_animation() # Start loading indicator
def handle_simple_message(self, message):
"""
Handle simple user messages with direct LLM response.
"""
direct_prompt = (
f"Respond to the user's message in a clear and concise manner.\n\nUser: {message}\n\nResponse:"
)
# Assuming simple messages use the Processing LLM
self.ollama.set_selected_llm(self.get_processing_llm())
self.ollama.send_request("/api/generate", {
"model": self.get_processing_llm(),
"prompt": direct_prompt,
"options": {
"temperature": 0.5,
"max_new_tokens": 500,
"stream": False, # No streaming for simple messages
"format": "json"
}
})
self.start_typing_animation() # Start loading indicator
self.ollama.response_received.connect(self.handle_simple_response)
def handle_simple_response(self, response):
if "response" in response:
reply = response["response"].strip()
self.append_message("LLM", reply)
else:
self.append_message("System", "No response from LLM.", message_type="error")
self.stop_typing_animation() # Stop loading indicator
# Disconnect to prevent multiple connections
self.ollama.response_received.disconnect(self.handle_simple_response)
def append_message(self, sender, message, message_type="normal"):
color = "gray"
if sender == "User":
color = "#00ccff" # Change color for better visibility
prefix = "<b>User:</b> "
elif sender == "LLM":
color = "green"
prefix = "<b>LLM:</b> "
else:
prefix = "<b>System:</b> "
formatted_message = self.format_message(message)
html_message = f'<p style="color: {color};">{prefix}{formatted_message}</p>'
self.chat_area.insertHtml(html_message + "<br>")
self.chat_area.moveCursor(QTextCursor.End)
def format_message(self, message):
message = re.sub(r'(https?://\S+)', r'<a href="\1">\1</a>', message)
message = re.sub(
r'```(.*?)```',
r'<pre style="background-color:#f0f0f0; padding:5px; font-family: monospace; white-space: pre-wrap;"><code>\1</code></pre>',
message,
flags=re.DOTALL | re.MULTILINE
)
return message
def display_message(self, sender, message, message_type="normal"):
self.append_message(sender, message, message_type)
def interrupt_processing(self):
self.task_manager.interrupt_processing()
self.display_message("System", "LLM processing has been interrupted.", "warning")
self.stop_typing_animation() # Stop loading animation on interrupt
def toggle_server(self):
if self.ollama.is_server_running():
reply = QMessageBox.question(self, 'Stop Server',
'Are you sure you want to stop the Ollama server?',
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
self.ollama.stop_server()
else:
self.ollama.start_server()
def open_settings(self):
settings_dialog = SettingsDialog(self.current_parameters, self)
settings_dialog.settings_updated.connect(self.update_parameters)
settings_dialog.exec_()
def update_parameters(self, params):
self.current_parameters = params
QMessageBox.information(self, "Settings Updated", "LLM parameters have been updated.")
def on_task_completed_step(self, result):
self.append_message("LLM", f"Result: {result}")
self.task_manager.completed_tasks.append(self.task_manager.current_task)
self.task_manager.completed_count += 1
self.update_progress(self.task_manager.completed_count, self.task_manager.total_tasks)
self.task_manager.current_task = None
self.task_manager.process_next_task()
self.stop_typing_animation() # Stop loading indicator
self.update_plan_list()
def on_task_failed_step(self, error):
self.append_message("System", f"Error: {error}", message_type="error")
self.task_manager.failed_tasks.append(self.task_manager.current_task)
self.task_manager.completed_count += 1
self.update_progress(self.task_manager.completed_count, self.task_manager.total_tasks)
self.task_manager.current_task = None
self.task_manager.process_next_task()
self.stop_typing_animation() # Stop loading indicator
self.update_plan_list()
def update_progress(self, completed, total):
if total == 0:
self.progress_bar_planning.setValue(0)
self.progress_bar_processing.setValue(0)
else:
planning_progress = int((completed / total) * 100)
processing_progress = planning_progress # Adjust as needed
self.progress_bar_planning.setValue(planning_progress)
self.progress_bar_processing.setValue(processing_progress)
self.connection_widget.update_connections()
def update_plan_list(self):
self.clear_task_area()
# Display completed tasks
for task in self.task_manager.completed_tasks:
widget = TaskWidget(task, goal="Completed", status="Completed")
self.task_area.addWidget(widget)
self.task_widgets[task] = widget
# Display current task
if self.task_manager.current_task:
widget = TaskWidget(self.task_manager.current_task, goal="In Progress", status="Processing")
self.task_area.addWidget(widget)
self.task_widgets[self.task_manager.current_task] = widget
# Display queued tasks
for task in self.task_manager.task_queue:
widget = TaskWidget(task, goal="Planned", status="Pending")
self.task_area.addWidget(widget)
self.task_widgets[task] = widget
# Display failed tasks
for task in self.task_manager.failed_tasks:
widget = TaskWidget(task, goal="Failed", status="Error")
self.task_area.addWidget(widget)
self.task_widgets[task] = widget
# Update connections
self.connection_widget.update_connections()
def clear_task_area(self):
while self.task_area.count():
child = self.task_area.takeAt(0)
if child.widget():
child.widget().deleteLater()
def display_final_answer(self, answer):
self.append_message("LLM", f"Final Answer: {answer}")
self.stop_typing_animation() # Stop loading indicator
# Helper methods to get selected LLMs
def get_planning_llm(self):
return self.planning_llm_combo.currentText()
def get_processing_llm(self):
return self.processing_llm_combo.currentText()
def get_final_llm(self):
return self.final_llm_combo.currentText()
Connection Widget to draw lines between tasks based on dependencies
class ConnectionWidget(QWidget):
def init(self, task_widgets):
super().init()
self.task_widgets = task_widgets # Dictionary mapping task_name to TaskWidget
self.setMinimumWidth(400) # Adjust as needed
def update_connections(self):
self.update() # Trigger paintEvent
def paintEvent(self, event):
painter = QPainter(self)
pen = QPen(QColor("white"), 2, Qt.SolidLine)
painter.setPen(pen)
# Example: Traverse through all tasks and draw lines from dependencies
for task_name, widget in self.task_widgets.items():
for dep in widget.dependencies:
if dep in self.task_widgets:
start_widget = self.task_widgets[dep]
end_widget = widget
# Calculate positions relative to the ConnectionWidget
parent_widget = self.parent()
if parent_widget:
# Map widget positions to the coordinate system of the ConnectionWidget
start_pos = parent_widget.mapTo(self, start_widget.pos()) + start_widget.rect().bottomRight()
end_pos = parent_widget.mapTo(self, end_widget.pos()) + end_widget.rect().topLeft()
painter.drawLine(start_pos, end_pos)
painter.end()
Die AutoLLM-Anwendung ist ein umfassendes Werkzeug zur Verwaltung und Interaktion mit Maschinenlernmodellen, das sowohl eine ansprechende Benutzeroberfläche als auch leistungsstarke Funktionen bietet. Jedoch gibt es einige Aspekte, die verbessert werden können.
Stärken:
Benutzerfreundliche Oberfläche:
Die Oberfläche ist übersichtlich und intuitiv gestaltet. Die Verwendung von QVBoxLayouts und QHBoxLayouts sorgt dafür, dass alle Elemente übersichtlich angeordnet sind.
Der Einsatz von Farben zur Unterscheidung zwischen verschiedenen Benutzern und Nachrichten ist eine positive Designentscheidung.
Funktionsumfang:
Die Anwendung bietet eine Vielzahl von Funktionen, darunter das Hinzufügen von Aufgaben, die Bearbeitung und Überwachung der Aufgaben sowie die Verwendung von LLM für Planung, Verarbeitung und Verifizierung. Dies zeigt, dass die Anwendung gut für das Management von komplexen Anfragen konzipiert ist.
Die Möglichkeit, Aufgaben zu priorisieren und den Status der Aufgaben zu visualisieren, ist besonders nützlich.
Echtzeitanzeige:
Die Verwendung von QTextEdit zur Anzeige der Konversation in Echtzeit ist ein effektives Mittel, um Benutzerinteraktionen dynamisch darzustellen. Auch Funktionen wie das Scrollen und die Unterstützung für Links und Codeformatierungen erhöhen die Benutzerfreundlichkeit.
Schwächen:
Fehlende Fehlerbehandlung:
Während einige der Klassen wie OllamaController über Ansätze zur Fehlerüberprüfung verfügen, gibt es immer noch Bereiche, in denen die Fehlerbehandlung verbessert werden könnte. Insbesondere bei der Verwendung von Netzwerkfunktionen sollte die Anwendung robuster gegen Ausfälle und Netzwerkprobleme sein.
Eine zentrale Fehlerbehandlungsroutine könnte dazu beitragen, konsistentere Rückmeldungen an den Benutzer zu geben.
Performance-Optimierung:
Der Code führt mehrere Threads und Netzwerkaufrufe durch, was zu Verlangsamungen führen kann, insbesondere bei langsamen Netzwerkverbindungen. Die Implementierung von asynchronen Aufrufen oder einer besseren Verwaltung von Threads könnte die Leistung der Anwendung erheblich verbessern.
Es sollte darauf geachtet werden, dass beim Abrufen und Verarbeiten großer Datenmengen die Hauptanwendung nicht blockiert wird.
Dokumentation und Kommentare:
Während der Code einige Erklärungen enthält, könnte die Dokumentation insgesamt verbessert werden. Gute Dokumentation ist für die Wartung des Codes und für andere Entwickler, die am Projekt arbeiten wollen, unerlässlich.
Die Verwendung präziserer und vollständiger Kommentare in den Methoden würde das Verständnis des Codes erleichtern.
Nutzerfeedback:
Es fehlt an effektiven Rückmeldemechanismen für die Benutzer, insbesondere wenn Aktionen durchgeführt werden. Ein einfaches Benachrichtigungssystem für Erfolge, Fehler oder Statusänderungen könnte die Benutzererfahrung erheblich verbessern.
Testabdeckung:
Der aktuelle Zustand des Codes lässt darauf schließen, dass es an ausführlichen Tests fehlt. Unit-Tests und Integrationstests wären vorteilhaft, um sicherzustellen, dass die Anwendung unter verschiedenen Bedingungen stabil läuft.
Fazit:
Die AutoLLM-Anwendung ist ein vielversprechendes Projekt mit einem soliden Grundgerüst für die Interaktion mit LLMs und das Aufgabenmanagement. Mit gezielten Verbesserungen in den Bereichen Fehlerbehandlung, Performance, Dokumentation und Benutzerfeedback kann die Anwendung erheblich gesteigert werden, um eine noch bessere Benutzererfahrung zu bieten.