Repository navigation
Expand file tree
/
Copy pathtree_generator.py
More file actions
43 lines (38 loc) · 1.74 KB
/
Copy pathtree_generator.py
File metadata and controls
43 lines (38 loc) · 1.74 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
from groq import Groq
import json
import os
FILE_PROMPT = """
You will be provided with list of source files and a summary of their contents. For each file, propose a new path and filename, using a directory structure that optimally organizes the files using known conventions and best practices.
Follow good naming conventions. Here are a few guidelines
- Think about your files : What related files are you working with?
- Identify metadata (for example, date, sample, experiment) : What information is needed to easily locate a specific file?
- Abbreviate or encode metadata
- Use versioning : Are you maintaining different versions of the same file?
- Think about how you will search for your files : What comes first?
- Deliberately separate metadata elements : Avoid spaces or special characters in your file names
If the file is already named well or matches a known convention, set the destination path to the same as the source path.
Your response must be a JSON object with the following schema:
```json
{
"files": [
{
"src_path": "original file path",
"dst_path": "new file path under proposed directory structure with proposed file name"
}
]
}
```
""".strip()
def create_file_tree(summaries: list, session):
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
chat_completion = client.chat.completions.create(
messages=[
{"role": "system", "content": FILE_PROMPT},
{"role": "user", "content": json.dumps(summaries)},
],
model="llama-3.1-70b-versatile",
response_format={"type": "json_object"}, # Uncomment if needed
temperature=0,
)
file_tree = json.loads(chat_completion.choices[0].message.content)["files"]
return file_tree