forked from KrishnaKumarSoni/blog-from-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessor.py
24 lines (22 loc) · 832 Bytes
/
processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import logging
def clean_and_format_messages(messages):
"""
Function to clean and format messages for further processing.
"""
cleaned_messages = []
for author, message in messages:
cleaned_messages.append({
"role": "User" if author == "user" else "ChatGPT",
"content": "\n[User]: " + message.strip() if author == "user" else "\n\n[ChatGPT Response]: " + message.strip()
})
return cleaned_messages
def segment_messages(messages, segment_size):
"""
Function to segment messages into chunks of a specified size.
"""
segments = []
for i in range(0, len(messages), segment_size):
segment = messages[i:i + segment_size]
segments.append(segment)
logging.info(f"Segmented messages into {len(segments)} segments.")
return segments