@@ -14,7 +14,7 @@ import reactor.core.scheduler.Schedulers
1414@Service
1515class RoomService (
1616 private val chatroomRepository : ChatroomRepository ,
17- private val officeroomRepository : OfficeroomRepository , // OfficeroomRepository 추가
17+ private val officeroomRepository : OfficeroomRepository ,
1818 private val webClient : WebClient .Builder
1919) {
2020
@@ -32,35 +32,58 @@ class RoomService(
3232 .bodyToMono(Map ::class .java)
3333 }
3434
35- fun addOfficeroom (
36- userid : String ,
37- mongo_officeroomid : String ,
38- input_data_set : String ,
39- output_data_set : String = "TESTING ⚠️TESTING ⚠️TESTING " // AI Model 도입 전임으로 임시로 설정
40- ): Mono <Map <* , * >> {
41-
42- val requestBody = mapOf (
43- " user_id" to userid,
44- " id" to mongo_officeroomid,
45- " input_data" to input_data_set,
46- " output_data" to output_data_set
35+ // Llama 모델로 input_data_set을 보내고 스트리밍 응답을 받는 함수
36+ private fun getLlamaResponse (inputDataSet : String ): Mono <String > {
37+ val llamaRequestBody = mapOf (
38+ " input_data" to inputDataSet
4739 )
4840
4941 return webClient.build()
50- .put ()
51- .uri(" /mongo/office/save_log " )
42+ .post ()
43+ .uri(" http://192.168.219.100:8000/Llama_stream " )
5244 .contentType(MediaType .APPLICATION_JSON )
53- .bodyValue(requestBody )
45+ .bodyValue(llamaRequestBody )
5446 .retrieve()
55- .bodyToMono(Map ::class .java)
47+ .bodyToFlux(String ::class .java) // 스트리밍 응답 받기
48+ .reduce { accumulated, chunk -> accumulated + chunk } // 스트림을 하나의 문자열로 합치기
49+ .map { response ->
50+ response.ifEmpty { " Llama 응답 실패" }
51+ }
52+ }
53+
54+
55+ fun addOfficeroom (
56+ userid : String ,
57+ mongo_officeroomid : String ,
58+ input_data_set : String
59+ ): Mono <Map <* , * >> {
60+
61+ // Llama 모델에 input_data_set을 보내고 응답을 받음
62+ return getLlamaResponse(input_data_set).flatMap { output_data_set ->
63+
64+ val requestBody = mapOf (
65+ " user_id" to userid,
66+ " id" to mongo_officeroomid,
67+ " input_data" to input_data_set,
68+ " output_data" to output_data_set
69+ )
70+
71+ webClient.build()
72+ .put()
73+ .uri(" /mongo/office/save_log" )
74+ .contentType(MediaType .APPLICATION_JSON )
75+ .bodyValue(requestBody)
76+ .retrieve()
77+ .bodyToMono(Map ::class .java)
78+ }
5679 }
5780
5881 fun saveOfficeroom (userid : String , mongo_officeroomid : String ): Officeroom {
5982 val newOfficeroom = Officeroom (
6083 userid = userid,
6184 mongo_officeroomid = mongo_officeroomid
6285 )
63- return officeroomRepository.save(newOfficeroom) // OfficeroomRepository를 사용하여 저장
86+ return officeroomRepository.save(newOfficeroom)
6487 }
6588
6689 fun saveChatroom (userid : String , charactersIdx : Int = 0, mongo_chatroomid : String ): Chatroom {
@@ -69,7 +92,7 @@ class RoomService(
6992 charactersIdx = charactersIdx,
7093 mongo_chatroomid = mongo_chatroomid
7194 )
72- return chatroomRepository.save(newChatroom) // ChatroomRepository를 사용하여 저장
95+ return chatroomRepository.save(newChatroom)
7396 }
7497
7598 fun loadOfficeroomLogs (userid : String , mongo_chatroomid : String ): Mono <Map <* , * >> {
@@ -80,68 +103,72 @@ class RoomService(
80103
81104 return webClient.build()
82105 .post()
83- .uri(" /mongo/office/load_log" ) // FastAPI 서버에서 로그를 불러오는 엔드포인트
106+ .uri(" /mongo/office/load_log" )
84107 .contentType(MediaType .APPLICATION_JSON )
85108 .bodyValue(requestBody)
86109 .retrieve()
87110 .bodyToMono(Map ::class .java)
88111 }
89112
90113 fun deleteOfficeroom (userid : String , mongo_officeroomid : String ): Mono <Map <* , * >> {
91- val requestBody = mapOf (
92- " user_id" to userid,
93- " id" to mongo_officeroomid
94- )
95-
96- return webClient.build()
97- .method(HttpMethod .DELETE )
98- .uri(" /mongo/office/delete_room" )
99- .contentType(MediaType .APPLICATION_JSON ) // 여기에서 contentType 설정
100- .bodyValue(requestBody)
101- .retrieve()
102- .bodyToMono(Map ::class .java)
114+ val requestBody = mapOf (
115+ " user_id" to userid,
116+ " id" to mongo_officeroomid
117+ )
118+
119+ return webClient.build()
120+ .method(HttpMethod .DELETE )
121+ .uri(" /mongo/office/delete_room" )
122+ .contentType(MediaType .APPLICATION_JSON )
123+ .bodyValue(requestBody)
124+ .retrieve()
125+ .bodyToMono(Map ::class .java)
103126 }
104127
105128 fun updateOfficeroomLog (
106129 userid : String ,
107130 mongo_officeroomid : String ,
108- index : Int , // 수정할 로그의 인덱스
109- input_data_set : String ,
110- output_data_set : String = "TESTING ⚠️TESTING ⚠️TESTING " // AI Model 도입 전임으로 임시 설정
131+ index : Int ,
132+ input_data_set : String
111133 ): Mono <Map <* , * >> {
134+
135+ // Llama 모델에 input_data_set을 보내고 응답을 받음
136+ return getLlamaResponse(input_data_set).flatMap { output_data_set ->
137+
138+ val requestBody = mapOf (
139+ " user_id" to userid,
140+ " id" to mongo_officeroomid,
141+ " index" to index,
142+ " input_data" to input_data_set,
143+ " output_data" to output_data_set
144+ )
145+
146+ webClient.build()
147+ .put()
148+ .uri(" /mongo/office/update_log" )
149+ .contentType(MediaType .APPLICATION_JSON )
150+ .bodyValue(requestBody)
151+ .retrieve()
152+ .bodyToMono(Map ::class .java)
153+ }
154+ }
155+
156+ fun deleteOfficeroomLog (userid : String , mongo_officeroomid : String , index : Int ): Mono <Map <* , * >> {
112157 val requestBody = mapOf (
113158 " user_id" to userid,
114159 " id" to mongo_officeroomid,
115- " index" to index, // 수정할 인덱스 전달
116- " input_data" to input_data_set,
117- " output_data" to output_data_set
160+ " index" to index
118161 )
119162
120163 return webClient.build()
121- .put( )
122- .uri(" /mongo/office/update_log " ) // FastAPI 서버로 수정 요청
164+ .method( HttpMethod . DELETE )
165+ .uri(" /mongo/office/delete_log " )
123166 .contentType(MediaType .APPLICATION_JSON )
124167 .bodyValue(requestBody)
125168 .retrieve()
126169 .bodyToMono(Map ::class .java)
127170 }
128171
129- fun deleteOfficeroomLog (userid : String , mongo_officeroomid : String , index : Int ): Mono <Map <* , * >> {
130- val requestBody = mapOf (
131- " user_id" to userid,
132- " id" to mongo_officeroomid,
133- " index" to index // 삭제할 로그의 인덱스를 전달
134- )
135-
136- return webClient.build()
137- .method(HttpMethod .DELETE )
138- .uri(" /mongo/office/delete_log" )
139- .contentType(MediaType .APPLICATION_JSON )
140- .bodyValue(requestBody)
141- .retrieve()
142- .bodyToMono(Map ::class .java)
143- }
144-
145172 fun saveOfficeroomToMySQL (userid : String , mongo_chatroomid : String ): Mono <Officeroom > {
146173 val newOfficeroom = Officeroom (
147174 userid = userid,
0 commit comments