Skip to content

Commit 3530811

Browse files
authored
feat: fix timestamp (#1198)
1 parent 4456242 commit 3530811

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

aperag/agent/stream_formatters.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515
"""Stream message formatters for agent responses."""
1616

17+
import time
1718
from typing import Any, Dict, List
1819

19-
from aperag.utils.utils import now_unix_milliseconds
20-
2120
from .i18n import ERROR_MESSAGES
2221
from .response_types import (
2322
AgentErrorResponse,
@@ -50,7 +49,7 @@ def format_i18n_error(error_key: str, language: str = "en-US", **kwargs) -> Agen
5049
type="error",
5150
id="error",
5251
data=error_message,
53-
timestamp=now_unix_milliseconds(),
52+
timestamp=int(time.time()),
5453
)
5554

5655

@@ -60,7 +59,7 @@ def format_stream_start(msg_id: str) -> AgentStartResponse:
6059
return AgentStartResponse(
6160
type="start",
6261
id=msg_id,
63-
timestamp=now_unix_milliseconds(),
62+
timestamp=int(time.time()),
6463
)
6564

6665

@@ -70,7 +69,7 @@ def format_stream_content(msg_id: str, content: str) -> AgentMessageResponse:
7069
type="message",
7170
id=msg_id,
7271
data=content,
73-
timestamp=now_unix_milliseconds(),
72+
timestamp=int(time.time()),
7473
)
7574

7675

@@ -88,7 +87,7 @@ def format_stream_end(
8887
id=msg_id,
8988
data=references,
9089
urls=urls,
91-
timestamp=now_unix_milliseconds(),
90+
timestamp=int(time.time()),
9291
)
9392

9493

@@ -98,7 +97,7 @@ def format_thinking(msg_id: str, content: str) -> AgentThinkingResponse:
9897
type="thinking",
9998
id=msg_id,
10099
data=content,
101-
timestamp=now_unix_milliseconds(),
100+
timestamp=int(time.time()),
102101
)
103102

104103

@@ -109,7 +108,7 @@ def format_tool_call_result(msg_id: str, data: str, tool_name: str, result: Any)
109108
data=data,
110109
tool_name=tool_name,
111110
result=result,
112-
timestamp=now_unix_milliseconds(),
111+
timestamp=int(time.time()),
113112
)
114113

115114

@@ -119,7 +118,7 @@ def format_agent_start_message(trace_id: str, language: str = "en-US") -> Dict[s
119118
return {
120119
"type": "start",
121120
"id": trace_id,
122-
"timestamp": now_unix_milliseconds(),
121+
"timestamp": int(time.time()),
123122
}
124123

125124

@@ -130,7 +129,7 @@ def format_agent_stop_message(trace_id: str, references: list = None, urls: list
130129
"id": trace_id,
131130
"data": references or [],
132131
"urls": urls or [],
133-
"timestamp": now_unix_milliseconds(),
132+
"timestamp": int(time.time()),
134133
}
135134

136135

@@ -140,7 +139,7 @@ def format_agent_thinking_message(trace_id: str, thinking_content: str) -> Dict[
140139
"type": "thinking",
141140
"id": trace_id,
142141
"data": thinking_content,
143-
"timestamp": now_unix_milliseconds(),
142+
"timestamp": int(time.time()),
144143
}
145144

146145

@@ -150,5 +149,5 @@ def format_agent_message(trace_id: str, content: str) -> Dict[str, Any]:
150149
"type": "message",
151150
"id": trace_id,
152151
"data": content,
153-
"timestamp": now_unix_milliseconds(),
152+
"timestamp": int(time.time()),
154153
}

aperag/service/chat_service.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import json
1616
import logging
17+
import time
1718
import uuid
1819
from typing import Any, AsyncGenerator, Dict, List, Optional
1920

@@ -38,7 +39,6 @@
3839
stop_response,
3940
success_response,
4041
)
41-
from aperag.utils.utils import now_unix_milliseconds
4242

4343
logger = logging.getLogger(__name__)
4444

@@ -52,7 +52,7 @@ def format_stream_start(msg_id: str) -> Dict[str, Any]:
5252
return {
5353
"type": "start",
5454
"id": msg_id,
55-
"timestamp": now_unix_milliseconds(),
55+
"timestamp": int(time.time()),
5656
}
5757

5858
@staticmethod
@@ -62,7 +62,7 @@ def format_stream_content(msg_id: str, content: str) -> Dict[str, Any]:
6262
"type": "message",
6363
"id": msg_id,
6464
"data": content,
65-
"timestamp": now_unix_milliseconds(),
65+
"timestamp": int(time.time()),
6666
}
6767

6868
@staticmethod
@@ -84,7 +84,7 @@ def format_stream_end(
8484
"data": references,
8585
"memoryCount": memory_count,
8686
"urls": urls,
87-
"timestamp": now_unix_milliseconds(),
87+
"timestamp": int(time.time()),
8888
}
8989

9090
@staticmethod
@@ -94,7 +94,7 @@ def format_complete_response(msg_id: str, content: str) -> Dict[str, Any]:
9494
"type": "message",
9595
"id": msg_id,
9696
"data": content,
97-
"timestamp": now_unix_milliseconds(),
97+
"timestamp": int(time.time()),
9898
}
9999

100100
@staticmethod
@@ -104,7 +104,7 @@ def format_error(error: str) -> Dict[str, Any]:
104104
"type": "error",
105105
"id": str(uuid.uuid4()),
106106
"data": error,
107-
"timestamp": now_unix_milliseconds(),
107+
"timestamp": int(time.time()),
108108
}
109109

110110

aperag/utils/history.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import json
1616
import logging
17+
import time
1718
from abc import ABC, abstractmethod
1819
from typing import Any, Dict, List, Optional
1920

@@ -26,7 +27,6 @@
2627
message_to_storage_dict,
2728
storage_dict_to_message,
2829
)
29-
from aperag.utils.utils import now_unix_milliseconds
3030

3131
logger = logging.getLogger(__name__)
3232

@@ -263,7 +263,7 @@ def success_response(message_id, data):
263263
"type": "message",
264264
"id": message_id,
265265
"data": data,
266-
"timestamp": now_unix_milliseconds(),
266+
"timestamp": int(time.time()),
267267
}
268268
)
269269

@@ -274,7 +274,7 @@ def fail_response(message_id, error):
274274
"type": "error",
275275
"id": message_id,
276276
"data": error,
277-
"timestamp": now_unix_milliseconds(),
277+
"timestamp": int(time.time()),
278278
}
279279
)
280280

@@ -284,7 +284,7 @@ def start_response(message_id):
284284
{
285285
"type": "start",
286286
"id": message_id,
287-
"timestamp": now_unix_milliseconds(),
287+
"timestamp": int(time.time()),
288288
}
289289
)
290290

@@ -299,7 +299,7 @@ def references_response(message_id, references, memory_count=0, urls=[]):
299299
"data": references,
300300
"memoryCount": memory_count,
301301
"urls": urls,
302-
"timestamp": now_unix_milliseconds(),
302+
"timestamp": int(time.time()),
303303
}
304304
)
305305

@@ -309,7 +309,7 @@ def stop_response(message_id):
309309
{
310310
"type": "stop",
311311
"id": message_id,
312-
"timestamp": now_unix_milliseconds(),
312+
"timestamp": int(time.time()),
313313
}
314314
)
315315

frontend/src/pages/agent/$botId/chats/$chatId.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default () => {
7373

7474
const onSubmit: ChatInputProps['onSubmit'] = useCallback(
7575
async (params) => {
76-
const timestamp = new Date().getTime();
76+
const timestamp = Math.floor(new Date().getTime() / 1000);
7777
const msg: ChatMessage = {
7878
type: 'message',
7979
role: 'human',

frontend/src/pages/bots/$botId/chats/$chatId.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default () => {
7373

7474
const onSubmit: ChatInputProps['onSubmit'] = useCallback(
7575
async (params) => {
76-
const timestamp = new Date().getTime();
76+
const timestamp = Math.floor(new Date().getTime() / 1000);
7777
const msg: ChatMessage = {
7878
type: 'message',
7979
role: 'human',

0 commit comments

Comments
 (0)