chore: replace datetime.now() with timezone.now() for consistent time handling
parent
669764492c
commit
75c461f385
|
|
@ -9,7 +9,7 @@
|
|||
import time
|
||||
from datetime import datetime
|
||||
from typing import List, Type
|
||||
|
||||
from django.utils import timezone
|
||||
from rest_framework import serializers
|
||||
|
||||
from application.flow.i_step_node import NodeResult
|
||||
|
|
@ -30,7 +30,7 @@ def get_global_variable(node):
|
|||
history_context = [{'question': chat_record.problem_text, 'answer': chat_record.answer_text} for chat_record in
|
||||
history_chat_record]
|
||||
chat_id = node.flow_params_serializer.data.get('chat_id')
|
||||
return {'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time(),
|
||||
return {'time': timezone.now().strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time(),
|
||||
'history_context': history_context, 'chat_id': str(chat_id), **node.workflow_manage.form_data,
|
||||
'chat_user_id': body.get('chat_user_id'),
|
||||
'chat_user_type': body.get('chat_user_type'),
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from django.db import models, transaction
|
|||
from django.db.models import QuerySet, Q
|
||||
from django.http import HttpResponse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils import timezone
|
||||
from langchain_mcp_adapters.client import MultiServerMCPClient
|
||||
from rest_framework import serializers, status
|
||||
from rest_framework.utils.formatting import lazy_format
|
||||
|
|
@ -734,11 +735,11 @@ class ApplicationOperateSerializer(serializers.Serializer):
|
|||
application.desc = node_data.get('desc')
|
||||
application.prologue = node_data.get('prologue')
|
||||
application.work_flow = work_flow
|
||||
application.publish_time = datetime.datetime.now()
|
||||
application.publish_time = timezone.now()
|
||||
application.is_publish = True
|
||||
application.save()
|
||||
work_flow_version = ApplicationVersion(work_flow=application.work_flow, application=application,
|
||||
name=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
name=timezone.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
publish_user_id=user_id,
|
||||
publish_user_name=user.username,
|
||||
workspace_id=workspace_id)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import django.db.models
|
|||
from django.db.models import QuerySet
|
||||
from django.db.models.functions import Substr, Reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils import timezone
|
||||
from langchain_core.embeddings import Embeddings
|
||||
|
||||
from common.config.embedding_config import VectorStore
|
||||
|
|
@ -236,7 +237,7 @@ class ListenerManagement:
|
|||
next_index = taskType.value + 1
|
||||
current_index = taskType.value
|
||||
status_number = state.value
|
||||
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') + '+00'
|
||||
current_time = timezone.now().strftime('%Y-%m-%d %H:%M:%S.%f') + '+00'
|
||||
params_dict = {'${bit_number}': bit_number, '${up_index}': up_index,
|
||||
'${status_number}': status_number, '${next_index}': next_index,
|
||||
'${table_name}': query_set.model._meta.db_table, '${current_index}': current_index,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
import datetime
|
||||
|
||||
from django.http import JsonResponse
|
||||
from django.utils import timezone
|
||||
from openai.types import CompletionUsage
|
||||
from openai.types.chat import ChatCompletionChunk, ChatCompletionMessage, ChatCompletion
|
||||
from openai.types.chat.chat_completion import Choice as BlockChoice
|
||||
|
|
@ -28,7 +29,7 @@ class OpenaiToResponse(BaseToResponse):
|
|||
BlockChoice(finish_reason='stop', index=0, chat_id=chat_id,
|
||||
answer_list=other_params.get('answer_list', ""),
|
||||
message=ChatCompletionMessage(role='assistant', content=content))],
|
||||
created=datetime.datetime.now().second, model='', object='chat.completion',
|
||||
created=timezone.now().second, model='', object='chat.completion',
|
||||
usage=CompletionUsage(completion_tokens=completion_tokens,
|
||||
prompt_tokens=prompt_tokens,
|
||||
total_tokens=completion_tokens + prompt_tokens)
|
||||
|
|
@ -41,7 +42,7 @@ class OpenaiToResponse(BaseToResponse):
|
|||
if other_params is None:
|
||||
other_params = {}
|
||||
chunk = ChatCompletionChunk(id=chat_record_id, model='', object='chat.completion.chunk',
|
||||
created=datetime.datetime.now().second, choices=[
|
||||
created=timezone.now().second, choices=[
|
||||
Choice(delta=ChoiceDelta(content=content, reasoning_content=other_params.get('reasoning_content', ""),
|
||||
chat_id=chat_id),
|
||||
finish_reason='stop' if is_end else None,
|
||||
|
|
|
|||
Loading…
Reference in New Issue