mirror of
https://github.com/wassname/stampy-chat.git
synced 2026-10-03 13:00:56 +08:00
temp
This commit is contained in:
1 parent
a0ffdf9a66
commit
e307d30e55
2 files changed
+78
-8
No files matched your search
@@ -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'
|
||||
]
|
||||
+52
-8
@@ -28,6 +28,7 @@ const Home: NextPage = () => {
|
||||
</p>
|
||||
<p>Python serverless test:</p>
|
||||
<ApiButton />
|
||||
<ApiButton2 />
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
@@ -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 (
|
||||
<>
|
||||
<span>
|
||||
<button className="mr-2"
|
||||
onClick={async () => setResponse(JSON.stringify(await calculate()))} disabled={loading}>
|
||||
{loading ? "Loading..." : "Calculate"}
|
||||
</button>
|
||||
the factorial of
|
||||
<input type="number" className="w-10 border border-gray-300 px-1 mx-1" value={num} onChange={(e) => setNum(parseInt(e.target.value))} />
|
||||
= {loading ? "..." : response}
|
||||
<button className="mr-2"
|
||||
onClick={async () => setResponse(JSON.stringify(await calculate()))} disabled={loading}>
|
||||
{loading ? "Loading..." : "Calculate"}
|
||||
</button>
|
||||
the factorial of
|
||||
<input
|
||||
type = "number"
|
||||
className = "w-10 border border-gray-300 px-1 mx-1" value={num} onChange={(e) => setNum(parseInt(e.target.value))} />
|
||||
= {loading ? "..." : response}
|
||||
</span>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
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 (
|
||||
<>
|
||||
<span>
|
||||
<button className="mr-2"
|
||||
onClick={async () => setResponse(JSON.stringify(await getEmbeddings()))} disabled={loading}> {loading ? "Loading..." : "Calculate"} </button>
|
||||
the factorial of
|
||||
<input
|
||||
type = "number"
|
||||
className = "w-10 border border-gray-300 px-1 mx-1" value={query} onChange={(e) => setQuery(e.target.value)} />
|
||||
= {loading ? "..." : response}
|
||||
</span>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user