Browse Source

feat: default playground code (#817)

Signed-off-by: shanghaikid <jiangruiyi@gmail.com>
ryjiang 4 months ago
parent
commit
9581c93bf3
2 changed files with 82 additions and 6 deletions
  1. 76 5
      client/src/pages/play/Constants.ts
  2. 6 1
      client/src/pages/play/Play.tsx

+ 76 - 5
client/src/pages/play/Constants.ts

@@ -1,10 +1,81 @@
-export const DEFAULT_CODE_VALUE = `POST /v2/vectordb/databases/describe
+export const DEFAULT_CODE_VALUE = `# TOKEN username:password
+
+# create collection
+POST /v2/vectordb/collections/create
+{
+  "collectionName": "attu_milvus_example",
+  "schema": {
+    "fields": [
+      {
+        "fieldName": "pk",
+        "dataType": "VarChar",
+        "isPrimary": true,
+        "elementTypeParams": {
+          "max_length": 100
+        }
+      },
+      {
+        "fieldName": "dense_vector",
+        "dataType": "FloatVector",
+        "elementTypeParams": {
+          "dim": 4
+        }
+      }
+    ]
+  }
+}
+
+# create index
+POST /v2/vectordb/indexes/create
 {
-  "dbName": "default"
+  "collectionName": "attu_milvus_example",
+  "indexParams": [
+    {
+            "index_type": "AUTOINDEX",
+            "metricType": "L2",
+            "fieldName": "dense_vector",
+            "indexName": "dense_vector"
+        }
+  ]
 }
 
-POST /v2/vectordb/databases/list
+# load collection
+POST /v2/vectordb/collections/load
+{
+  "collectionName": "attu_milvus_example"
+}
 
-POST /v2/vectordb/collections/list`;
+# insert data
+POST /v2/vectordb/entities/insert
+{
+  "collectionName": "attu_milvus_example",
+  "data": [
+    {
+      "pk": "id1",
+      "dense_vector": [0.1, 0.2, 0.3, 0.4]
+    },
+    {
+      "pk": "id2",
+      "dense_vector": [0.5, 0.6, 0.7, 0.8]
+    }
+  ]
+}
+
+# vector search
+POST /v2/vectordb/entities/search
+{
+  "collectionName": "attu_milvus_example",
+  "data": [[0.15, 0.25, 0.35, 0.45]],
+  "annsField": "dense_vector",
+  "limit": 3,
+  "outputFields": ["pk", "dense_vector"]
+}
+`;
 
-export const DEFAULT_FOLD_LINE_RANGES = [{ lineFrom: 2, LineTo: 4 }];
+export const DEFAULT_FOLD_LINE_RANGES = [
+  { lineFrom: 5, LineTo: 26 },
+  { lineFrom: 30, LineTo: 40 },
+  { lineFrom: 44, LineTo: 46 },
+  { lineFrom: 50, LineTo: 62 },
+  { lineFrom: 66, LineTo: 72 },
+];

+ 6 - 1
client/src/pages/play/Play.tsx

@@ -23,6 +23,7 @@ import { MilvusHTTP } from './language/milvus.http';
 import { getCMStyle, getStyles } from './style';
 import { CustomEventNameEnum, PlaygroundCustomEventDetail } from './Types';
 import { DocumentEventManager } from './utils/event';
+import { DEFAULT_CODE_VALUE } from '@/pages/play/Constants';
 
 const Play: FC = () => {
   // hooks
@@ -38,7 +39,7 @@ const Play: FC = () => {
   const classes = getStyles();
   const [code, setCode] = useState(() => {
     const savedCode = localStorage.getItem(ATTU_PLAY_CODE);
-    return savedCode || '';
+    return savedCode || DEFAULT_CODE_VALUE;
   });
 
   // refs
@@ -91,6 +92,10 @@ const Play: FC = () => {
 
   // save code to local storage
   useEffect(() => {
+    if (code === '') {
+      localStorage.removeItem(ATTU_PLAY_CODE);
+      return;
+    }
     localStorage.setItem(ATTU_PLAY_CODE, code);
   }, [code]);