visuddhinanda 1 éve
szülő
commit
cc2fedd768

+ 40 - 0
api-v8/app/Http/Api/TemplateRender.php

@@ -154,6 +154,9 @@ class TemplateRender
             case 'dict-pref':
                 $result = $this->render_dict_pref();
                 break;
+            case 'ai':
+                $result = $this->render_ai();
+                break;
             default:
                 # code...
                 $result = [
@@ -1359,6 +1362,43 @@ class TemplateRender
         }
         return $output;
     }
+
+    private function render_ai()
+    {
+        $model = $this->get_param($this->param, "model", 1, 1);
+
+        $props = [
+            "model" => $model,
+        ];
+
+        switch ($this->format) {
+            case 'react':
+                $output = [
+                    'props' => base64_encode(\json_encode($props)),
+                    'html' => "",
+                    'text' => '',
+                    'tag' => 'div',
+                    'tpl' => 'ai',
+                ];
+                break;
+            case 'unity':
+                $output = [
+                    'props' => base64_encode(\json_encode($props)),
+                    'tpl' => 'ai',
+                ];
+                break;
+            case 'text':
+                $output = 'ai';
+                break;
+            case 'prompt':
+                $output = '';
+                break;
+            default:
+                $output = 'ai';
+                break;
+        }
+        return $output;
+    }
     private  function get_param(array $param, string $name, int $id, string $default = '')
     {
         if (isset($param[$name])) {

+ 3 - 0
dashboard-v4/dashboard/src/components/template/MdTpl.tsx

@@ -1,4 +1,5 @@
 import { GrammarPopShell } from "../dict/GrammarPop";
+import Ai from "./Ai";
 import Article from "./Article";
 import DictPreferenceEditor from "./DictPreferenceEditor";
 import Exercise from "./Exercise";
@@ -69,6 +70,8 @@ const Widget = ({ tpl, props, children }: IWidgetMdTpl) => {
       return <Reference props={props ? props : ""} />;
     case "dict-pref":
       return props ? <DictPreferenceEditor props={props} /> : <>无效的参数</>;
+    case "ai":
+      return <Ai props={props ? props : ""} />;
     default:
       return <>未定义模版({tpl})</>;
   }