Skip to content

Commit

Permalink
Merge pull request #26 from LetsExercise/feat-openai-point
Browse files Browse the repository at this point in the history
Feat openai point
  • Loading branch information
castberry10 authored Aug 6, 2024
2 parents 6cf8844 + 3bbe1d7 commit 66fc037
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 8 deletions.
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"axios": "^1.7.3",
"firebase": "^10.12.3",
"next": "14.2.5",
"react": "^18",
Expand Down
49 changes: 49 additions & 0 deletions src/app/api/openai/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { NextResponse } from 'next/server';
import axios from 'axios';

export async function POST(request) {
const { goal, status } = await request.json();

try {
const response = await axios.post(
'https://api.openai.com/v1/chat/completions',
{
model: 'gpt-4o-mini',
messages: [
{
role: 'system',
content: '너는 운동, 식단, 잠관리를 해주는 앱의 어시스턴트야.'
},
{
role: 'user',
content: `
goal: ${JSON.stringify(goal)}
status: ${JSON.stringify(status)}
위의 goal과 status를 0부터 100까지의 점수로 변환해줘.
goal은 사용자가 지정한 목표를 나타내고, status는 사용자의 현재 상태를 나타내.
0은 아무것도 하지 않았거나 아무것도 달성하지 못했을 때, 100은 목표를 완벽하게 달성했을 때를 의미해.
칼로리가 너무 적거나 너무 커도, 자는 시간이 너무 적거나 너무 많아도 안돼.
운동은 얼마나 하든 괜찮아
프로그램에서 사용되는거니까 다른말은 하지말고 0부터 100까지의 정수로만 변환해줘.
`
}
],
max_tokens: 256,
temperature: 0.7,
},
{
headers: {
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
'Content-Type': 'application/json',
},
}
);

const score = response.data.choices[0].message.content.trim();
return NextResponse.json({ score });
} catch (error) {
console.error(error);
return NextResponse.json({ error: 'Error generating score' }, { status: 500 });
}
}
9 changes: 2 additions & 7 deletions src/app/layout.module.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
.child {
// background-color: red;
width: 390px;
// border: 1px solid #000;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
}

.parent {
// background-color: blue;
width: 100%;
display: flex;
justify-content: center;
// shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);

justify-content: center;
}
1 change: 1 addition & 0 deletions src/app/page.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.main {
display: flex;
height: 100vh;
flex-direction: column;
justify-content: space-around;
align-items: center;
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function Home() {
<div />
<div>
<Logo />
<h3>수면, 음식, 운동</h3>
<h3>수면, 식단, 운동</h3>
<div>나만의 펫과 함께</div>
<div>오늘 하루를 활동해 볼까요?</div>
</div>
Expand Down

0 comments on commit 66fc037

Please sign in to comment.