File size: 975 Bytes
df511cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import tempfile
import shutil
import os
from pathlib import Path

def convert_history_to_openai_format(system_prompt : str, history : list[tuple]):
    messages = [{ "role": "system", "content": system_prompt }]
    for (user_msg, assistant_msg) in history:
        messages.append({ "role": "user", "content": user_msg })
        if assistant_msg is not None:
            messages.append({ "role": "assistant", "content": assistant_msg })
    return messages

# Test case
#print(convert_history_to_openai_format("You are a helpful assistant.", [["Hi! How are you?", "I'm fine!, and you?"], ["Testing", None]]))

def move_file_to_temp_dir(dest_dir : str, src_full_path: str, rename_component : str) -> str:
    p = Path(src_full_path)
    dest_full = os.path.join(dest_dir, rename_component + "_" + p.stem + p.suffix)
    shutil.move(src_full_path, dest_full)
    return dest_full

def remake_temp_dir(dir : str) -> str:
    temp_dir = tempfile.mkdtemp()
    return temp_dir