Forráskód Böngészése

Merge pull request #2405 from visuddhinanda/development

Development
visuddhinanda 1 napja
szülő
commit
14a8998170

+ 12 - 34
api-v13/app/Console/Commands/UpgradeAITranslation.php

@@ -357,41 +357,19 @@ class UpgradeAITranslation extends Command
             ->get();
             ->get();
         $result = [];
         $result = [];
         foreach ($sentences as $key => $sentence) {
         foreach ($sentences as $key => $sentence) {
-            $id = "{$sentence->book_id}-{$sentence->paragraph}-{$sentence->word_start}-{$sentence->word_end}";
-            /*
-            $nissaya = [];
-            $rows = explode("\n", $sentence->content);
-            foreach ($rows as $key => $row) {
-                if (strpos('=', $row) >= 0) {
-                    $factors = explode("=", $row);
-                    $nissaya[] = Tools::MyToRm($factors[0]) . ':' . end($factors);
-                } else {
-                    $nissaya[] = $row;
-                }
+            if (!empty($sentence->content)) {
+                $id = "{$sentence->book_id}-{$sentence->paragraph}-{$sentence->word_start}-{$sentence->word_end}";
+
+                $aiNissaya = $this->nissayaTranslateService
+                    ->setModel($this->model)
+                    ->translate($sentence->content, false);
+                Log::debug('ai response ', ['content' => $aiNissaya['data']]);
+                $result[] = [
+                    'id' => $id,
+                    'content' => json_encode($aiNissaya['data'] ?? [], JSON_UNESCAPED_UNICODE),
+                    'content_type' => 'json',
+                ];
             }
             }
-            $nissayaText = json_encode(implode("\n", $nissaya), JSON_UNESCAPED_UNICODE);
-            Log::debug($nissayaText);
-            $startAt = time();
-            $response = $this->openAIService->setApiUrl($this->model['url'])
-                ->setModel($this->model['model'])
-                ->setApiKey($this->model['key'])
-                ->setSystemPrompt($sysPrompt)
-                ->setTemperature(0.7)
-                ->setStream(false)
-                ->send("# nissaya\n\n{$nissayaText}\n\n");
-            $complete = time() - $startAt;
-            $content = $response['choices'][0]['message']['content'] ?? '';
-            Log::debug("ai response in {$complete}s content=" . $content);
-            */
-            $aiNissaya = $this->nissayaTranslateService
-                ->setModel($this->model)
-                ->translate($sentence->content, false);
-            Log::debug('ai response ', ['content' => $aiNissaya['data']]);
-            $result[] = [
-                'id' => $id,
-                'content' => json_encode($aiNissaya['data'] ?? [], JSON_UNESCAPED_UNICODE),
-                'content_type' => 'json',
-            ];
         }
         }
 
 
         return $result;
         return $result;

+ 12 - 7
api-v13/app/Http/Controllers/NissayaCardController.php

@@ -2,14 +2,15 @@
 
 
 namespace App\Http\Controllers;
 namespace App\Http\Controllers;
 
 
-use App\Models\NissayaEnding;
+use Illuminate\Support\Facades\Log;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
-use mustache\mustache;
+use Illuminate\Support\Facades\App;
+
 use App\Http\Api\ChannelApi;
 use App\Http\Api\ChannelApi;
 use App\Http\Api\MdRender;
 use App\Http\Api\MdRender;
-use Illuminate\Support\Facades\App;
 use App\Models\DhammaTerm;
 use App\Models\DhammaTerm;
 use App\Models\Relation;
 use App\Models\Relation;
+use App\Models\NissayaEnding;
 
 
 class NissayaCardController extends Controller
 class NissayaCardController extends Controller
 {
 {
@@ -50,13 +51,15 @@ class NissayaCardController extends Controller
             "_System_Grammar_Term_" . strtolower($request->input('lang')) . "_",
             "_System_Grammar_Term_" . strtolower($request->input('lang')) . "_",
             "_System_Grammar_Term_en_"
             "_System_Grammar_Term_en_"
         );
         );
+
         if (!$localTerm) {
         if (!$localTerm) {
             return $this->error('no term channel');
             return $this->error('no term channel');
         }
         }
-        $termTable = DhammaTerm::where('channal', $localTerm);
 
 
         $cardData['ending']['word'] = $nissayaEnding;
         $cardData['ending']['word'] = $nissayaEnding;
-        $endingTerm = $termTable->where('word', $nissayaEnding)->first();
+        $endingTerm = DhammaTerm::where('channal', $localTerm)
+            ->where('word', $nissayaEnding)
+            ->first();
         if ($endingTerm) {
         if ($endingTerm) {
             $cardData['ending']['id'] = $endingTerm->guid;
             $cardData['ending']['id'] = $endingTerm->guid;
             $cardData['ending']['tag'] = $endingTerm->tag;
             $cardData['ending']['tag'] = $endingTerm->tag;
@@ -107,7 +110,9 @@ class NissayaCardController extends Controller
                     $localCase  = [];
                     $localCase  = [];
                     foreach ($cases as $case) {
                     foreach ($cases as $case) {
                         $localCase[] = [
                         $localCase[] = [
-                            'label' => $termTable->where('word', $case)->value('meaning'),
+                            'label' => DhammaTerm::where('channal', $localTerm)
+                                ->where('word', $case)
+                                ->value('meaning'),
                             'case' => $case,
                             'case' => $case,
                             'link' => config('mint.server.dashboard_base_path') . '/term/list/' . $case
                             'link' => config('mint.server.dashboard_base_path') . '/term/list/' . $case
                         ];
                         ];
@@ -124,7 +129,7 @@ class NissayaCardController extends Controller
                     $localTo  = [];
                     $localTo  = [];
                     foreach ($linkTos->case as $to) {
                     foreach ($linkTos->case as $to) {
                         $localTo[] = [
                         $localTo[] = [
-                            'label' => $termTable->where('word', $to)->value('meaning'),
+                            'label' => DhammaTerm::where('channal', $localTerm)->where('word', $to)->value('meaning'),
                             'case' => $to,
                             'case' => $to,
                             'link' => config('mint.server.dashboard_base_path') . '/term/list/' . $to
                             'link' => config('mint.server.dashboard_base_path') . '/term/list/' . $to
                         ];
                         ];

+ 1 - 1
api-v13/app/Services/TermService.php

@@ -92,7 +92,7 @@ class TermService
             "_System_Grammar_Term_" . strtolower($lang) . "_",
             "_System_Grammar_Term_" . strtolower($lang) . "_",
             "_System_Grammar_Term_en_"
             "_System_Grammar_Term_en_"
         );
         );
-        $result = DhammaTerm::select(['word', 'tag', 'meaning', 'other_meaning'])
+        $result = DhammaTerm::select(['guid', 'word', 'tag', 'meaning', 'other_meaning'])
             ->where('channal', $localTermChannel)
             ->where('channal', $localTermChannel)
             ->get();
             ->get();
         return ['items' => $result, 'total' => count($result)];
         return ['items' => $result, 'total' => count($result)];

+ 4 - 2
dashboard-v6/src/features/editor/Chapter.tsx

@@ -50,11 +50,13 @@ export default function ChapterEditor({
 
 
   useEffect(() => {
   useEffect(() => {
     if (!currUser?.id || !chapterId) return;
     if (!currUser?.id || !chapterId) return;
-
+    const paramObj = search
+      ? Object.fromEntries(new URLSearchParams(search))
+      : undefined;
     save({
     save({
       type: "chapter",
       type: "chapter",
       article_id: chapterId,
       article_id: chapterId,
-      param: search || undefined,
+      param: JSON.stringify(paramObj),
     });
     });
   }, [currUser?.id, chapterId, search, save]);
   }, [currUser?.id, chapterId, search, save]);
 
 

+ 4 - 1
dashboard-v6/src/features/editor/Paragraph.tsx

@@ -51,10 +51,13 @@ export default function ParaEditor({
   useEffect(() => {
   useEffect(() => {
     if (!currUser?.id || !chapterId) return;
     if (!currUser?.id || !chapterId) return;
 
 
+    const paramObj = search
+      ? Object.fromEntries(new URLSearchParams(search))
+      : undefined;
     save({
     save({
       type: "chapter",
       type: "chapter",
       article_id: chapterId,
       article_id: chapterId,
-      param: search || undefined,
+      param: JSON.stringify(paramObj),
     });
     });
   }, [currUser?.id, chapterId, search, save]);
   }, [currUser?.id, chapterId, search, save]);
 
 

+ 4 - 2
dashboard-v6/src/features/editor/Term.tsx

@@ -45,11 +45,13 @@ export default function TermEditor({
 
 
   useEffect(() => {
   useEffect(() => {
     if (!currUser?.id || !termId) return;
     if (!currUser?.id || !termId) return;
-
+    const paramObj = search
+      ? Object.fromEntries(new URLSearchParams(search))
+      : undefined;
     save({
     save({
       type: "term",
       type: "term",
       article_id: termId,
       article_id: termId,
-      param: search || undefined,
+      param: JSON.stringify(paramObj),
     });
     });
   }, [currUser?.id, termId, search, save]);
   }, [currUser?.id, termId, search, save]);