diff --git a/web/api/embeddings.py b/web/api/embeddings.py new file mode 100644 index 0000000..6a526a1 --- /dev/null +++ b/web/api/embeddings.py @@ -0,0 +1,26 @@ +import json +from http.server import BaseHTTPRequestHandler + +class handler(BaseHTTPRequestHandler): + + # post request = calculate factorial of passed number + def do_POST(self): + self.send_response(200) + self.send_header('Content-type', 'application/json') + self.end_headers() + content_length = int(self.headers['Content-Length']) + post_data = self.rfile.read(content_length) + data = json.loads(post_data) + # results = embeddings(data['query']) + results = { 'results' : 'foo' } + self.wfile.write(json.dumps(results).encode('utf-8')) + +def embeddings(query): + + # write a function here that takes a query, returns a bunch of semantically similar links + + return [ \ + 'https://www.lesswrong.com/posts/FinfRNLMfbq5ESxB9/microsoft-research-paper-claims-sparks-of-artificial', \ + 'https://www.lesswrong.com/posts/XhfBRM7oRcpNZwjm8/abstracts-should-be-either-actually-short-tm-or-broken-into', \ + 'https://www.lesswrong.com/posts/ohXcBjGvazPAxq2ex/continue-working-on-hard-alignment-don-t-give-up' + ] diff --git a/web/src/pages/index.tsx b/web/src/pages/index.tsx index a7e0a43..631e762 100644 --- a/web/src/pages/index.tsx +++ b/web/src/pages/index.tsx @@ -28,6 +28,7 @@ const Home: NextPage = () => {

Python serverless test:

+ ); @@ -47,7 +48,7 @@ const ApiButton: React.FC = () => { setLoading(true); - const res = await fetch("/api", { + const res = await fetch("/api/embeddings", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({number: num}), @@ -64,13 +65,56 @@ const ApiButton: React.FC = () => { return ( <> - - the factorial of - setNum(parseInt(e.target.value))} /> - = {loading ? "..." : response} + + the factorial of + setNum(parseInt(e.target.value))} /> + = {loading ? "..." : response} + + + ); +}; + + +const ApiButton2: React.FC = () => { + const [response, setResponse] = useState(""); + const [query, setQuery] = useState(""); + const [loading, setLoading] = useState(false); + + const getEmbeddings = async () => { + + setLoading(true); + + const res = await fetch("/api", { + method: "POST", + headers: { "Content-Type": "application/json", }, + body: JSON.stringify({query: query}), + }) + + const data = await res.json(); + + setLoading(false); + + return data; + + // return data.result || "error"; + + }; + + return ( + <> + + + the factorial of + setQuery(e.target.value)} /> + = {loading ? "..." : response} );