Skip to content

Commit bf78e55

Browse files
committed
Initial commit
0 parents  commit bf78e55

File tree

733 files changed

+174652
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

733 files changed

+174652
-0
lines changed

.replit

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
entrypoint = "index.js"
2+
modules = ["nodejs-20:v8-20230920-bd784b9"]
3+
hidden = [".config", "package-lock.json"]
4+
5+
[nix]
6+
channel = "stable-23_05"
7+
8+
[unitTest]
9+
language = "nodejs"
10+
11+
[deployment]
12+
run = ["node", "index.js"]
13+
deploymentTarget = "cloudrun"
14+
ignorePorts = false

assets/favicon.ico

Whitespace-only changes.

index.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const express = require("express");
2+
const http = require("http");
3+
const WebSocket = require("ws");
4+
const bodyParser = require("body-parser");
5+
const { GoogleGenerativeAI, HarmBlockThreshold, HarmCategory } = require("@google/generative-ai");
6+
7+
const app = express();
8+
const server = http.createServer(app);
9+
const wss = new WebSocket.Server({ server });
10+
const genAI = new GoogleGenerativeAI(process.env["API_KEY"]);
11+
const safetySettings = [
12+
{
13+
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
14+
threshold: HarmBlockThreshold.BLOCK_NONE,
15+
},
16+
{
17+
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
18+
threshold: HarmBlockThreshold.BLOCK_NONE,
19+
},
20+
{
21+
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
22+
threshold: HarmBlockThreshold.BLOCK_NONE,
23+
},
24+
{
25+
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
26+
threshold: HarmBlockThreshold.BLOCK_NONE,
27+
},
28+
];
29+
30+
app.use(bodyParser.json());
31+
app.use(express.static("public"));
32+
33+
wss.on("connection", function connection(ws) {
34+
ws.on("message", async function incoming(messageBuffer) {
35+
try {
36+
const message = messageBuffer.toString();
37+
console.log(message);
38+
39+
const model = genAI.getGenerativeModel({ model: "gemini-pro", safetySettings });
40+
const result = await model.generateContentStream(message);
41+
42+
for await (const chunk of result.stream) {
43+
ws.send(chunk.text());
44+
}
45+
} catch (error) {
46+
console.error(error);
47+
ws.send("Error: Unable to process the request.");
48+
}
49+
});
50+
});
51+
52+
server.listen(process.env.PORT || 3000, () => {
53+
console.log(`Server started on port ${server.address().port}`);
54+
});

node_modules/.bin/mime

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)