Skip to content

Commit

Permalink
sdlkasdnlkafsd
Browse files Browse the repository at this point in the history
  • Loading branch information
lopatoj committed Sep 22, 2024
1 parent 302ce06 commit 63d80a3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
9 changes: 0 additions & 9 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ import https from "node:https";
import fs from "node:fs";
import cors from "cors";
import { live } from "./routers/chats";
import OpenAI from "openai";

import { config } from "dotenv";
if (process.env.NODE_ENV !== "production") config();

console.log(process.env.NODE_ENV);

const chat = new OpenAI({
model: "gpt-3.5-turbo",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the meaning of life?" },
],
});

export const app = express();
app.use(express.json());
app.use(cors());
Expand Down
38 changes: 29 additions & 9 deletions server/src/routers/profile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Router, Response, Request } from "express";
import { authMiddleware, UserData } from "../middleware/auth";
import { database } from "../mongodb";
// import { HfInference } from "@huggingface/inference";
import { OpenAI } from "openai";

const users = database.collection("users");
const profile = Router();

const openai = new OpenAI({
apiKey: process.env.CHATGPT
});

profile.use(authMiddleware);

profile.get("/me", (_req, res: Response<{}, { user: UserData }>) => {
Expand All @@ -16,15 +20,31 @@ profile.post("/me", async (req: Request<{}, {}, Partial<{ bio: string, open_to_w
let { bio, open_to_wave } = req.body;
const user = res.locals.user;

// const inference = new HfInference("hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
console.log(bio, open_to_wave);

if (bio) {
const res = await openai.chat.completions.create({
messages: [{ role: "user", content: `Rate how extroverted this person is 1 to 10 with 1 being introverted and 10 being extroverted. State your answer wrapped with brackets. Ex: [9]
Rate how logical/emotional this person is 1 to 10 with 1 being logical and 10 being emotional . State your answer wrapped with brackets. Ex: [9]
Rate how reserved/impulsive this person is 1 to 10 with 1 being reserved and 10 being impulsive . State your answer wrapped with brackets. Ex: [9]
Rate how sensing/intuition this person is 1 to 10 with 1 being sensing and 10 being intuition. State your answer wrapped with brackets. Ex: [9]
// for await (const chunk of inference.chatCompletionStream({
// model: "meta-llama/Meta-Llama-3.1-70B-Instruct",
// messages: [{ role: "user", content: "What is the capital of France?" }],
// max_tokens: 500,
// })) {
// process.stdout.write(chunk.choices[0]?.delta?.content || "");
// }
Rate how Judging/Perceiving this person is 1 to 10 with 1 being Judging and 10 being Perceiving. State your answer wrapped with brackets. Ex: [9]` }, { role: "user", content: bio }],
model: "gpt-3.5-turbo",
});

if (!res.choices[0].message.content) {
return;
}

const traits = res.choices[0].message.content!.split("\n").map((line: string) => parseInt(line.match(/\[(\d+)\]/)![1]));

await users.updateOne({ firebase_id: user.firebase_id }, { "$set": { traits } });
}


await users.updateOne({ firebase_id: user.firebase_id }, { "$set": { bio: (bio || user.bio), open_to_wave: (open_to_wave !== null ? open_to_wave : user.open_to_wave) } });
res.json({ ...user, bio, open_to_wave });
Expand Down

0 comments on commit 63d80a3

Please sign in to comment.