semantic search working in flask

This commit is contained in:
Fraser
2023-03-30 08:15:36 -04:00
parent bb5af6e40f
commit 492fd1982e
5 changed files with 149 additions and 13 deletions
+2 -2
View File
@@ -1,3 +1,5 @@
const API_URL = process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:3000";
import Head from "next/head";
import React from "react";
import { type NextPage } from "next";
@@ -25,8 +27,6 @@ const ShowEntry: React.FC<{entry: Entry}> = ({entry}) => {
);
};
const API_URL = process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:5000/";
const Home: NextPage = () => {
const [ entries, setEntries ] = useState<Entry[]>([]);
+10 -5
View File
@@ -1,3 +1,5 @@
const API_URL = process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:3000";
import { type NextPage } from "next";
import React from "react";
import Head from "next/head";
@@ -18,9 +20,12 @@ const Semantic: NextPage = () => {
setLoading(true);
setQuery("");
const res = await fetch("/api/semantic_search", {
const res = await fetch(API_URL + "/semantic", {
method: "POST",
headers: { "Content-Type": "application/json", },
headers: { "Content-Type": "application/json",
// allow cross-origin requests
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({query: query}),
})
@@ -47,7 +52,7 @@ const Semantic: NextPage = () => {
<SearchBox search={semantic_search} />
<ul>
{results.map((entry, i) => (
<li key={i}>
<li key={"entry" + i}>
<ShowSemanticEntry entry={entry} />
</li>
))}
@@ -84,8 +89,8 @@ const ShowSemanticEntry: React.FC<{entry: SemanticEntry}> = ({entry}) => {
{ entry.text.split("\n").map((paragraph, i) => {
const p = paragraph.trim();
if (p === "") return <></>;
if (p === ".....") return <hr key={i} />;
return <p className="text-sm" key={i}> {paragraph} </p>
if (p === ".....") return <hr key={"b" + i} />;
return <p className="text-sm" key={"p" + i}> {paragraph} </p>
})
}