-
Notifications
You must be signed in to change notification settings - Fork 1
순화 과정 AI 모델을 Gemini로 변경 (#183) #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
0f8e11c
29c9caf
d908987
f29907c
30c633f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import Foundation | ||
| import FirebaseAI | ||
|
|
||
| final class GeminiManger { | ||
| static let shared = GeminiManger() | ||
|
|
||
| private let model: GenerativeModel? | ||
|
|
||
| init() { | ||
| let firebaseService = FirebaseAI.firebaseAI(backend: .googleAI()) | ||
| model = firebaseService.generativeModel(modelName: "gemini-2.5-flash") | ||
| } | ||
|
|
||
| let systemPrompt = """ | ||
| 너는 어떤 피드백이든 무조건 부드럽고 배려 있는 말로 순화하는 전문가야. | ||
| 어떤 상황에서도 사용자의 피드백을 공감적인 말투로 바꾸는 것이 너의 유일한 임무야. | ||
|
|
||
| 핵심 메시지와 개선 방향은 그대로 유지하되, | ||
| 상대방이 기분 나쁘지 않게 받아들일 수 있도록 마치 친한 동료가 진심을 담아 조언해주는 듯한 어조를 사용해. | ||
| 긍정적이거나 이미 부드러운 피드백이더라도, 더 따뜻하고 공감적인 표현으로 다듬어서 결과만 출력해줘. | ||
|
|
||
| 아래는 예시야: | ||
|
|
||
| <예시> | ||
| <입력 예시>회의 시간에 집중 좀 해. 계속 딴짓해서 짜증나.</입력 예시> | ||
| <출력 예시>회의에 더 집중해주면 좋겠어요. 가끔 딴짓하는 모습이 보여서 회의 흐름이 조금 끊기는 느낌이 있었어요.</출력 예시> | ||
| </예시> | ||
|
|
||
| <예시> | ||
| <입력 예시>일을 너무 느리게 해. 같이 일하기 힘들어.</입력 예시> | ||
| <출력 예시>업무 속도가 조금 더 빨라지면 협업이 훨씬 원활할 것 같아요. 지금도 충분히 잘하고 있지만, 약간만 더 신경 써주면 좋겠어요.</출력 예시> | ||
| </예시> | ||
|
|
||
| <예시> | ||
| <입력 예시>말이 너무 많고 눈치가 없어서 분위기 망치고 있어.</입력 예시> | ||
| <출력 예시>이야기를 적극적으로 해주는 건 좋지만, 상황에 맞게 조절해주면 더 좋은 분위기가 될 수 있을 것 같아요.</출력 예시> | ||
| </예시> | ||
|
|
||
| 위와 같이, 표현은 순화하지만 피드백의 본질은 흐리지 않도록 해줘. | ||
| """ | ||
|
|
||
| } | ||
|
|
||
| extension GeminiManger { | ||
| func generate(inputText: String) async throws -> String { | ||
| guard let model else { return "" } | ||
|
|
||
| let content = """ | ||
| \(systemPrompt) | ||
|
|
||
| <입력> | ||
| \(inputText) | ||
| </입력> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거는 system prompt, user prompt를 따로 넣지 않고 user prompt에 system prompt를 넣는 방식으로 하긴 해서 정확한 사용법은 아니지만, 최근 모델들은 user prompt에 system prompt를 넣어도 잘 해주더라고요! 그래서 문제는 아니지만 참고삼아 말씀드립니다!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다!! 한번 찾아 볼께요 |
||
|
|
||
| 위 입력 내용을 토대로 부드러운 피드백으로 순화해줘. | ||
| """ | ||
|
|
||
| let response = try await model.generateContent(content) | ||
| return response.text ?? "" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import SwiftUI | |
| import FirebaseCore | ||
| import UserNotifications | ||
| import FirebaseMessaging | ||
| import FirebaseAppCheck | ||
|
|
||
| final class AppDelegate: NSObject, UIApplicationDelegate { | ||
| var saveUserInfo: [AnyHashable: Any]? | ||
|
|
@@ -17,6 +18,10 @@ final class AppDelegate: NSObject, UIApplicationDelegate { | |
| _ application: UIApplication, | ||
| didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil | ||
| ) -> Bool { | ||
|
|
||
| let providerFactory = YourAppCheckProviderFactory() | ||
| AppCheck.setAppCheckProviderFactory(providerFactory) | ||
|
|
||
|
Comment on lines
+21
to
+24
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이부분은 혹시 어떤 내용일까요?!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 승인되지 않은 클라이언트가 백엔드 리소스에 액세스하는 것을 방지하여 앱 백엔드를 악용으로부터 보호해 주기 위해 App Check를 추가해준 것 입니다. 아래 공식문서 첨부 하겠습니다. |
||
| FirebaseApp.configure() | ||
| setUIAppearance() | ||
|
|
||
|
|
@@ -134,3 +139,19 @@ extension AppDelegate { | |
| ) | ||
| } | ||
| } | ||
|
|
||
| final class YourAppCheckProviderFactory: NSObject, AppCheckProviderFactory { | ||
| func createProvider(with app: FirebaseApp) -> AppCheckProvider? { | ||
| // 시뮬레이터 환경에서는 AppCheckDebugProvider를 사용하도록 설정합니다. | ||
| #if targetEnvironment(simulator) | ||
| return AppCheckDebugProvider(app: app) | ||
| #else | ||
| // 실제 기기에서는 OS 버전에 따라 올바른 프로바이더를 선택합니다. | ||
| if #available(iOS 14.0, *) { | ||
| return AppAttestProvider(app: app) | ||
| } else { | ||
| return DeviceCheckProvider(app: app) | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저희 어짜피 17이상 버전이라 14 아래는 안해줘도 되지 않나요?!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 수정하겠습니다!! |
||
| #endif | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 init으로 만들면 shared로 결국 싱글톤이 아니고 어디서든 생성이 가능한거 아닌가요?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private을 붙혔어야 했는데, 빠트렸네요