Преглед изворни кода

Merge pull request #2332 from visuddhinanda/development

Development
visuddhinanda пре 8 месеци
родитељ
комит
5e81587433

+ 3 - 1
ai-translate/ai_translate/__init__.py

@@ -21,11 +21,13 @@ def open_redis_cluster(config):
 
 
 def start_consumer(context, name, config, queue, callback, proxy):
+    HeartBeat = 3600
     logger.debug("open rabbitmq %s@%s:%d/%s with timeout %ds",
                  config['user'], config['host'], config['port'], config['virtual-host'], config['customer-timeout'])
     connection = pika.BlockingConnection(
         pika.ConnectionParameters(
             host=config['host'], port=config['port'],
+            heartbeat=HeartBeat,
             credentials=pika.PlainCredentials(
                 config['user'], config['password']),
             virtual_host=config['virtual-host']))
@@ -37,7 +39,7 @@ def start_consumer(context, name, config, queue, callback, proxy):
         handle_message(context, ch, method, properties.message_id,
                        properties.content_type, json.loads(
                            body, object_hook=SimpleNamespace),
-                       callback, proxy, config['customer-timeout'])
+                       callback, proxy, HeartBeat, name)
 
     channel.basic_consume(
         queue=queue, on_message_callback=_callback, auto_ack=False)

+ 3 - 2
ai-translate/ai_translate/service.py

@@ -106,7 +106,7 @@ class Message:
 class AiTranslateService:
     """AI翻译服务"""
 
-    def __init__(self, redis, ch, method, api_url, openai_proxy, customer_timeout):
+    def __init__(self, redis, ch, method, api_url, openai_proxy, customer_timeout, worker_name: str):
         self.queue = 'ai_translate'
         self.model_token = None
         self.task = None
@@ -120,6 +120,7 @@ class AiTranslateService:
         self.channel = ch
         self.maxProcessTime = 15 * 60  # 一个句子的最大处理时间
         self.openai_proxy = openai_proxy
+        self.worker_name = worker_name
 
     def process_translate(self, message_id: str, body: Message) -> bool:
         """处理翻译任务"""
@@ -156,7 +157,7 @@ class AiTranslateService:
                 self.task.id,
                 'task',
                 self.task.title,
-                f'id:{message_id}',
+                f'id:{message_id} worker:{self.worker_name}',
                 None
             )
         times = [self.maxProcessTime]

+ 2 - 2
ai-translate/ai_translate/worker.py

@@ -7,12 +7,12 @@ from .utils import is_stopped
 logger = logging.getLogger(__name__)
 
 
-def handle_message(redis, ch, method, id, content_type, body, api_url: str, openai_proxy: str, customer_timeout: int):
+def handle_message(redis, ch, method, id, content_type, body, api_url: str, openai_proxy: str, customer_timeout: int, worker_name: str):
     MaxRetry: int = 3
     try:
         logger.info("process message start (%s) messages", len(body.payload))
         consumer = AiTranslateService(
-            redis, ch, method, api_url, openai_proxy, customer_timeout)
+            redis, ch, method, api_url, openai_proxy, customer_timeout, worker_name)
         messages = ns_to_dataclass([body], Message)
         consumer.process_translate(id, messages[0])
         logger.info(f'message {id} ack')

+ 1 - 1
ai-translate/config.orig.toml

@@ -4,7 +4,7 @@ port = 5672
 user = 'www'
 password = 'change-me'
 virtual-host = 'testing'
-customer-timeout = 600
+customer-timeout = 3600
 
 [redis]
 namespace = 'testing://'

+ 1 - 0
dashboard-v4/dashboard/src/components/template/SentEdit/SentEditMenu.tsx

@@ -162,6 +162,7 @@ const SentEditMenuWidget = ({
 
   return (
     <div
+      style={{ position: "relative" }}
       onMouseEnter={() => {
         setIsHover(true);
       }}

+ 2 - 0
open-ai-server/src/server.js

@@ -79,6 +79,8 @@ app.post("/api/openai", async (req, res) => {
       headers["x-api-key"] = apiKey;
       headers["anthropic-version"] = "2023-06-01";
     }
+
+    logger.info("request " + requestUrl);
     if (isStreaming) {
       // 流式响应处理
       res.setHeader("Content-Type", "text/event-stream");