Skip to content

Commit

Permalink
Merge pull request #22 from easy-lead/feat/#19
Browse files Browse the repository at this point in the history
Feat/#19
  • Loading branch information
oU-Ua authored Jul 30, 2024
2 parents 589ab6a + 06839aa commit 09fc9e8
Show file tree
Hide file tree
Showing 22 changed files with 822 additions and 11 deletions.
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

//이미지 저장을 위한 s3의존성
implementation platform('com.amazonaws:aws-java-sdk-bom:1.12.529')
implementation 'com.amazonaws:aws-java-sdk-s3'

//ocr을 위한 goolge vision 의존성
implementation 'com.google.cloud:google-cloud-vision:3.44.0'
implementation 'com.google.cloud:google-cloud-storage:2.10.0'

//health check를 위한 의존성
implementation("org.springframework.boot:spring-boot-starter-actuator")
}

tasks.named('test') {
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/easylead/easylead/common/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
@AllArgsConstructor
@Getter
public enum ErrorCode {
SERVER_ERROR("G500",HttpStatus.INTERNAL_SERVER_ERROR, "요청 수행 중 서버 에러 발생");

SERVER_ERROR("G500",HttpStatus.INTERNAL_SERVER_ERROR, "요청 수행 중 서버 에러 발생"),
// S3 관련 에러 코드
EMPTY_FILE_EXCEPTION("F500-1", HttpStatus.BAD_REQUEST, "빈 파일입니다."),
NO_FILE_EXTENTION("F500-2", HttpStatus.BAD_REQUEST, "확장자가 없습니다."),
INVALID_FILE_EXTENTION("F500-3", HttpStatus.BAD_REQUEST, "부적절한 확장자입니다."),
IO_EXCEPTION_ON_IMAGE_UPLOAD("F502-1", HttpStatus.INTERNAL_SERVER_ERROR, "이미지 업로드 중 에러가 발생했습니다."),
IO_EXCEPTION_ON_FILE_UPLOAD("F502-1", HttpStatus.INTERNAL_SERVER_ERROR, "파일 업로드 중 에러가 발생했습니다."),
PUT_OBJECT_EXCEPTION("F502-2", HttpStatus.INTERNAL_SERVER_ERROR, "S3에 이미지 업로드 중 에러가 발생했습니다."),
IO_EXCEPTION_ON_IMAGE_DELETE("F502-3", HttpStatus.INTERNAL_SERVER_ERROR, "이미지 삭제 중 에러가 발생했습니다.");

private final String errorCode;
private final HttpStatus httpStatusCode;
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/easylead/easylead/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.easylead.easylead.config;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class S3Config {
@Value("${cloud.aws.credentials.access-key}")
private String accessKey;
@Value("${cloud.aws.credentials.secret-key}")
private String secretKey;
@Value("${cloud.aws.region.static}")
private String region;

@Bean
public AmazonS3Client amazonS3Client() {
BasicAWSCredentials awsCredentials= new BasicAWSCredentials(accessKey, secretKey);
return (AmazonS3Client) AmazonS3ClientBuilder.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.easylead.easylead.domain.books.entity;

import com.easylead.easylead.common.entity.BaseEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.util.Date;

import static lombok.AccessLevel.PROTECTED;

@NoArgsConstructor(access = PROTECTED)
@SuperBuilder
@Builder
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Entity
@Getter
public class Book extends BaseEntity {
public class Book {
@Id
private String ISBN;
private String title;
private String writer;
private String publisher;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.easylead.easylead.domain.content.entity;

import com.easylead.easylead.domain.books.entity.Book;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import static jakarta.persistence.FetchType.LAZY;

@NoArgsConstructor()
@AllArgsConstructor
@Entity
@Getter
public class Content {
@EmbeddedId
private ContentId contentId;

@ManyToOne(fetch = LAZY)
@MapsId("ISBN")
@JoinColumn(name = "ISBN")
private Book book;

private String pageContent;
private String pageImg;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.easylead.easylead.domain.content.entity;

import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Embeddable
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ContentId implements Serializable {
private Long pageId;
private String ISBN;
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ public Flux<String> askCustomStream(String text) throws JsonProcessingException

List<Message> messages = new ArrayList<>();

// 시스템 역할 설정
messages.add(new Message("\"너는 입력받은 한국어를 쉬운 한국어로 변환해주는 도우미야. " +
"다음 조건들을 모두 충족하는 내용으로 변환해서 알려줘. \\\\n " +
"1. 입력받은 한국어 문장을 이해하기 쉬운 한국어 문장으로 변환해줘. " +
"2. 문장은 간결하게, 한 문장이 길어지면 두 문장으로 나눠서 변환해줘. " +
"3. 꾸미는 말 빼고, 이어진 문장은 두 개의 문장으로 변환해줘. " +
"4. 주어를 중심으로 알기 쉽게 변환해줘. " +
"5. 최대한 능동형 문장으로, 서술식의 구어체(-합니다, -입니다)로 변환해줘. " +
"6. 추상적 표현과 비유는 자제하도록 해. " +
"7. 이중부정 문장은 이해하기 쉬운 문장으로 바꿔. " +
"8. 한 문장에 한 줄씩 적어야해. " +
"9. 대화문은 문장 전후로 한 줄 띄어줘. " +
"10. 단어는 일상생활에서 자주 쓰는, 가능한 짧고 이해하기 쉬운 단어로 사용하도록 해. " +
"11. 한자어나 외국어를 풀어서 쉬운 말로 변환해. " +
"12. 약어가 있으면 다음 문장에 설명을 추가해.", "system"));

messages.add(new Message(text,"user"));

ChatGPTRequestDTO chatGptRequest = new ChatGPTRequestDTO(
Expand All @@ -228,9 +244,24 @@ public HttpRequest requestGPTCustom(String text) throws JsonProcessingException
List<Message> messages = new ArrayList<>();
// Assistant API 사용할지 Prompt를 변경할지 선택하기
// 시스템 역할 설정
messages.add(new Message("\"너는 입력받은 한국어를 쉬운 한국어로 변환해주는 도우미야. " +
"다음 조건들을 모두 충족하는 내용으로 변환해서 알려줘. \\\\n " +
"1. 입력받은 한국어 문장을 이해하기 쉬운 한국어 문장으로 변환해줘. " +
"2. 문장은 간결하게, 한 문장이 길어지면 두 문장으로 나눠서 변환해줘. " +
"3. 꾸미는 말 빼고, 이어진 문장은 두 개의 문장으로 변환해줘. " +
"4. 주어를 중심으로 알기 쉽게 변환해줘. " +
"5. 최대한 능동형 문장으로, 서술식의 구어체(-합니다, -입니다)로 변환해줘. " +
"6. 추상적 표현과 비유는 자제하도록 해. " +
"7. 이중부정 문장은 이해하기 쉬운 문장으로 바꿔. " +
"8. 한 문장에 한 줄씩 적어야해. " +
"9. 대화문은 문장 전후로 한 줄 띄어줘. " +
"10. 단어는 일상생활에서 자주 쓰는, 가능한 짧고 이해하기 쉬운 단어로 사용하도록 해. " +
"11. 한자어나 외국어를 풀어서 쉬운 말로 변환해. " +
"12. 약어가 있으면 다음 문장에 설명을 추가해.", "system"));

messages.add(new Message(text, "user"));

ChatGPTRequestDTO chatGptRequest = new ChatGPTRequestDTO("ft:gpt-3.5-turbo-0125:personal::9ldfWO0p", messages, 0.3,false);
ChatGPTRequestDTO chatGptRequest = new ChatGPTRequestDTO("ft:gpt-3.5-turbo-0613:personal::9prSIgJ8", messages, 0.3,false);
String input = null;
input = mapper.writeValueAsString(chatGptRequest);
System.out.println(input);
Expand Down Expand Up @@ -295,4 +326,30 @@ public String responseDalle(HttpRequest request) throws JsonProcessingException

}


public HttpRequest requestImgPrompt(String reqText) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
List<Message> messages = new ArrayList<>();
// Assistant API 사용할지 Prompt를 변경할지 선택하기
// 시스템 역할 설정
messages.add(new Message("너는 동화책 삽화에 대해 잘알고, 내용에 중요한 부분을 삽화 프롬프트로 작성할 수 있는 전문가야. ", "system"));

messages.add(new Message(reqText+"\n\n 이 내용을 토대로 동화책 삽화 1개만 그리고 싶어. 따뜻한 느낌의 동화책에 맞는 그림체로 삽화 만드는 프롬프트 작성해줘 ", "user"));

ChatGPTRequestDTO chatGptRequest = new ChatGPTRequestDTO("gpt-4", messages, 0.3,false);
String input = null;
input = mapper.writeValueAsString(chatGptRequest);
System.out.println(input);
System.out.println("apikey : " + gptApiKey);

HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.openai.com/v1/chat/completions"))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + gptApiKey)
.POST(HttpRequest.BodyPublishers.ofString(input))
.build();

return request;
}

}
43 changes: 43 additions & 0 deletions src/main/java/com/easylead/easylead/domain/read/entity/Read.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.easylead.easylead.domain.read.entity;

import com.easylead.easylead.domain.books.entity.Book;
import com.easylead.easylead.domain.users.entity.Users;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

import static jakarta.persistence.FetchType.LAZY;
import static lombok.AccessLevel.PROTECTED;

@Builder
@AllArgsConstructor
@EqualsAndHashCode
@NoArgsConstructor(access = PROTECTED)
@Getter
@Entity
public class Read {
@EmbeddedId
private ReadId readId;

@ManyToOne(fetch = LAZY)
@MapsId("userId")
@JoinColumn(name = "read_user_id")
private Users readUser;

@ManyToOne(fetch = LAZY)
@MapsId("ISBN")
@JoinColumn(name = "ISBN")
private Book book;

private Long page;

@CreationTimestamp
@Column(nullable = false, updatable = false)
private LocalDateTime createdAt;

@UpdateTimestamp
private LocalDateTime updateAt;
}
19 changes: 19 additions & 0 deletions src/main/java/com/easylead/easylead/domain/read/entity/ReadId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.easylead.easylead.domain.read.entity;

import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Embeddable
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ReadId implements Serializable {
private Long userId;
private String ISBN;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.easylead.easylead.domain.request.entity;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum Progress {
P0("접수 완료"),
P1("담당자 확인 중"),
P2("글맞춤 중"),
P3("검수 중"),
P4("글맞춤 완료");

private final String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.easylead.easylead.domain.request.entity;

import com.easylead.easylead.domain.books.entity.Book;
import com.easylead.easylead.domain.users.entity.Users;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

import static jakarta.persistence.FetchType.LAZY;
import static lombok.AccessLevel.PROTECTED;

@Builder
@AllArgsConstructor
@EqualsAndHashCode
@NoArgsConstructor(access = PROTECTED)
@Getter
@Entity
public class Request {
@EmbeddedId
private RequestId requestId;

@ManyToOne(fetch = LAZY)
@MapsId("userId")
@JoinColumn(name = "user_id")
private Users readUser;

@ManyToOne(fetch = LAZY)
@MapsId("ISBN")
@JoinColumn(name = "ISBN")
private Book book;

@Enumerated(EnumType.STRING)
private Progress progress;

@CreationTimestamp
@Column(nullable = false, updatable = false)
private LocalDateTime createdAt;

@UpdateTimestamp
private LocalDateTime updateAt;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.easylead.easylead.domain.request.entity;

import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Embeddable
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class RequestId implements Serializable {
private Long userId;
private String ISBN;
}
Loading

0 comments on commit 09fc9e8

Please sign in to comment.