Skip to content

Commit

Permalink
Merge branch 'develop' into feature/route
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 authored Apr 6, 2024
2 parents 9e206fc + e45e8ad commit 2444e6e
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 10 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
testImplementation 'org.springframework.security:spring-security-test'
// AI
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
// Json
implementation 'com.google.code.gson:gson:2.8.8'

implementation 'org.json:json:20210307'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.example.kukathonbackend.domain.commuting.domain;


import jakarta.persistence.*;
import lombok.*;
import org.example.kukathonbackend.domain.user.domain.User;
import org.example.kukathonbackend.domain.week.domain.Week;

import java.time.LocalDate;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
@Data
@Table(name = "commuting")
public class Commuting {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "commuting_id")
private Long id;

@Column(name = "date")
private LocalDate date ;


@Column(name = "commuting_time")
private Integer commutingTime;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "week_id")
private Week week;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.example.kukathonbackend.domain.recommend.application;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

import java.nio.charset.StandardCharsets;

public class Recommend {

public void SelfDevelopmentRecommend(String tagValue, Long time) {
CloseableHttpClient httpClient = HttpClients.createDefault();

try {
HttpPost request = new HttpPost("https://clovastudio.stream.ntruss.com/testapp/v1/chat-completions/HCX-003");

StringEntity params = new StringEntity("{\n" +
" \"messages\" : [ {\n" +
" \"role\" : \"system\",\n" +
" \"content\" : \"- 당신은 자기계발추천 전문가입니다.\\r\\n- 시간에 알맞은 자기계발활동을 추천합니다\\r\\n- 자기계발활동은 총 3개를 추천해야합니다.\\r\\n- 운동, 스트레칭같은 움직이는 활동은 추천하지 않습니다.\\r\\n- 지하철 및 버스같은 공공장소에서 할 수 있는 자기계발활동만을 추천합니다.\\n- 최대한 다양한 자기계발활동을 추천합니다.\\r\\n\\r\\ninput : 버스 및 지하철에서 30분 동안 할 수 있는 자기계발활동을 추천해줘\\r\\noutput : 자기계발서 독서하기 | 주식 공부하기 | 유튜브로 악기 공부하기\"\n" +
" }, {\n" +
" \"role\" : \"user\",\n" +
" \"content\" : \"input : 나는 " + tagValue + "을 가장 좋아해. 버스 및 지하철에서 " + time + "분 동안 할 수 있는 자기계발활동을 추천해줘\\r\\noutput : \"\n" +
" } ],\n" +
" \"topP\" : 0.8,\n" +
" \"topK\" : 0,\n" +
" \"maxTokens\" : 256,\n" +
" \"temperature\" : 0.8,\n" +
" \"repeatPenalty\" : 5.02,\n" +
" \"stopBefore\" : [ ],\n" +
" \"includeAiFilters\" : true,\n" +
" \"seed\" : 0\n" +
"}", ContentType.create("application/json", StandardCharsets.UTF_16));

request.setEntity(params);

request.addHeader("X-NCP-CLOVASTUDIO-API-KEY", "NTA0MjU2MWZlZTcxNDJiY63jYug0FDdswQfuPc3APjJSqVN89avhAcRqL1FVh6SB");
request.addHeader("X-NCP-APIGW-API-KEY", "eqXwFOLTnhQPnrdo8Iub3Y3ZCAUXFzbeolSBxPR1");
request.addHeader("X-NCP-CLOVASTUDIO-REQUEST-ID", "f7fb56ea-5a39-4f4a-b91f-c72972b68274");

HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();

if (entity != null) {
String result = EntityUtils.toString(entity);
JSONObject jsonResult = new JSONObject(result);
JSONObject resultObject = jsonResult.getJSONObject("result");
JSONObject messageObject = resultObject.getJSONObject("message");
String content = messageObject.getString("content");
System.out.println(content);
}

} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
httpClient.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import lombok.*;
import org.example.kukathonbackend.domain.user.domain.User;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
@Data
@Table(name = "route")
@Table(name = "commuting_route")
public class Route {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -24,17 +25,17 @@ public class Route {
@Column(name = "arrive_location")
private String arriveLocation;

@Column(name = "start_latitude")
private String startLatitude;
@Column(name = "start_latitude", precision = 10, scale = 8)
private BigDecimal startLatitude;

@Column(name = "start_longitude")
private String startLongitude;
@Column(name = "start_longitude", precision = 10, scale = 8)
private BigDecimal startLongitude;

@Column(name = "arrive_latitude")
private String arriveLatitude;
@Column(name = "arrive_latitude", precision = 10, scale = 8)
private BigDecimal arriveLatitude;

@Column(name = "arrive_longitude")
private String arriveLongitude;
@Column(name = "arrive_longitude", precision = 10, scale = 8)
private BigDecimal arriveLongitude;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.example.kukathonbackend.domain.tasklist.domain;

public enum TagEnum {
READING, // 독서
VIDEO_CONTENT, // 영상_컨텐츠
WEBTOON, // 웹툰
RELAXATION, // 휴식
STUDYING, // 공부
SNS, // SNS
OTHER // 기타
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.example.kukathonbackend.domain.tasklist.domain;


import jakarta.persistence.*;
import lombok.*;
import org.example.kukathonbackend.domain.commuting.domain.Commuting;
import org.example.kukathonbackend.domain.week.domain.Week;

import java.time.LocalDate;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
@Data
@Table(name = "task_list")
public class TaskList {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "task_id")
private Long id;

@Column(name = "task")
private String task;


@Column(name = "tag")
private TagEnum tag;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "commuting_id")
private Commuting commuting;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.example.kukathonbackend.domain.week.domain;


import jakarta.persistence.*;
import lombok.*;
import org.example.kukathonbackend.domain.user.domain.User;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
@Data
@Table(name = "week")
public class Week {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "week_id")
private Long id;

@Column(name = "start_day")
private String startDay;

@Column(name = "end_day")
private String endDay;

@Column(name = "goal")
private String goal;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.example.kukathonbackend.domain.weeklygoal.domain;


import jakarta.persistence.*;
import lombok.*;
import org.example.kukathonbackend.domain.week.domain.Week;

import java.time.LocalDate;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
@Data
@Table(name = "weekly_goal")
public class WeeklyGoal {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "weekly_goal_id")
private Long id;

@Column(name = "goal", columnDefinition = "TEXT")
private String goal;

@Column(name = "goal_success")
private Boolean goalSuccess;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "week_id")
private Week week;
}

0 comments on commit 2444e6e

Please sign in to comment.