Skip to content

Commit

Permalink
Update datetime usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ionic-bond committed Dec 24, 2024
1 parent cd0bde1 commit 04b69eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions stream_translator_gpt/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from abc import ABC, abstractmethod
from datetime import datetime
from datetime import datetime, timezone

import google.generativeai as genai
import numpy as np
Expand Down Expand Up @@ -37,7 +37,7 @@ def work(cls, **kwargs):


def sec2str(second: float):
dt = datetime.utcfromtimestamp(second)
dt = datetime.fromtimestamp(second, tz=timezone.utc)
result = dt.strftime('%H:%M:%S')
result += ',' + str(int(second * 10 % 10))
return result
Expand Down
8 changes: 4 additions & 4 deletions stream_translator_gpt/llm_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
import re
from collections import deque
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

import google.generativeai as genai
from google.api_core.exceptions import InternalServerError, ResourceExhausted, TooManyRequests
Expand Down Expand Up @@ -50,7 +50,7 @@ def _parse_json_completion(completion):


def _is_task_timeout(task: TranslationTask, timeout: float) -> bool:
return datetime.utcnow() - task.start_time > timedelta(seconds=timeout)
return datetime.now(timezone.utc) - task.start_time > timedelta(seconds=timeout)


class LLMClint():
Expand Down Expand Up @@ -175,7 +175,7 @@ def __init__(self, llm_client: LLMClint, timeout: int, retry_if_translation_fail

def _trigger(self, translation_task: TranslationTask):
if not translation_task.start_time:
translation_task.start_time = datetime.utcnow()
translation_task.start_time = datetime.now(timezone.utc)
translation_task.translation_failed = False
thread = threading.Thread(target=self.llm_client.translate, args=(translation_task,))
thread.daemon = True
Expand Down Expand Up @@ -225,7 +225,7 @@ def __init__(self, llm_client: LLMClint, timeout: int, retry_if_translation_fail

def _trigger(self, translation_task: TranslationTask):
if not translation_task.start_time:
translation_task.start_time = datetime.utcnow()
translation_task.start_time = datetime.now(timezone.utc)
translation_task.translation_failed = False
thread = threading.Thread(target=self.llm_client.translate, args=(translation_task,))
thread.daemon = True
Expand Down

0 comments on commit 04b69eb

Please sign in to comment.