From e307d30e556e071d1aa6413b9dfdd0a3c720573a Mon Sep 17 00:00:00 2001
From: Fraser
Date: Fri, 24 Mar 2023 21:00:37 -0400
Subject: [PATCH] temp
---
web/api/embeddings.py | 26 ++++++++++++++++++
web/src/pages/index.tsx | 60 +++++++++++++++++++++++++++++++++++------
2 files changed, 78 insertions(+), 8 deletions(-)
create mode 100644 web/api/embeddings.py
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}
>
);