Skip to content

Commit f5e767b

Browse files
committed
intital commit
1 parent cd2cce7 commit f5e767b

File tree

6 files changed

+133
-317
lines changed

6 files changed

+133
-317
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OPENAI_API_KEY=

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"next": "13.4.13",
13+
"openai": "^3.3.0",
1314
"react": "18.2.0",
1415
"react-dom": "18.2.0"
1516
}

pages/api/generate.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Configuration, OpenAIApi } from "openai";
2+
3+
const configuration = new Configuration({
4+
apiKey: process.env.OPENAI_API_KEY,
5+
});
6+
const openai = new OpenAIApi(configuration);
7+
8+
export default async function (req, res) {
9+
if (!configuration.apiKey) {
10+
res.status(500).json({
11+
error: {
12+
message:
13+
"OpenAI API key not configured, please follow instructions in README.md",
14+
},
15+
});
16+
return;
17+
}
18+
19+
const question = req.body.question || "";
20+
if (question.trim().length === 0) {
21+
res.status(400).json({
22+
error: {
23+
message: "Please enter a valid question",
24+
},
25+
});
26+
return;
27+
}
28+
29+
try {
30+
const completion = await openai.createChatCompletion({
31+
model: "gpt-3.5-turbo",
32+
messages: getMessages(question),
33+
temperature: 1,
34+
});
35+
console.log(completion.data.usage);
36+
res.status(200).json({
37+
result: completion.data.choices[0].message.content,
38+
});
39+
} catch (error) {
40+
// Consider adjusting the error handling logic for your use case
41+
if (error.response) {
42+
console.error(error.response.status, error.response.data);
43+
res.status(error.response.status).json(error.response.data);
44+
} else {
45+
console.error(`Error with OpenAI API request: ${error.message}`);
46+
res.status(500).json({
47+
error: {
48+
message: "An error occurred during your request.",
49+
},
50+
});
51+
}
52+
}
53+
}
54+
55+
const getMessages = (question) => {
56+
return [
57+
{
58+
role: "system",
59+
content:
60+
"You are a senior at punjab engineering college(pec), chandigarh and helping freshers during orientation. Address me as a new student as Punjab engineering college. Answer everything in a very informal way, you can also include some trending memes in your responses. Also, include some emojis in answers wherever relevant",
61+
},
62+
{ role: "user", content: "Tell me everything you know about pec" },
63+
{
64+
role: "assistant",
65+
content:
66+
"Step into Punjab Engineering College, where the journey of higher learning takes an amazing twist! Our classrooms and labs are like hidden treasure troves of knowledge,But hold up, some lab gadgets are like those forbidden candy jars, you just can't touch (xD, seriously!).The hostels are like your second home, but with Wi-Fi isn't as faster as your best friend's gossip- 6 in total, 4 for boys, 2 for girls. Boys' hostels are like boss-level comfort zones - no washing machines, but laundry adventures await! The college has more guys, around 84%, and awesome girls make up the remaining 16% - a diverse bunch! Imagine the big hall, also known as the auditorium, as a place where all the excitement and fun come together - just like a lively concert, but with an academic twist! Ah, the PEC ACM CSS, the coding society that's not just a club but a ticket to the learning wonderland and the best club of PEC (ofcourse you know!). Get ready to ride the rollercoaster of collaboration and learning, where your coding dreams take flight faster than you can say \"algorithm.\" As for the other clubs, well, let your curiosity roam wild and explore the uncharted territories of interests - they're all lined up, eagerly waiting for your discovery. The Career Development and Guidance Centre - they're like your career superheroes, helping you figure out what job path to take. They're the guiding stars encouraging you to tackle industrial challenges like a pro. Talking about stars, let's not forget relative grading, where you shine as bright as your peers, creating constellations of achievements. Imagine a library where books throw a party - that's PEC's library for you. So, gear up for a rollercoaster ride at Punjab Engineering College - where every day is a new level of \"OMG, did that just happen?!\"",
67+
},
68+
{ role: "user", content: question },
69+
];
70+
};

pages/index.js

Lines changed: 2 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Head from 'next/head'
2-
import Image from 'next/image'
32
import { Inter } from 'next/font/google'
43
import styles from '@/styles/Home.module.css'
54

@@ -9,105 +8,13 @@ export default function Home() {
98
return (
109
<>
1110
<Head>
12-
<title>Create Next App</title>
11+
<title>PECGPT</title>
1312
<meta name="description" content="Generated by create next app" />
1413
<meta name="viewport" content="width=device-width, initial-scale=1" />
1514
<link rel="icon" href="/favicon.ico" />
1615
</Head>
1716
<main className={`${styles.main} ${inter.className}`}>
18-
<div className={styles.description}>
19-
<p>
20-
Get started by editing&nbsp;
21-
<code className={styles.code}>pages/index.js</code>
22-
</p>
23-
<div>
24-
<a
25-
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
26-
target="_blank"
27-
rel="noopener noreferrer"
28-
>
29-
By{' '}
30-
<Image
31-
src="/vercel.svg"
32-
alt="Vercel Logo"
33-
className={styles.vercelLogo}
34-
width={100}
35-
height={24}
36-
priority
37-
/>
38-
</a>
39-
</div>
40-
</div>
41-
42-
<div className={styles.center}>
43-
<Image
44-
className={styles.logo}
45-
src="/next.svg"
46-
alt="Next.js Logo"
47-
width={180}
48-
height={37}
49-
priority
50-
/>
51-
</div>
52-
53-
<div className={styles.grid}>
54-
<a
55-
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
56-
className={styles.card}
57-
target="_blank"
58-
rel="noopener noreferrer"
59-
>
60-
<h2>
61-
Docs <span>-&gt;</span>
62-
</h2>
63-
<p>
64-
Find in-depth information about Next.js features and&nbsp;API.
65-
</p>
66-
</a>
67-
68-
<a
69-
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
70-
className={styles.card}
71-
target="_blank"
72-
rel="noopener noreferrer"
73-
>
74-
<h2>
75-
Learn <span>-&gt;</span>
76-
</h2>
77-
<p>
78-
Learn about Next.js in an interactive course with&nbsp;quizzes!
79-
</p>
80-
</a>
81-
82-
<a
83-
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
84-
className={styles.card}
85-
target="_blank"
86-
rel="noopener noreferrer"
87-
>
88-
<h2>
89-
Templates <span>-&gt;</span>
90-
</h2>
91-
<p>
92-
Discover and deploy boilerplate example Next.js&nbsp;projects.
93-
</p>
94-
</a>
95-
96-
<a
97-
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
98-
className={styles.card}
99-
target="_blank"
100-
rel="noopener noreferrer"
101-
>
102-
<h2>
103-
Deploy <span>-&gt;</span>
104-
</h2>
105-
<p>
106-
Instantly deploy your Next.js site to a shareable URL
107-
with&nbsp;Vercel.
108-
</p>
109-
</a>
110-
</div>
17+
<p>Made with ❤️ by PECACM</p>
11118
</main>
11219
</>
11320
)

0 commit comments

Comments
 (0)