Skip to content

Commit

Permalink
Fix: AI Prompt 파일 암호화 방식 변경 및 그에 따른 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjiw0n committed Feb 15, 2024
1 parent d9cfc88 commit c3c0939
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 51 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Decrypt CHICHI file
run: openssl aes-256-cbc -d -in src/main/resources/AIPrompt/CHICHI.txt.enc -out src/main/resources/AIPrompt/CHICHI.txt -pass pass:${{ secrets.PROMPT_SECRET_PASSWORD }}

- name: Decrypt DADA file
run: openssl aes-256-cbc -d -in src/main/resources/AIPrompt/DADA.txt.enc -out src/main/resources/AIPrompt/DADA.txt -pass pass:${{ secrets.PROMPT_SECRET_PASSWORD }}

- name: Decrypt LULU file
run: openssl aes-256-cbc -d -in src/main/resources/AIPrompt/LULU.txt.enc -out src/main/resources/AIPrompt/LULU.txt -pass pass:${{ secrets.PROMPT_SECRET_PASSWORD }}
- name: Run Java Application
run: java -jar your-app.jar
env:
AIPROMPT_CHICHI: ${{ secrets.AIPROMPT_CHICHI }}
AIPROMPT_DADA: ${{ secrets.AIPROMPT_DADA }}
AIPROMPT_LULU: ${{ secrets.AIPROMPT_LULU }}

- name: Build with Gradle
run: ./gradlew --warning-mode all build -i
Expand Down
39 changes: 0 additions & 39 deletions src/main/java/com/kuit/chatdiary/AIPrompt.java

This file was deleted.

34 changes: 30 additions & 4 deletions src/main/java/com/kuit/chatdiary/service/OpenAIService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kuit.chatdiary.service;

import com.kuit.chatdiary.AIPrompt;
import com.kuit.chatdiary.domain.Chat;
import com.kuit.chatdiary.domain.ChatType;
import com.kuit.chatdiary.domain.Member;
Expand All @@ -22,6 +21,15 @@ public class OpenAIService {
@Value("${OPEN_AI_KEY}")
private String OPEN_AI_KEY;

@Value("${AIPROMPT_CHICHI}")
private String AIPROMPT_CHICHI;

@Value("${AIPROMPT_DADA}")
private String AIPROMPT_DADA;

@Value("${AIPROMPT_LULU}")
private String AIPROMPT_LULU;

@Autowired
private ChatRepository chatRepository;

Expand All @@ -37,15 +45,20 @@ public String getCompletion(Long userId, Integer model, Member member) {

List<Map<String, Object>> messages = new ArrayList<>();

String sender = String.valueOf(Sender.getByIndex(model));
String nickname = member.getNickname();
String gender = member.getGender();
String age = String.valueOf(member.getAge());
String prompt = AIPrompt.valueOf(sender).getPrompt(nickname, gender, age);
String userPrompt = createUserPrompt(nickname, gender, age);
String prompt = switch (model) {
case 1 -> AIPROMPT_DADA;
case 2 -> AIPROMPT_CHICHI;
case 3 -> AIPROMPT_LULU;
default -> throw new IllegalStateException("Unexpected value: " + model);
};

Map<String, Object> systemMessage = new HashMap<>();
systemMessage.put("role", "system");
systemMessage.put("content", prompt);
systemMessage.put("content", userPrompt + prompt);
messages.add(systemMessage);

List<Map<String, Object>> previousMessages = getRecentMessages(userId);
Expand Down Expand Up @@ -109,4 +122,17 @@ private Map<String, Object> getImagePart(String content) {
return imagePart;
}

public String createUserPrompt(String nickname, String gender, String age) {
String prompt = "You talk with a friend named '{nickname}' who is a {gender}, {age} years old.\n";
prompt = prompt.replace("{nickname}", defaultValue(nickname, "사용자"))
.replace("{gender}", defaultValue(gender, "Unknown"))
.replace("{age}", defaultValue(age, "Unknown"));
return prompt;
}

private String defaultValue(String value, String defaultValue) {
return (value != null) ? value : defaultValue;
}


}
Binary file removed src/main/resources/AIPrompt/CHICHI.txt.enc
Binary file not shown.
Binary file removed src/main/resources/AIPrompt/DADA.txt.enc
Binary file not shown.
Binary file removed src/main/resources/AIPrompt/LULU.txt.enc
Binary file not shown.

0 comments on commit c3c0939

Please sign in to comment.