Skip to content

Commit 8a03185

Browse files
2 parents f30be8f + 207f8d2 commit 8a03185

File tree

6 files changed

+146
-2
lines changed

6 files changed

+146
-2
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"livekit-server-sdk": "^1.1.0",
2828
"next": "^13.2.1",
2929
"next-auth": "^4.19.0",
30+
"openai": "^3.2.1",
3031
"pusher": "^5.1.2",
3132
"pusher-js": "^8.0.1",
3233
"react": "18.2.0",

prisma/schema.prisma

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ model User {
5757
sessions Session[]
5858
Room Room[]
5959
Participant Participant[]
60+
Transcript Transcript[]
6061
}
6162

6263
model VerificationToken {
@@ -72,14 +73,30 @@ model Room {
7273
updatedAt DateTime @updatedAt
7374
name String @id @unique @default(cuid())
7475
metadata String? @db.Text
76+
slug String?
7577
OwnerId String
7678
Owner User @relation(fields: [OwnerId], references: [id], onDelete: Cascade)
7779
summary String? @db.Text
7880
Participant Participant[]
81+
transcripts Transcript[]
7982
8083
@@index([OwnerId])
8184
}
8285

86+
model Transcript {
87+
id String @id @default(cuid())
88+
createdAt DateTime @default(now())
89+
updatedAt DateTime @updatedAt
90+
RoomName String
91+
Room Room @relation(fields: [RoomName], references: [name], onDelete: Cascade)
92+
text String @db.Text
93+
UserId String
94+
User User @relation(fields: [UserId], references: [id], onDelete: Cascade)
95+
96+
@@index([RoomName])
97+
@@index([UserId])
98+
}
99+
83100
model Participant {
84101
id String @id @default(cuid())
85102
createdAt DateTime @default(now())

src/pages/rooms/[name].tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import Pusher from "pusher-js";
1818
import useTranscribe from "~/hooks/useTranscribe";
1919
import Captions from "~/components/captions";
2020

21-
// THis is join room page, provide room name to join as a participant
22-
2321
const Home: NextPage = () => {
2422
const router = useRouter();
2523
const { name: roomName } = router.query;

src/server/api/routers/pusher.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ export const pusherRouter = createTRPCRouter({
2727
senderId: user.id,
2828
}
2929
);
30+
ctx.prisma.room.update({
31+
where: {
32+
name: input.roomName,
33+
},
34+
data: {
35+
transcripts: {
36+
create: {
37+
text: message,
38+
UserId: user.id,
39+
},
40+
},
41+
},
42+
});
3043
return response;
3144
}),
3245
});

src/server/api/routers/rooms.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import {
2424
import { TokenResult } from "~/lib/type";
2525
import { CreateRoomRequest } from "livekit-server-sdk/dist/proto/livekit_room";
2626
const roomClient = new RoomServiceClient(apiHost, apiKey, apiSecret);
27+
const configuration = new Configuration({
28+
apiKey: process.env.OPEN_API_SECRET,
29+
});
30+
import { Configuration, OpenAIApi } from "openai";
31+
const openai = new OpenAIApi(configuration);
2732
export const roomsRouter = createTRPCRouter({
2833
joinRoom: protectedProcedure
2934
.input(
@@ -49,6 +54,24 @@ export const roomsRouter = createTRPCRouter({
4954
identity,
5055
accessToken: token,
5156
};
57+
try {
58+
ctx.prisma.participant.create({
59+
data: {
60+
User: {
61+
connect: {
62+
id: ctx.session.user.id,
63+
},
64+
},
65+
Room: {
66+
connect: {
67+
name: roomName,
68+
},
69+
},
70+
},
71+
});
72+
} catch (error) {
73+
console.log(error);
74+
}
5275

5376
return result;
5477
}),
@@ -82,4 +105,65 @@ export const roomsRouter = createTRPCRouter({
82105

83106
return result;
84107
}),
108+
getRoomsByUser: protectedProcedure.query(async ({ ctx }) => {
109+
const rooms = await ctx.prisma.room.findMany({
110+
where: {
111+
OR: [
112+
{
113+
Owner: {
114+
id: ctx.session.user.id,
115+
},
116+
},
117+
{
118+
Participant: {
119+
some: {
120+
User: {
121+
id: ctx.session.user.id,
122+
},
123+
},
124+
},
125+
},
126+
],
127+
},
128+
});
129+
130+
return rooms;
131+
}),
132+
getRoomSummary: protectedProcedure
133+
.input(
134+
z.object({
135+
roomName: z.string(),
136+
})
137+
)
138+
.query(async ({ input, ctx }) => {
139+
// order all transcripts by createdAt in ascending order
140+
const transcripts = await ctx.prisma.transcript.findMany({
141+
where: {
142+
Room: {
143+
name: input.roomName,
144+
},
145+
},
146+
include: {
147+
User: true,
148+
},
149+
orderBy: {
150+
createdAt: "asc",
151+
},
152+
});
153+
const chatLog = transcripts
154+
.map((transcript) => `${transcript.User.name} : ${transcript.text}`)
155+
.join("\n");
156+
const prompt = `generate a summarization of the transcript of a meeting conversation below in english:\n${chatLog}`;
157+
const completion = await openai.createCompletion({
158+
model: "text-davinci-002",
159+
prompt: prompt,
160+
temperature: 0.7,
161+
top_p: 1,
162+
frequency_penalty: 0,
163+
presence_penalty: 0,
164+
max_tokens: 256,
165+
});
166+
console.log(completion);
167+
return completion;
168+
}),
85169
});

0 commit comments

Comments
 (0)