Sfoglia il codice sorgente

Merge pull request #2325 from visuddhinanda/development

Development
visuddhinanda 9 mesi fa
parent
commit
f81e0cd2ed

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

@@ -20,7 +20,7 @@ def open_redis_cluster(config):
     return (cli, config['namespace'])
     return (cli, config['namespace'])
 
 
 
 
-def start_consumer(context, name, config, queue, callback):
+def start_consumer(context, name, config, queue, callback,proxy):
     logger.debug("open rabbitmq %s@%s:%d/%s with timeout %ds",
     logger.debug("open rabbitmq %s@%s:%d/%s with timeout %ds",
                  config['user'], config['host'], config['port'], config['virtual-host'], config['customer-timeout'])
                  config['user'], config['host'], config['port'], config['virtual-host'], config['customer-timeout'])
     connection = pika.BlockingConnection(
     connection = pika.BlockingConnection(
@@ -37,7 +37,7 @@ def start_consumer(context, name, config, queue, callback):
         handle_message(context, ch, method, properties.message_id,
         handle_message(context, ch, method, properties.message_id,
                        properties.content_type, json.loads(
                        properties.content_type, json.loads(
                            body, object_hook=SimpleNamespace),
                            body, object_hook=SimpleNamespace),
-                       callback, config['customer-timeout'])
+                       callback,proxy, config['customer-timeout'])
 
 
     channel.basic_consume(
     channel.basic_consume(
         queue=queue, on_message_callback=_callback, auto_ack=False)
         queue=queue, on_message_callback=_callback, auto_ack=False)
@@ -52,5 +52,8 @@ def launch(name, queue, config_file):
         config = tomllib.load(config_fd)
         config = tomllib.load(config_fd)
         logger.debug('api-url:(%s)', config['app']['api-url'])
         logger.debug('api-url:(%s)', config['app']['api-url'])
         redis_cli = open_redis_cluster(config['redis'])
         redis_cli = open_redis_cluster(config['redis'])
+        openai_proxy = config['app'].get('openai-proxy', None)
         start_consumer(redis_cli, name,
         start_consumer(redis_cli, name,
-                       config['rabbitmq'], queue, config['app']['api-url'])
+                       config['rabbitmq'], 
+                       queue, config['app']['api-url'], 
+                       openai_proxy)

+ 20 - 7
ai-translate/ai_translate/service.py

@@ -106,7 +106,7 @@ class Message:
 class AiTranslateService:
 class AiTranslateService:
     """AI翻译服务"""
     """AI翻译服务"""
 
 
-    def __init__(self, redis, ch, method, api_url, customer_timeout):
+    def __init__(self, redis, ch, method, api_url, openai_proxy,customer_timeout):
         self.queue = 'ai_translate'
         self.queue = 'ai_translate'
         self.model_token = None
         self.model_token = None
         self.task = None
         self.task = None
@@ -119,6 +119,7 @@ class AiTranslateService:
         self.customer_timeout = customer_timeout
         self.customer_timeout = customer_timeout
         self.channel = ch
         self.channel = ch
         self.maxProcessTime = 15 * 60  # 一个句子的最大处理时间
         self.maxProcessTime = 15 * 60  # 一个句子的最大处理时间
+        self.openai_proxy=openai_proxy 
 
 
     def process_translate(self, message_id: str, body: Message) -> bool:
     def process_translate(self, message_id: str, body: Message) -> bool:
         """处理翻译任务"""
         """处理翻译任务"""
@@ -355,12 +356,24 @@ class AiTranslateService:
 
 
         while attempt < max_retries:
         while attempt < max_retries:
             try:
             try:
-                response = requests.post(
-                    message.model.url,
-                    json=param,
-                    headers=headers,
-                    timeout=self.llm_timeout
-                )
+                if self.openai_proxy:
+                    response = requests.post(
+                        self.openai_proxy,
+                        json={
+                            "open_ai_url": message.model.url,
+                            "api_key": message.model.key,
+                            'payload':param,
+                        },
+                        headers=headers,
+                        timeout=self.llm_timeout
+                    )
+                else:
+                    response = requests.post(
+                        message.model.url,
+                        json=param,
+                        headers=headers,
+                        timeout=self.llm_timeout
+                    )
                 response.raise_for_status()
                 response.raise_for_status()
 
 
                 logger.info(f'{self.queue} LLM request successful')
                 logger.info(f'{self.queue} LLM request successful')

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

@@ -7,7 +7,7 @@ from .utils import is_stopped
 logger = logging.getLogger(__name__)
 logger = logging.getLogger(__name__)
 
 
 
 
-def handle_message(redis, ch, method, id, content_type, body, api_url: str, customer_timeout: int):
+def handle_message(redis, ch, method, id, content_type, body, api_url: str,openai_proxy:str, customer_timeout: int):
     MaxRetry: int = 3
     MaxRetry: int = 3
     try:
     try:
         logger.info("process message start (%s) messages", len(body.payload))
         logger.info("process message start (%s) messages", len(body.payload))

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

@@ -13,3 +13,4 @@ port = 6371
 
 
 [app]
 [app]
 api-url = 'http://127.0.0.1:8000/api'
 api-url = 'http://127.0.0.1:8000/api'
+openai-proxy = 'http://localhost:4000/api/openai'

+ 1 - 0
api-v8/app/Console/Commands/CreateMyHanCrop.php

@@ -105,6 +105,7 @@ class CreateMyHanCrop extends Command
             Storage::disk('local')->makeDirectory($dir);
             Storage::disk('local')->makeDirectory($dir);
             Storage::disk('local')->makeDirectory($dir . '/img');
             Storage::disk('local')->makeDirectory($dir . '/img');
             Storage::disk('local')->put($dir . "/index.html", $content);
             Storage::disk('local')->put($dir . "/index.html", $content);
+            Storage::disk('local')->put($dir . "/img/{$page}", $page);
             $this->info("page={$page} word=" . count($words));
             $this->info("page={$page} word=" . count($words));
         } else {
         } else {
             $this->error('page' . $page . 'no words');
             $this->error('page' . $page . 'no words');

+ 1 - 10
api-v8/app/Http/Api/TemplateRender.php

@@ -553,17 +553,8 @@ class TemplateRender
                     'tpl' => 'nissaya',
                     'tpl' => 'nissaya',
                 ];
                 ];
                 break;
                 break;
-            case 'text':
-                $output = $pali . '၊' . $meaning;
-                break;
-            case 'tex':
-                $output = $pali . '၊' . $meaning;
-                break;
-            case 'simple':
-                $output = $pali . '၊' . $meaning;
-                break;
             case 'prompt':
             case 'prompt':
-                $output = Tools::MyToRm($pali) . ':' . $meaning;
+                $output = Tools::MyToRm($pali) . ':' . end($props["meaning"]);
                 break;
                 break;
             default:
             default:
                 $output = $pali . '၊' . $meaning;
                 $output = $pali . '၊' . $meaning;

+ 9 - 0
api-v8/app/Http/Controllers/ProjectTreeController.php

@@ -61,9 +61,18 @@ class ProjectTreeController extends Controller
         }
         }
         foreach ($newData as $key => $value) {
         foreach ($newData as $key => $value) {
             if ($value['parent_id']) {
             if ($value['parent_id']) {
+                $parent = null;
+                /*
                 $parent = \array_find($newData, function ($element) use ($value) {
                 $parent = \array_find($newData, function ($element) use ($value) {
                     return $element['old_id'] == $value['parent_id'];
                     return $element['old_id'] == $value['parent_id'];
                 });
                 });
+                */
+                foreach ($newData as $item) {
+                    if ($item['old_id'] == $value['parent_id']) {
+                        $parent = $item;
+                        break;
+                    }
+                }
                 if ($parent) {
                 if ($parent) {
                     $newData[$key]['parent_id'] = $parent['uid'];
                     $newData[$key]['parent_id'] = $parent['uid'];
                     $parentPath = $parent['path'] ? json_decode($parent['path']) : [];
                     $parentPath = $parent['path'] ? json_decode($parent['path']) : [];

+ 1 - 1
api-v8/storage/resources

@@ -1 +1 @@
-Subproject commit 8d97f4676c32d4b76f94a8180816eaa7f3319df0
+Subproject commit 5f87f0be2352900d3614dc9d9f765141bb5140ce