-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileOrganizer.py
More file actions
84 lines (75 loc) · 2.8 KB
/
fileOrganizer.py
File metadata and controls
84 lines (75 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from openai import OpenAI
import os
def list_files(startpath):
for root, dirs, files in os.walk(startpath):
level = root.replace(startpath, '').count(os.sep)
indent = ' ' * 4 * (level)
print('{}{}/'.format(indent, os.path.basename(root)))
subindent = ' ' * 4 * (level + 1)
for f in files:
print('{}{}'.format(subindent, f))
directory_structure = list_files('/home/m/userInterface')
client = OpenAI()
assistant = client.beta.assistants.create(
name="File Organizer",
instructions="You are an assistant that helps users organize their files and directories. You can list, move, rename, delete, and create files and directories.",
tools=[
{
"type": "function",
"function": {
"name": "list_files",
"description": "List all files and directories in a given directory",
"parameters": {
"type": "object",
"properties": {
"directory": {"type": "string", "description": "The directory to list"}
},
"required": ["directory"]
}
}
},
{
"type": "function",
"function": {
"name": "move_file",
"description": "Move a file from one directory to another",
"parameters": {
"type": "object",
"properties": {
"source": {"type": "string", "description": "The file to move"},
"destination": {"type": "string", "description": "The directory to move the file to"}
},
"required": ["source", "destination"]
}
}
},
# Define additional functions here...
],
model="gpt-3.5-turbo-1106"
)
# Step 2: Create a Thread
thread = client.beta.threads.create()
# Get the directory structure. This has to be abstracted out to fit the needs of multiple users
# Step 3: Add a Message to a Thread
message = client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content="Provide suggestions on how I can improve the organization of my project."
)
# Step 4: Run the Assistant
run = client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id,
instructions="You are an assistant that helps users organize their files and directories. You can list, move, rename, delete, and create files and directories."
)
# Step 5: Check the Run status
run = client.beta.threads.runs.retrieve(
thread_id=thread.id,
run_id=run.id
)
# Step 6: Display the Assistant's Response
messages = client.beta.threads.messages.list(
thread_id=thread.id
)
for message in messages:
print(f"{message.role}: {message.content}")