-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
239 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from ceylon.llm import LLMTaskCoordinator, LLMTaskOperator | ||
|
||
from langchain_openai import ChatOpenAI | ||
|
||
code_llm = ChatOpenAI(model="gpt-4o") | ||
|
||
python_developer = LLMTaskOperator( | ||
name="python_developer", | ||
role="Junior Python Developer", | ||
context="Develop Python application with standalone application development knowlage", | ||
skills=[ | ||
"Python programming" | ||
], | ||
llm=code_llm | ||
) | ||
|
||
python_gui_developer = LLMTaskOperator( | ||
name="python_gui_developer", | ||
role="Junior Python GUI Developer", | ||
context="Develop Python application with GUI development knowlage", | ||
skills=[ | ||
"Python programming", | ||
"GUI development" | ||
], | ||
llm=code_llm | ||
) | ||
|
||
from ceylon.task import Task | ||
|
||
task = Task( | ||
name="Create Task Management App", | ||
description="Develop a advance task manager app. Required features. mark completed, filter with date, download by selected date. Need a UI for users" | ||
) | ||
|
||
tool_llm = ChatOpenAI(model="gpt-4o-mini") | ||
llm = ChatOpenAI(model="gpt-4o-mini") | ||
|
||
from textwrap import dedent | ||
|
||
agents = [python_developer, python_gui_developer] | ||
|
||
software_agency = LLMTaskCoordinator( | ||
tasks=[task], | ||
agents=agents, | ||
team_goal=dedent(""" | ||
Develop and deliver straightforward, secure, and efficient Python-based | ||
software solutions that provide clear business value, | ||
achieve 95% client satisfaction, and are completed on time and within budget | ||
"""), | ||
context=dedent(""" | ||
Employ agile methodologies to gather and analyze client requirements, design simple yet | ||
robust solutions, implement clean and readable Python code, conduct thorough testing, | ||
and deploy using streamlined CI/CD practices. Prioritize code simplicity, | ||
maintainability, and adherence to Python best practices | ||
throughout the development lifecycle, following the principle that | ||
'simple is better than complex'. | ||
"""), | ||
llm=llm, | ||
tool_llm=tool_llm | ||
) | ||
|
||
completed_tasks = software_agency.do() | ||
# Print results | ||
for task in completed_tasks: | ||
print(f"Task: {task.name}") | ||
print(f"Result: {task.final_answer}") | ||
print("-" * 50) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,154 +1,198 @@ | ||
import tkinter as tk | ||
from tkinter import messagebox, simpledialog, filedialog | ||
from tkinter import ttk | ||
from tkinter import messagebox, filedialog | ||
from datetime import datetime | ||
from dataclasses import dataclass, field | ||
import csv | ||
|
||
|
||
@dataclass | ||
class Task: | ||
def __init__(self, title, description, due_date, priority): | ||
self.title = title | ||
self.description = description | ||
self.due_date = due_date | ||
self.priority = priority | ||
self.completed = False | ||
|
||
def __str__(self): | ||
status = "Completed" if self.completed else "Pending" | ||
return f"{self.title} - Due: {self.due_date} - Priority: {self.priority} - Status: {status}" | ||
|
||
class TaskManagerApp: | ||
def __init__(self, root): | ||
self.root = root | ||
self.root.title("Task Manager") | ||
description: str | ||
due_date: datetime.date | ||
priority: str | ||
completed: bool = field(default=False) | ||
|
||
self.tasks = [] # List to store Task objects | ||
|
||
# Menu Bar | ||
self.menu_bar = tk.Menu(self.root) | ||
self.root.config(menu=self.menu_bar) | ||
class TaskManager: | ||
def __init__(self): | ||
self.tasks = [] | ||
|
||
# Task List Frame | ||
self.frame_task_list = tk.Frame(self.root) | ||
self.frame_task_list.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) | ||
def add_task(self, description, due_date, priority): | ||
if priority not in ['High', 'Medium', 'Low']: | ||
raise ValueError("Priority must be 'High', 'Medium', or 'Low'") | ||
task = Task(description, due_date, priority) | ||
self.tasks.append(task) | ||
|
||
self.task_listbox = tk.Listbox(self.frame_task_list, selectmode=tk.SINGLE) | ||
self.task_listbox.pack(fill=tk.BOTH, expand=True) | ||
def mark_task_completed(self, task_index): | ||
if 0 <= task_index < len(self.tasks): | ||
self.tasks[task_index].completed = True | ||
else: | ||
raise IndexError("Task index out of range") | ||
|
||
# Buttons | ||
self.button_frame = tk.Frame(self.frame_task_list) | ||
self.button_frame.pack() | ||
def get_pending_tasks(self): | ||
return [task for task in self.tasks if not task.completed] | ||
|
||
tk.Button(self.button_frame, text="Add Task", command=self.add_task).pack(side=tk.LEFT) | ||
tk.Button(self.button_frame, text="Edit Task", command=self.edit_task).pack(side=tk.LEFT) | ||
tk.Button(self.button_frame, text="Delete Task", command=self.delete_task).pack(side=tk.LEFT) | ||
tk.Button(self.button_frame, text="Complete Task", command=self.complete_task).pack(side=tk.LEFT) | ||
tk.Button(self.button_frame, text="Download Tasks", command=self.download_tasks).pack(side=tk.LEFT) # New button | ||
def get_finished_tasks(self): | ||
return [task for task in self.tasks if task.completed] | ||
|
||
# Task Details Frame | ||
self.frame_task_details = tk.Frame(self.root) | ||
self.frame_task_details.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True) | ||
def edit_task(self, task_index, new_description, new_due_date, new_priority): | ||
if 0 <= task_index < len(self.tasks): | ||
task = self.tasks[task_index] | ||
task.description = new_description | ||
task.due_date = new_due_date | ||
task.priority = new_priority | ||
else: | ||
raise IndexError("Task index out of range") | ||
|
||
def delete_task(self, task_index): | ||
if 0 <= task_index < len(self.tasks): | ||
del self.tasks[task_index] | ||
else: | ||
raise IndexError("Task index out of range") | ||
|
||
def get_tasks_sorted_by_date(self): | ||
return sorted(self.tasks, key=lambda task: task.due_date) | ||
|
||
def export_tasks_to_file(self, filename): | ||
sorted_tasks = self.get_tasks_sorted_by_date() | ||
try: | ||
with open(filename, 'w', newline='') as file: | ||
writer = csv.writer(file) | ||
writer.writerow(["Description", "Due Date", "Priority", "Completed"]) | ||
for task in sorted_tasks: | ||
writer.writerow([task.description, task.due_date, task.priority, task.completed]) | ||
return True | ||
except Exception as e: | ||
print(f"An error occurred while writing to file: {e}") | ||
return False | ||
|
||
|
||
class TaskApp: | ||
def __init__(self, root): | ||
self.root = root | ||
self.root.title("Task Manager") | ||
|
||
tk.Label(self.frame_task_details, text="Title:").pack() | ||
self.entry_title = tk.Entry(self.frame_task_details) | ||
self.entry_title.pack() | ||
self.task_manager = TaskManager() | ||
|
||
tk.Label(self.frame_task_details, text="Description:").pack() | ||
self.text_description = tk.Text(self.frame_task_details, height=5) | ||
self.text_description.pack() | ||
# Description | ||
tk.Label(root, text="Description").grid(row=0, column=0) | ||
self.description_entry = tk.Entry(root) | ||
self.description_entry.grid(row=0, column=1) | ||
|
||
tk.Label(self.frame_task_details, text="Due Date (YYYY-MM-DD):").pack() | ||
self.entry_due_date = tk.Entry(self.frame_task_details) | ||
self.entry_due_date.pack() | ||
# Due Date | ||
tk.Label(root, text="Due Date (YYYY-MM-DD)").grid(row=1, column=0) | ||
self.due_date_entry = tk.Entry(root) | ||
self.due_date_entry.grid(row=1, column=1) | ||
|
||
tk.Label(self.frame_task_details, text="Priority:").pack() | ||
# Priority | ||
tk.Label(root, text="Priority").grid(row=2, column=0) | ||
self.priority_var = tk.StringVar(value="Medium") | ||
priority_options = ["Low", "Medium", "High"] | ||
self.priority_menu = ttk.Combobox(self.frame_task_details, textvariable=self.priority_var, values=priority_options) | ||
self.priority_menu.pack() | ||
tk.OptionMenu(root, self.priority_var, "High", "Medium", "Low").grid(row=2, column=1) | ||
|
||
# Add Task Button | ||
tk.Button(root, text="Add Task", command=self.add_task).grid(row=3, column=1) | ||
|
||
tk.Button(self.frame_task_details, text="Save Task", command=self.save_task).pack() | ||
# Download Task List Button | ||
tk.Button(root, text="Download Task List", command=self.download_task_list).grid(row=3, column=2) | ||
|
||
# Task List | ||
self.task_list_frame = tk.Frame(root) | ||
self.task_list_frame.grid(row=4, column=0, columnspan=3) | ||
self.update_task_list() | ||
|
||
def add_task(self): | ||
self.clear_task_details() | ||
self.entry_title.focus() | ||
|
||
def edit_task(self): | ||
selected_task_index = self.task_listbox.curselection() | ||
if selected_task_index: | ||
task = self.tasks[selected_task_index[0]] | ||
self.entry_title.delete(0, tk.END) | ||
self.entry_title.insert(0, task.title) | ||
self.text_description.delete("1.0", tk.END) | ||
self.text_description.insert("1.0", task.description) | ||
self.entry_due_date.delete(0, tk.END) | ||
self.entry_due_date.insert(0, task.due_date) | ||
description = self.description_entry.get() | ||
due_date_str = self.due_date_entry.get() | ||
priority = self.priority_var.get() | ||
|
||
try: | ||
due_date = datetime.strptime(due_date_str, '%Y-%m-%d').date() | ||
self.task_manager.add_task(description, due_date, priority) | ||
messagebox.showinfo("Success", "Task added successfully!") | ||
self.description_entry.delete(0, tk.END) | ||
self.due_date_entry.delete(0, tk.END) | ||
self.priority_var.set("Medium") | ||
self.update_task_list() | ||
except ValueError as e: | ||
messagebox.showerror("Error", str(e)) | ||
|
||
def update_task_list(self): | ||
for widget in self.task_list_frame.winfo_children(): | ||
widget.destroy() | ||
|
||
tk.Label(self.task_list_frame, text="Pending Tasks").grid(row=0, column=0) | ||
tk.Label(self.task_list_frame, text="Finished Tasks").grid(row=0, column=1) | ||
|
||
pending_tasks = self.task_manager.get_pending_tasks() | ||
finished_tasks = self.task_manager.get_finished_tasks() | ||
|
||
for idx, task in enumerate(pending_tasks): | ||
tk.Label(self.task_list_frame, text=f"{task.description} (Due: {task.due_date}, Priority: {task.priority})").grid(row=idx + 1, column=0) | ||
tk.Button(self.task_list_frame, text="Mark as Done", command=lambda idx=idx: self.mark_task_done(idx)).grid(row=idx + 1, column=1) | ||
tk.Button(self.task_list_frame, text="Edit", command=lambda idx=idx: self.edit_task(idx)).grid(row=idx + 1, column=2) | ||
tk.Button(self.task_list_frame, text="Delete", command=lambda idx=idx: self.delete_task(idx)).grid(row=idx + 1, column=3) | ||
|
||
for idx, task in enumerate(finished_tasks): | ||
tk.Label(self.task_list_frame, text=f"{task.description} (Due: {task.due_date}, Priority: {task.priority})").grid(row=len(pending_tasks) + idx + 1, column=1) | ||
|
||
def mark_task_done(self, task_index): | ||
try: | ||
self.task_manager.mark_task_completed(task_index) | ||
self.update_task_list() | ||
except IndexError as e: | ||
messagebox.showerror("Error", str(e)) | ||
|
||
def edit_task(self, task_index): | ||
try: | ||
task = self.task_manager.tasks[task_index] | ||
self.description_entry.delete(0, tk.END) | ||
self.description_entry.insert(0, task.description) | ||
self.due_date_entry.delete(0, tk.END) | ||
self.due_date_entry.insert(0, task.due_date.strftime('%Y-%m-%d')) | ||
self.priority_var.set(task.priority) | ||
|
||
def delete_task(self): | ||
selected_task_index = self.task_listbox.curselection() | ||
if selected_task_index: | ||
del self.tasks[selected_task_index[0]] | ||
self.update_task_listbox() | ||
|
||
def complete_task(self): | ||
selected_task_index = self.task_listbox.curselection() | ||
if selected_task_index: | ||
task = self.tasks[selected_task_index[0]] | ||
task.completed = True | ||
self.update_task_listbox() | ||
|
||
def save_task(self): | ||
title = self.entry_title.get() | ||
description = self.text_description.get("1.0", tk.END).strip() | ||
due_date = self.entry_due_date.get() | ||
priority = self.priority_var.get() | ||
def save_changes(): | ||
new_description = self.description_entry.get() | ||
new_due_date_str = self.due_date_entry.get() | ||
new_priority = self.priority_var.get() | ||
try: | ||
new_due_date = datetime.strptime(new_due_date_str, '%Y-%m-%d').date() | ||
self.task_manager.edit_task(task_index, new_description, new_due_date, new_priority) | ||
self.update_task_list() | ||
messagebox.showinfo("Success", "Task updated successfully!") | ||
self.description_entry.delete(0, tk.END) | ||
self.due_date_entry.delete(0, tk.END) | ||
self.priority_var.set("Medium") | ||
save_button.destroy() | ||
except ValueError as e: | ||
messagebox.showerror("Error", str(e)) | ||
|
||
save_button = tk.Button(self.root, text="Save Changes", command=save_changes) | ||
save_button.grid(row=3, column=2) | ||
|
||
except IndexError as e: | ||
messagebox.showerror("Error", str(e)) | ||
|
||
def delete_task(self, task_index): | ||
try: | ||
self.task_manager.delete_task(task_index) | ||
self.update_task_list() | ||
messagebox.showinfo("Success", "Task deleted successfully!") | ||
except IndexError as e: | ||
messagebox.showerror("Error", str(e)) | ||
|
||
def download_task_list(self): | ||
filename = filedialog.asksaveasfilename(defaultextension=".csv", filetypes=[("CSV files", "*.csv")]) | ||
if filename: | ||
success = self.task_manager.export_tasks_to_file(filename) | ||
if success: | ||
messagebox.showinfo("Success", "Task list downloaded successfully!") | ||
else: | ||
messagebox.showerror("Error", "Failed to download task list.") | ||
|
||
if title and due_date: | ||
try: | ||
# Validate the date format | ||
datetime.strptime(due_date, '%Y-%m-%d') | ||
task = Task(title, description, due_date, priority) | ||
self.tasks.append(task) | ||
self.update_task_listbox() | ||
self.clear_task_details() | ||
messagebox.showinfo("Info", "Task saved successfully!") | ||
except ValueError: | ||
messagebox.showerror("Error", "Invalid date format. Please use YYYY-MM-DD.") | ||
else: | ||
messagebox.showwarning("Warning", "Title and Due Date are required.") | ||
|
||
def clear_task_details(self): | ||
self.entry_title.delete(0, tk.END) | ||
self.text_description.delete("1.0", tk.END) | ||
self.entry_due_date.delete(0, tk.END) | ||
self.priority_var.set("Medium") | ||
|
||
def update_task_listbox(self): | ||
# Sort tasks by priority before updating the listbox | ||
priority_order = {"High": 1, "Medium": 2, "Low": 3} | ||
self.tasks.sort(key=lambda x: priority_order[x.priority]) # Sort by priority | ||
|
||
self.task_listbox.delete(0, tk.END) | ||
for task in self.tasks: | ||
self.task_listbox.insert(tk.END, str(task)) | ||
|
||
def download_tasks(self): | ||
# Open a file dialog to choose the save location | ||
file_path = filedialog.asksaveasfilename(defaultextension=".csv", | ||
filetypes=[("CSV files", "*.csv"), ("All files", "*.*")]) | ||
if file_path: | ||
try: | ||
with open(file_path, mode='w', newline='') as file: | ||
writer = csv.writer(file) | ||
# Write the header | ||
writer.writerow(["Title", "Description", "Due Date", "Priority", "Status"]) | ||
for task in self.tasks: | ||
writer.writerow([task.title, task.description, task.due_date, task.priority, "Completed" if task.completed else "Pending"]) | ||
messagebox.showinfo("Success", "Tasks downloaded successfully!") | ||
except Exception as e: | ||
messagebox.showerror("Error", f"Failed to download tasks: {e}") | ||
|
||
if __name__ == "__main__": | ||
root = tk.Tk() | ||
app = TaskManagerApp(root) | ||
root.mainloop() | ||
app = TaskApp(root) | ||
root.mainloop() | ||
|