Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2ab507a
feat: ChatBubbleView 구현
earths-voluble Apr 4, 2024
916816b
feat: MessageView 구현
earths-voluble Apr 4, 2024
48aa667
feat: ChatBubbleView 및 MessageView 구현
earths-voluble Apr 5, 2024
e21c6ef
add: CollectionView 구성 파일 추가
Changhyun-Kyle Apr 6, 2024
76d7e69
refine: MockData 파싱으로 변경
Changhyun-Kyle Apr 6, 2024
672954f
feat: 채팅 리스트 구현
Changhyun-Kyle Apr 6, 2024
2234a2a
Merge branch 'develop' into Step3
Changhyun-Kyle Apr 8, 2024
7ea3c9a
Merge pull request #4 from Changhyun-Kyle/Step3
Changhyun-Kyle Apr 8, 2024
1b08502
chore: MockData 추가
Changhyun-Kyle Apr 8, 2024
2f41b50
chore: MockData 반영 로직 추가
Changhyun-Kyle Apr 8, 2024
f48bd66
chore: isHidden 추가
Changhyun-Kyle Apr 8, 2024
ad47d2d
feat: 자동 스크롤 기능 구현
Changhyun-Kyle Apr 8, 2024
02c23c0
feat: UICollectionView 구분선 제거 및 선택 효과 삭제
Changhyun-Kyle Apr 8, 2024
6e7b29b
fix: 메세지 뷰 버그 수정
Changhyun-Kyle Apr 8, 2024
5430115
feat: ChatInputView 구현
earths-voluble Apr 9, 2024
ef9b4f3
feat: ChatInputView 오토 레이아웃 추가
earths-voluble Apr 9, 2024
2389e00
chore: ChatSendButton -> ChatInputSendButton으로 네이밍 변경
earths-voluble Apr 9, 2024
b353ade
chore: UITextViewDelegate 수정
earths-voluble Apr 11, 2024
11c4a23
feat: 소프트웨어 키보드 표시 시 레이아웃 수정
earths-voluble Apr 11, 2024
eec2041
feat: 화면 터치 시 키보드 숨김 기능 추가
earths-voluble Apr 11, 2024
22621e7
refine: 실제 네트워크 통신 로직으로 변경
Changhyun-Kyle Apr 14, 2024
0055729
feat: requestDTO 추가
Changhyun-Kyle Apr 14, 2024
193ac2a
feat: 메세지 버블 뷰 기능 구현
Changhyun-Kyle Apr 14, 2024
513a18d
feat: RequestDTO 구현
Changhyun-Kyle Apr 14, 2024
35fbc11
refine: 메세지 버블 뷰 수정
Changhyun-Kyle Apr 14, 2024
a9e6f8a
chore: 코드 컨벤션에 맞게 수정
Changhyun-Kyle Apr 14, 2024
63bb864
refactor: 키보드 관련 이벤트 메서드 분리
Changhyun-Kyle Apr 14, 2024
94d547c
chore: 불필요 Delegate 삭제
Changhyun-Kyle Apr 14, 2024
2362a16
refine: 메세지 버블 뷰 수정
Changhyun-Kyle Apr 14, 2024
5c47291
refactor: 키보드 관련 이벤트 메서드 분리
Changhyun-Kyle Apr 14, 2024
f8f76bf
chore: 불필요 주석 제거
Changhyun-Kyle Apr 14, 2024
7fd3fc4
fix: Request Body 생성 오류 수정
Changhyun-Kyle Apr 14, 2024
e662dd2
Merge pull request #6 from Changhyun-Kyle/Step3
Changhyun-Kyle Apr 14, 2024
914b98c
refactor: ChattingView 구현 후 ViewController 로직 분기
Changhyun-Kyle Apr 21, 2024
f5b8308
refine: ChatBubbleMakable 생성 및 MessageView 네이밍 변경
Changhyun-Kyle Apr 21, 2024
9995476
chore: extension 구현부 수정
Changhyun-Kyle Apr 21, 2024
0fa8156
refactor: ChatBubbleMakable 프로토콜 구현 및 분기 처리
Changhyun-Kyle Apr 21, 2024
fe71b9d
chore: MessageView 네이밍 수정
Changhyun-Kyle Apr 21, 2024
fe7de10
fix: prepareReuse를 활용한 메세지 뷰 버그 수정
Changhyun-Kyle Apr 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions ChatBot/ChatBot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
2770189E2BCBF4A20040A6A9 /* UIViewController+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2770189D2BCBF4A20040A6A9 /* UIViewController+.swift */; };
27E09B7B2BD4F1A000C37C48 /* ChattingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E09B7A2BD4F1A000C37C48 /* ChattingView.swift */; };
27E09B7D2BD50DD700C37C48 /* ChatBubbleMakable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E09B7C2BD50DD700C37C48 /* ChatBubbleMakable.swift */; };
27EFEA4F2BBC174D004A3426 /* ChatBotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27EFEA4E2BBC174D004A3426 /* ChatBotTests.swift */; };
27EFEA562BBD3EDB004A3426 /* ChatBotNetworkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27EFEA552BBD3EDB004A3426 /* ChatBotNetworkTests.swift */; };
27EFEA612BBD6D75004A3426 /* Bundle+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27EFEA602BBD6D75004A3426 /* Bundle+.swift */; };
Expand All @@ -22,6 +25,14 @@
27EFEA7B2BBD7DC3004A3426 /* MockURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27EFEA7A2BBD7DC3004A3426 /* MockURLSession.swift */; };
27EFEA7D2BBD7DFD004A3426 /* NetworkTestable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27EFEA7C2BBD7DFC004A3426 /* NetworkTestable.swift */; };
27EFEA7F2BBE44AA004A3426 /* NetworkURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27EFEA7E2BBE44AA004A3426 /* NetworkURL.swift */; };
27EFEA832BBFD813004A3426 /* ChatCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27EFEA822BBFD813004A3426 /* ChatCollectionView.swift */; };
27EFEA852BBFD836004A3426 /* ChatCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27EFEA842BBFD836004A3426 /* ChatCell.swift */; };
27EFEA872BBFDD0F004A3426 /* ChatCollectionViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27EFEA862BBFDD0F004A3426 /* ChatCollectionViewDataSource.swift */; };
893621222BC4014D00EFB2C7 /* ChatInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 893621212BC4014D00EFB2C7 /* ChatInputView.swift */; };
893621242BC4017F00EFB2C7 /* ChatInputTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 893621232BC4017F00EFB2C7 /* ChatInputTextView.swift */; };
893621262BC40E5500EFB2C7 /* ChatInputSendButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 893621252BC40E5500EFB2C7 /* ChatInputSendButton.swift */; };
89510A662BBE938700354947 /* ChatBubbleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89510A652BBE938700354947 /* ChatBubbleView.swift */; };
89510A682BBE9BC400354947 /* MessageLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89510A672BBE9BC400354947 /* MessageLabel.swift */; };
89A49A642BB4233C00C643D3 /* ResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89A49A632BB4233C00C643D3 /* ResponseModel.swift */; };
89A49A662BB426ED00C643D3 /* RequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89A49A652BB426ED00C643D3 /* RequestModel.swift */; };
89A49A682BB4272600C643D3 /* Choice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89A49A672BB4272600C643D3 /* Choice.swift */; };
Expand All @@ -45,6 +56,9 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
2770189D2BCBF4A20040A6A9 /* UIViewController+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+.swift"; sourceTree = "<group>"; };
27E09B7A2BD4F1A000C37C48 /* ChattingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChattingView.swift; sourceTree = "<group>"; };
27E09B7C2BD50DD700C37C48 /* ChatBubbleMakable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatBubbleMakable.swift; sourceTree = "<group>"; };
27EFEA4C2BBC174D004A3426 /* ChatBotTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ChatBotTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
27EFEA4E2BBC174D004A3426 /* ChatBotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatBotTests.swift; sourceTree = "<group>"; };
27EFEA552BBD3EDB004A3426 /* ChatBotNetworkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatBotNetworkTests.swift; sourceTree = "<group>"; };
Expand All @@ -62,6 +76,14 @@
27EFEA7A2BBD7DC3004A3426 /* MockURLSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockURLSession.swift; sourceTree = "<group>"; };
27EFEA7C2BBD7DFC004A3426 /* NetworkTestable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkTestable.swift; sourceTree = "<group>"; };
27EFEA7E2BBE44AA004A3426 /* NetworkURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkURL.swift; sourceTree = "<group>"; };
27EFEA822BBFD813004A3426 /* ChatCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatCollectionView.swift; sourceTree = "<group>"; };
27EFEA842BBFD836004A3426 /* ChatCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatCell.swift; sourceTree = "<group>"; };
27EFEA862BBFDD0F004A3426 /* ChatCollectionViewDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatCollectionViewDataSource.swift; sourceTree = "<group>"; };
893621212BC4014D00EFB2C7 /* ChatInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatInputView.swift; sourceTree = "<group>"; };
893621232BC4017F00EFB2C7 /* ChatInputTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatInputTextView.swift; sourceTree = "<group>"; };
893621252BC40E5500EFB2C7 /* ChatInputSendButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatInputSendButton.swift; sourceTree = "<group>"; };
89510A652BBE938700354947 /* ChatBubbleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatBubbleView.swift; sourceTree = "<group>"; };
89510A672BBE9BC400354947 /* MessageLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageLabel.swift; sourceTree = "<group>"; };
89A49A632BB4233C00C643D3 /* ResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseModel.swift; sourceTree = "<group>"; };
89A49A652BB426ED00C643D3 /* RequestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestModel.swift; sourceTree = "<group>"; };
89A49A672BB4272600C643D3 /* Choice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Choice.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -135,6 +157,7 @@
children = (
27EFEA602BBD6D75004A3426 /* Bundle+.swift */,
27EFEA6B2BBD7B32004A3426 /* URLSession+.swift */,
2770189D2BCBF4A20040A6A9 /* UIViewController+.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -180,6 +203,23 @@
path = Mock;
sourceTree = "<group>";
};
89510A642BBE934E00354947 /* View */ = {
isa = PBXGroup;
children = (
89510A652BBE938700354947 /* ChatBubbleView.swift */,
27E09B7C2BD50DD700C37C48 /* ChatBubbleMakable.swift */,
89510A672BBE9BC400354947 /* MessageLabel.swift */,
27EFEA822BBFD813004A3426 /* ChatCollectionView.swift */,
27EFEA842BBFD836004A3426 /* ChatCell.swift */,
27EFEA862BBFDD0F004A3426 /* ChatCollectionViewDataSource.swift */,
893621212BC4014D00EFB2C7 /* ChatInputView.swift */,
893621252BC40E5500EFB2C7 /* ChatInputSendButton.swift */,
893621232BC4017F00EFB2C7 /* ChatInputTextView.swift */,
27E09B7A2BD4F1A000C37C48 /* ChattingView.swift */,
);
path = View;
sourceTree = "<group>";
};
89A49A622BB422DF00C643D3 /* Model */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -232,6 +272,7 @@
isa = PBXGroup;
children = (
273615912BB2A496004C3F15 /* App */,
89510A642BBE934E00354947 /* View */,
89A49A622BB422DF00C643D3 /* Model */,
27EFEA732BBD7BB0004A3426 /* ViewModel */,
273615922BB2A4A7004C3F15 /* Controller */,
Expand Down Expand Up @@ -356,18 +397,29 @@
27EFEA6C2BBD7B32004A3426 /* URLSession+.swift in Sources */,
27EFEA792BBD7DA1004A3426 /* MockDataSample.swift in Sources */,
27EFEA7F2BBE44AA004A3426 /* NetworkURL.swift in Sources */,
27E09B7D2BD50DD700C37C48 /* ChatBubbleMakable.swift in Sources */,
893621222BC4014D00EFB2C7 /* ChatInputView.swift in Sources */,
B4B3E2C12B42D1BB00818B3C /* ChatBotViewController.swift in Sources */,
89510A682BBE9BC400354947 /* MessageLabel.swift in Sources */,
27EFEA7D2BBD7DFD004A3426 /* NetworkTestable.swift in Sources */,
27EFEA872BBFDD0F004A3426 /* ChatCollectionViewDataSource.swift in Sources */,
27EFEA832BBFD813004A3426 /* ChatCollectionView.swift in Sources */,
B4B3E2BD2B42D1BB00818B3C /* AppDelegate.swift in Sources */,
27EFEA7B2BBD7DC3004A3426 /* MockURLSession.swift in Sources */,
27EFEA6A2BBD7B17004A3426 /* HttpMethod.swift in Sources */,
27EFEA702BBD7B7D004A3426 /* JSONHandler.swift in Sources */,
27EFEA682BBD7AF3004A3426 /* APIType.swift in Sources */,
89A49A6A2BB4273700C643D3 /* Usage.swift in Sources */,
89510A662BBE938700354947 /* ChatBubbleView.swift in Sources */,
27EFEA722BBD7B95004A3426 /* NetworkError.swift in Sources */,
27EFEA852BBFD836004A3426 /* ChatCell.swift in Sources */,
27EFEA752BBD7BC0004A3426 /* ChatViewModel.swift in Sources */,
893621262BC40E5500EFB2C7 /* ChatInputSendButton.swift in Sources */,
89A49A6C2BB4274B00C643D3 /* Message.swift in Sources */,
27EFEA612BBD6D75004A3426 /* Bundle+.swift in Sources */,
2770189E2BCBF4A20040A6A9 /* UIViewController+.swift in Sources */,
893621242BC4017F00EFB2C7 /* ChatInputTextView.swift in Sources */,
27E09B7B2BD4F1A000C37C48 /* ChattingView.swift in Sources */,
89A49A642BB4233C00C643D3 /* ResponseModel.swift in Sources */,
27EFEA6E2BBD7B53004A3426 /* NetworkService.swift in Sources */,
B4B3E2BF2B42D1BB00818B3C /* SceneDelegate.swift in Sources */,
Expand Down Expand Up @@ -560,7 +612,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = K9NKZR257N;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = ChatBot/Supportings/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -573,7 +625,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.tacocat.ChatBot;
PRODUCT_BUNDLE_IDENTIFIER = com.tacocat.ChatBot.test;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand All @@ -588,7 +640,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = K9NKZR257N;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = ChatBot/Supportings/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -601,7 +653,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.tacocat.ChatBot;
PRODUCT_BUNDLE_IDENTIFIER = com.tacocat.ChatBot.test;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand Down
38 changes: 21 additions & 17 deletions ChatBot/ChatBot/Controller/ChatBotViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,44 @@ import Combine
final class ChatBotViewController: UIViewController {

private let chatBotViewModel: ChatViewModel = .init()
private var cancellable = Set<AnyCancellable>()
private let chattingView: ChattingView = .init()
private var cancellable: Set<AnyCancellable> = .init()
private let input: PassthroughSubject<ChatViewModel.Input, Never> = .init()

override func viewDidLoad() {
super.viewDidLoad()
override func loadView() {
super.loadView()
self.view = chattingView
setupKeyboardNotification()
bind()
setupChatInputView()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
input.send(
.sendButtonTapped(
message: Message(
role: "user",
content: "Compose a poem that explains the concept of recursion in programming."
)
)
)

deinit {
NotificationCenter.default.removeObserver(self)
}
}

private extension ChatBotViewController {
func setupChatInputView() {
chattingView.setChatSendButton { [weak self] message in
self?.input.send(.sendButtonTapped(message: message))
guard let requestDTO = self?.chatBotViewModel.requestDTO else { return }
self?.chattingView.applyChatResponse(response: requestDTO)
}
}

func bind() {
let output = chatBotViewModel.transform(
input: input.eraseToAnyPublisher()
)
output.sink { event in
output.sink { [weak self] event in
switch event {
case .fetchChatResponseDidFail(let error):
print(error.localizedDescription)
case .fetchChatResponseDidSucceed(let response):
print(response.choices[0].message.content)
self?.chattingView.applyChatResponse(response: response)
case .toggleSendButton(let isEnable):
print("\(isEnable)")
self?.chattingView.isSendButtonEnable(isEnable)
}
}
.store(in: &cancellable)
Expand Down
61 changes: 61 additions & 0 deletions ChatBot/ChatBot/Extensions/UIViewController+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// UIViewController+.swift
// ChatBot
//
// Created by 강창현 on 4/14/24.
//

import UIKit

extension UIViewController {
func setupKeyboardNotification() {
NotificationCenter.default.addObserver(
self,
selector: #selector(self.keyboardWillShow),
name: UIResponder.keyboardWillShowNotification,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(self.keyboardWillHide),
name: UIResponder.keyboardWillHideNotification,
object: nil
)
addKeyboardGesture()
}

private func addKeyboardGesture() {
let tapGestureRecognizer = UITapGestureRecognizer(
target: self,
action: #selector(dismissKeyboard)
)
view.addGestureRecognizer(tapGestureRecognizer)
}

@objc
private func dismissKeyboard() {
view.endEditing(true)
}

@objc
private func keyboardWillShow(notification: NSNotification) {
guard
let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
else {
return
}

self.view.frame.size.height -= keyboardSize.height
}
Comment on lines +40 to +49
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보통 키보드 레이아웃 조절 시 view의 frame 자체를 움직이기 보단, scrollView의 contentInset을 조절해서 레이아웃을 구현하는 것이 좋습니다.
view의 frame 자체 직접 조절하게 되면, autolayout이 깨질 수 있고, 여러분들이 질문주신 것 처럼, 예상치 못한 UI와 관련된 문제들이 발생할 수 있습니다.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 ChattingView(UIView) 안에 CollectionViewChatInputViewadd 되어 있습니다. contentInset을 활용하기 위해선 UIScrollView를 상속한 View에서 작업이 이루어져야 하는데 그렇다면 ChattingViewUIView가 아닌 UIScrollView로 구현하거나 CollectionView 안에 ChatInputView를 add 해줘야 할까요??

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChattingView를 UIScrollView로 구현해보시면 좋을 것 같습니다ㅎㅎ


@objc
private func keyboardWillHide(notification: NSNotification) {
guard
let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
else {
return
}

self.view.frame.size.height += keyboardSize.height
}
}
2 changes: 1 addition & 1 deletion ChatBot/ChatBot/Model/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by 이보한 on 2024/3/27.
//

struct Message: Codable {
struct Message: Codable, Hashable {
let role: String
let content: String
}
18 changes: 9 additions & 9 deletions ChatBot/ChatBot/Model/Network/Mock/MockDataSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ enum MockDataSample {
content: "Compose a poem that explains the concept of recursion in programming."
),
Message(
role: "system",
content: "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."
role: "assistant",
content: "$s7Combine9PublisherPAAE4sink17receiveCompletion0D5ValueAA14AnyCancellableCyAA11SubscribersO0E0Oy_7FailureQzGc_y6OutputQzctF + 304"
),
Message(
role: "user",
content: "Compose a poem that explains the concept of recursion in programming."
content: "$s7ChatBot0A9ViewModelC05fetchaB4Data33_C3094975EA75902AF323554274754D0BLL4bodyyAA07RequestD0V_tF + 548"
),
Message(
role: "system",
content: "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."
role: "assistant",
content: "Y"
),
Message(
role: "user",
content: "Compose a poem that explains the concept of recursion in programming."
content: "ChatBot0A9ViewModelC9transform5input7Combine12AnyPublisherVyAC6OutputOs5NeverOGAHyAC5InputOALG_tFyAOcfU_ + 832"
),
Message(
role: "system",
content: "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."
role: "assistant",
content: "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Fatal: supplied item identifiers are not unique. Duplicate identifiers"
),
Message(
role: "user",
content: "Compose a poem that explains the concept of recursion in programming."
content: "17.4asdfasdfasdfasdfasdf"
),
]
)
Expand Down
3 changes: 2 additions & 1 deletion ChatBot/ChatBot/Model/Network/NetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct NetworkService: NetworkTestable {

private let session: URLSessionProtocol

init(session: URLSessionProtocol = MockURLSession(statusCode: 200)) {
init(session: URLSessionProtocol = URLSession.shared) {
self.session = session
}

Expand All @@ -29,3 +29,4 @@ struct NetworkService: NetworkTestable {
.eraseToAnyPublisher()
}
}

7 changes: 7 additions & 0 deletions ChatBot/ChatBot/Model/Request/RequestModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
// Created by 이보한 on 2024/3/27.
//

import Foundation

struct RequestModel: Codable {
var model: String = "gpt-3.5-turbo-1106"
var stream: Bool = false
var messages: [Message]
}

struct RequestDTO: Hashable {
let id: UUID
var message: Message
}
Loading