diff --git a/packages/nextjs/pages/index.tsx b/packages/nextjs/pages/index.tsx index f1b7603..18c3825 100644 --- a/packages/nextjs/pages/index.tsx +++ b/packages/nextjs/pages/index.tsx @@ -2,116 +2,145 @@ import { NextPage } from "next"; import { useEffect, useState } from "react"; const ETHSpace: NextPage = () => { - //在对后端发起请求后,将response的内容保存在results中 - const [result, setResult] = useState("The search results will be shown here"); - //设置默认是在我们提供的数据集而不是公共数据集中查询 - const [qinPublic, setQinPublic] = useState(false); - //获取目前提供的数据集选项 - const [options, setOptions] = useState([]); - //获取用户选择的数据集 - const [dataset, setDataset] = useState(""); - //获取用户搜索的prompt - const [seaPrompt, setSeaPrompt] = useState(""); - //仅在组件挂载时执行一次获取数据集列表 - useEffect(() => { - const data = fetchOptions(); - setOptions(data); - }); + //在对后端发起请求后,将response的内容保存在results中 + const [result, setResult] = useState<{data:string,metadata:{}}[]>([{data:"The search results will be shown here",metadata:{}},]); + //设置默认是在我们提供的数据集而不是公共数据集中查询 + const [qinPublic, setQinPublic] = useState(false); + //获取目前提供的数据集选项 + const [options, setOptions] = useState([]); + //获取用户选择的数据集 + const [dataset, setDataset] = useState(""); + //获取用户搜索的prompt + const [seaPrompt, setSeaPrompt] = useState(""); + //仅在组件挂载时执行一次获取数据集列表 + useEffect(() => { + fetchOptions(); + // console.log(data); + }); - //从后端获取数据集列表 - const fetchOptions = () => { - return ['eth-smart-contracts', 'eth-smart-contracts-sliced', "eth-smart-contracts-analysis"]; - }; - //获取search prompt与dataset名字后向后端发request - const handleonClick =()=>{ - - }; - return ( -
-
-
-
-

AI-based Smart Contract Explorer

-

-- Smart Contract Search Platform based on AI

- -- Let AI fully assist smart contract developers

-
- -
-
-
-
- { - setSeaPrompt(e.target.value); - }} - placeholder="Enter your prompt to search" /> -
-
-
-
- {!qinPublic ? ( - - ) : ( - { - setDataset(e.target.value); - }} - placeholder="Pls input the public dataset name" /> - )} -
-
-
- -
-
-
- -

A search question example:

-

* Give me some function examples about NFT

-

* 0x73c7448760517E3E6e416b2c130E3c6dB2026A1d

-
-
-
-
+ //从后端获取数据集列表 + const fetchOptions = async () => { + const response = await fetch("https://faasbyleeduckgo.gigalixirapp.com/api/v1/run?name=VectorAPI&func_name=get_cluster", { + method: "POST", + headers:{ + 'Content-Type':'application/json;charset=utf-8', + }, + body:JSON.stringify({ + "params": ["ai-based-smart-contract-explorer"] + }) + }); + const data=await response.json(); + setOptions(data.result); + }; + //获取search prompt与dataset名字后向后端发request + const handleonClick = async() => { + const response = await fetch("https://faasbyleeduckgo.gigalixirapp.com/api/v1/run?name=VectorAPI&func_name=search_data",{ + method:"POST", + headers:{ + 'Content-Type':'application/json; charset=utf-8', + }, + body:JSON.stringify({ + "params": [dataset, seaPrompt, 5] + }) + }); + const data=await response.json(); + // console.log(data.result.similarities); + setResult(data.result.similarities); + }; + return ( +
+
+
+
+

AI-based Smart Contract Explorer

+

-- Smart Contract Search Platform based on AI

+ -- Let AI fully assist smart contract developers

+
+
-
-
-

Search Results

- - {result} - +
+
+
+ { + setSeaPrompt(e.target.value); + }} + placeholder="Enter your prompt to search" />
- +
+
+
+ {!qinPublic ? ( + + ) : ( + { + setDataset(e.target.value); + }} + placeholder="Pls input the public dataset name" /> + )} +
+
+
+ +
+
+
+ +

A search question example:

+

* Give me some function examples about NFT

+

* 0x73c7448760517E3E6e416b2c130E3c6dB2026A1d

+
+
- ) +
+
+
+

Search Results

+ + {result.map((res,index)=>( +
+
+ Data +
{res.data}
+ Metadata +
{JSON.stringify(res.metadata,null,2)}
+
+ ))} +
+
+ +
+
+ ) }; export default ETHSpace; \ No newline at end of file