Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,8 @@ scheduler = CommitScheduler(
|
|
33 |
every=1, # Upload every 1 minutes
|
34 |
)
|
35 |
|
36 |
-
def save_or_update_conversation(conversation_id, history,
|
|
|
37 |
"""
|
38 |
Save or update conversation data in a JSON Lines file.
|
39 |
If the entry already exists (same id and message_index), update the 'label' field.
|
@@ -58,8 +59,8 @@ def save_or_update_conversation(conversation_id, history,message, response, mess
|
|
58 |
"id": conversation_id,
|
59 |
"timestamp": datetime.now(ZoneInfo("Asia/Tokyo")).isoformat(),
|
60 |
"history":history,
|
61 |
-
"prompt": message,
|
62 |
-
"completion": response,
|
63 |
"message_index": message_index,
|
64 |
"label": liked
|
65 |
})
|
@@ -67,7 +68,7 @@ def save_or_update_conversation(conversation_id, history,message, response, mess
|
|
67 |
# Write updated data back to file
|
68 |
with feedback_file.open("w") as f:
|
69 |
for entry in data:
|
70 |
-
f.write(json.dumps(entry) + "\n")
|
71 |
|
72 |
|
73 |
def respond(
|
@@ -105,7 +106,7 @@ def respond(
|
|
105 |
|
106 |
# Save conversation after the full response is generated
|
107 |
message_index = len(history)
|
108 |
-
save_or_update_conversation(conversation_id,
|
109 |
|
110 |
def vote(data: gr.LikeData, history, conversation_id):
|
111 |
"""
|
@@ -113,7 +114,7 @@ def vote(data: gr.LikeData, history, conversation_id):
|
|
113 |
"""
|
114 |
message_index = data.index[0]
|
115 |
liked = data.liked
|
116 |
-
save_or_update_conversation(conversation_id, None, None, message_index, liked)
|
117 |
|
118 |
def create_conversation_id():
|
119 |
return str(uuid.uuid4())
|
|
|
33 |
every=1, # Upload every 1 minutes
|
34 |
)
|
35 |
|
36 |
+
def save_or_update_conversation(conversation_id, history,
|
37 |
+
message, response, message_index, liked=None):
|
38 |
"""
|
39 |
Save or update conversation data in a JSON Lines file.
|
40 |
If the entry already exists (same id and message_index), update the 'label' field.
|
|
|
59 |
"id": conversation_id,
|
60 |
"timestamp": datetime.now(ZoneInfo("Asia/Tokyo")).isoformat(),
|
61 |
"history":history,
|
62 |
+
"prompt": str(message),
|
63 |
+
"completion": str(response),
|
64 |
"message_index": message_index,
|
65 |
"label": liked
|
66 |
})
|
|
|
68 |
# Write updated data back to file
|
69 |
with feedback_file.open("w") as f:
|
70 |
for entry in data:
|
71 |
+
f.write(json.dumps(entry,ensure_ascii=False) + "\n")
|
72 |
|
73 |
|
74 |
def respond(
|
|
|
106 |
|
107 |
# Save conversation after the full response is generated
|
108 |
message_index = len(history)
|
109 |
+
save_or_update_conversation(conversation_id,messages, message, response, message_index)
|
110 |
|
111 |
def vote(data: gr.LikeData, history, conversation_id):
|
112 |
"""
|
|
|
114 |
"""
|
115 |
message_index = data.index[0]
|
116 |
liked = data.liked
|
117 |
+
save_or_update_conversation(conversation_id, history,None, None, message_index, liked)
|
118 |
|
119 |
def create_conversation_id():
|
120 |
return str(uuid.uuid4())
|