...
This commit is contained in:
parent
b191022e6d
commit
540c700c89
@ -2,6 +2,7 @@ package kr.lunaticbum.back.lun
|
|||||||
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
import org.springframework.boot.runApplication
|
import org.springframework.boot.runApplication
|
||||||
|
import org.springframework.scheduling.annotation.EnableAsync
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling
|
import org.springframework.scheduling.annotation.EnableScheduling
|
||||||
import org.springframework.web.reactive.function.client.WebClient
|
import org.springframework.web.reactive.function.client.WebClient
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -9,7 +10,7 @@ import java.util.concurrent.ExecutionException
|
|||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.concurrent.TimeoutException
|
import java.util.concurrent.TimeoutException
|
||||||
|
|
||||||
|
@EnableAsync
|
||||||
@EnableScheduling // 추가
|
@EnableScheduling // 추가
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
class LunApplication {
|
class LunApplication {
|
||||||
|
|||||||
@ -36,17 +36,17 @@ class AppConfig : WebMvcConfigurer {
|
|||||||
// return QdrantClient("https://ollama.lunaticbum.kr:6334")
|
// return QdrantClient("https://ollama.lunaticbum.kr:6334")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Bean
|
// @Bean
|
||||||
fun chatClient(): OllamaApi {
|
// fun chatClient(): OllamaApi {
|
||||||
return OllamaApi("https://lama.lunaticbum.kr")
|
// return OllamaApi("https://lama.lunaticbum.kr")
|
||||||
|
//
|
||||||
// .withDefaultOptions(
|
//// .withDefaultOptions(
|
||||||
// OllamaOptions.create()
|
//// OllamaOptions.create()
|
||||||
// .withModel("phi4:14b")
|
//// .withModel("phi4:14b")
|
||||||
// .withNumThread(5)
|
//// .withNumThread(5)
|
||||||
// .withSeed(5)
|
//// .withSeed(5)
|
||||||
// .withTemperature(0.9f))
|
//// .withTemperature(0.9f))
|
||||||
}
|
// }
|
||||||
// @Bean
|
// @Bean
|
||||||
// fun getProperty() : Map<String,String>{
|
// fun getProperty() : Map<String,String>{
|
||||||
// println("telegramBotKey >>>> $telegramBotKey")
|
// println("telegramBotKey >>>> $telegramBotKey")
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
package kr.lunaticbum.back.lun.configs
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
class AsyncConfig {
|
||||||
|
@Bean
|
||||||
|
fun taskExecutor(): ThreadPoolTaskExecutor {
|
||||||
|
val executor = ThreadPoolTaskExecutor()
|
||||||
|
executor.corePoolSize = 10 // 코어 스레드 풀 크기 설정
|
||||||
|
executor.maxPoolSize = 20 // 최대 스레드 풀 크기 설정
|
||||||
|
executor.queueCapacity = 500 // 작업 큐 용량 설정
|
||||||
|
executor.setThreadNamePrefix("AsyncThread-") // 스레드 이름 접두사 설정
|
||||||
|
|
||||||
|
// 작업이 완료된 후 스레드 풀이 종료될 때까지 대기할 시간 설정 (단위: 초)
|
||||||
|
executor.setAwaitTerminationSeconds(60)
|
||||||
|
|
||||||
|
executor.initialize()
|
||||||
|
return executor
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -28,11 +28,11 @@ class BumsInterceptor : HandlerInterceptor {
|
|||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
|
override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
|
||||||
var skippResourcesExtension = arrayListOf(".js",".css").filter { request.requestURI.contains(it) }.size > 0
|
var skippResourcesExtension = arrayListOf(".js",".css").filter { request.requestURI.contains(it) }.size > 0
|
||||||
if (!skippResourcesExtension) {
|
// if (!skippResourcesExtension) {
|
||||||
println("===============================================")
|
// println("===============================================")
|
||||||
println("==================== BEGIN ====================")
|
// println("==================== BEGIN ====================")
|
||||||
println("Request URL ===> " + request.requestURL)
|
// println("Request URL ===> " + request.requestURL)
|
||||||
}
|
// }
|
||||||
return super.preHandle(request, response, handler)
|
return super.preHandle(request, response, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class BumsInterceptor : HandlerInterceptor {
|
|||||||
handler: Any,
|
handler: Any,
|
||||||
@Nullable modelAndView: ModelAndView?
|
@Nullable modelAndView: ModelAndView?
|
||||||
) {
|
) {
|
||||||
var skippResourcesExtension = arrayListOf(".js",".css").filter { request.requestURI.contains(it) }.size > 0
|
var skippResourcesExtension = arrayListOf(".ajax",".js",".css").filter { request.requestURI.contains(it) }.size > 0
|
||||||
if (!skippResourcesExtension) {
|
if (!skippResourcesExtension) {
|
||||||
if (request.requestURI.contains("logout") == false && !request.cookies.isNullOrEmpty() && request.cookies.filter {
|
if (request.requestURI.contains("logout") == false && !request.cookies.isNullOrEmpty() && request.cookies.filter {
|
||||||
it.name.equals(
|
it.name.equals(
|
||||||
@ -60,6 +60,7 @@ class BumsInterceptor : HandlerInterceptor {
|
|||||||
access = it
|
access = it
|
||||||
accessOk = true
|
accessOk = true
|
||||||
println("==================== accessOk ${accessOk} ======================")
|
println("==================== accessOk ${accessOk} ======================")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request.cookies.forEach {
|
request.cookies.forEach {
|
||||||
@ -70,44 +71,41 @@ class BumsInterceptor : HandlerInterceptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (refreshOk || accessOk) {
|
if (refreshOk || accessOk) {
|
||||||
if (refreshOk) {
|
request.getSession(true)?.let { session ->
|
||||||
if (!accessOk) {
|
session.setAttribute(WRITE_PERMISSION_KEY, true)
|
||||||
refresh?.let { refresh ->
|
session.maxInactiveInterval = 60 * 5
|
||||||
jwtService.getUserIdFromRefresh(refresh.value)?.let { userId ->
|
|
||||||
userManager.findById(userId)?.block()?.let { user ->
|
|
||||||
jwtService.generate(user)?.let { token ->
|
|
||||||
response.addCookie(cookieUpdate(Cookie("access", token.tokenKey)))
|
|
||||||
response.addCookie(cookieUpdate(Cookie("refresh", token.refreshToken)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
response.addCookie(cookieUpdate(access))
|
|
||||||
}
|
|
||||||
} else if (accessOk) {
|
|
||||||
response.addCookie(cookieUpdate(access))
|
|
||||||
}
|
}
|
||||||
modelAndView?.modelMap?.put(WRITE_PERMISSION_KEY, "OK")
|
|
||||||
modelAndView?.modelMap?.put("user_id", jwtService.getUserIdFromToken(access?.value ?: ""))
|
|
||||||
} else {
|
} else {
|
||||||
println("==================== accessOk ${accessOk} && refreshOk ${refreshOk} ======================")
|
|
||||||
response.addCookie(Cookie("access", "").apply { maxAge = -1 })
|
|
||||||
response.addCookie(Cookie("refresh", "").apply { maxAge = -1 })
|
|
||||||
modelAndView?.modelMap?.put(WRITE_PERMISSION_KEY, "NO")
|
|
||||||
modelAndView?.modelMap?.put("user_id", "")
|
|
||||||
}
|
|
||||||
println("Response modelMap ===> ${Gson().toJson(modelAndView?.modelMap)}")
|
|
||||||
} else if (request.requestURI.contains("logout")) {
|
|
||||||
modelAndView?.modelMap?.put(WRITE_PERMISSION_KEY, "NO")
|
|
||||||
modelAndView?.modelMap?.put("user_id", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (request.requestURI.contains("logout")) {
|
||||||
|
request.getSession(true)?.let { session ->
|
||||||
|
session.invalidate()
|
||||||
|
session.setAttribute(WRITE_PERMISSION_KEY, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
println("==================== END ======================")
|
println("==================== END ======================")
|
||||||
println("===============================================")
|
println("===============================================")
|
||||||
}
|
}
|
||||||
|
request.cookies?.forEach {
|
||||||
|
if (it.name.equals("CLEAR", true)) {
|
||||||
|
request.getSession(true)?.let { session ->
|
||||||
|
session.invalidate()
|
||||||
|
session.setAttribute(WRITE_PERMISSION_KEY, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modelAndView?.modelMap?.put(WRITE_PERMISSION_KEY,"NO")
|
||||||
|
request.getSession(true)?.let {
|
||||||
|
(it.getAttribute(WRITE_PERMISSION_KEY) as? Boolean)?.let { permission ->
|
||||||
|
if (permission) {
|
||||||
|
modelAndView?.modelMap?.put(WRITE_PERMISSION_KEY,"OK")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
super.postHandle(request, response, handler, modelAndView)
|
super.postHandle(request, response, handler, modelAndView)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cookieUpdate(cookie: Cookie?) : Cookie? {
|
fun cookieUpdate(cookie: Cookie?) : Cookie? {
|
||||||
cookie?.maxAge = (globalEvv.ACCESS_EXPIRATION / 1000).toInt()
|
cookie?.maxAge = (globalEvv.ACCESS_EXPIRATION / 1000).toInt()
|
||||||
cookie?.domain = "lunaticbum.kr"
|
cookie?.domain = "lunaticbum.kr"
|
||||||
|
|||||||
@ -143,39 +143,34 @@ class BlogController() {
|
|||||||
fun modify(httpServletRequest: HttpServletRequest, @RequestParam("token") token : String?) : ResultMV{
|
fun modify(httpServletRequest: HttpServletRequest, @RequestParam("token") token : String?) : ResultMV{
|
||||||
logService.log("incoming modify")
|
logService.log("incoming modify")
|
||||||
val vm = ResultMV("content/blog/modify")
|
val vm = ResultMV("content/blog/modify")
|
||||||
var s33Key : String? = null
|
vm.modelMap.put(WRITE_PERMISSION_KEY,"NO")
|
||||||
if(jwtService.hasPerrmission(httpServletRequest)) {
|
httpServletRequest.getSession(true)?.let { session ->
|
||||||
postManageg.find20()?.apply {
|
(session.getAttribute(WRITE_PERMISSION_KEY) as? Boolean)?.let {
|
||||||
forEach {
|
postManageg.find20()?.apply {
|
||||||
it.title = URLDecoder.decode(it.title)
|
forEach {
|
||||||
val content = URLDecoder.decode(it.content)
|
it.title = URLDecoder.decode(it.title)
|
||||||
it.content = if (content.length > 50) content.substring(0,150) else content
|
val content = URLDecoder.decode(it.content)
|
||||||
|
it.content = if (content.length > 50) content.substring(0,150) else content
|
||||||
|
}
|
||||||
|
vm.modelMap.put("chunkedPosts", this.chunked(3))
|
||||||
}
|
}
|
||||||
vm.modelMap.put("chunkedPosts", this.chunked(3))
|
vm.modelMap.put(WRITE_PERMISSION_KEY,"OK")
|
||||||
|
vm.modelMap.put("path","editor/")
|
||||||
|
vm.modelMap.put("SK",token)
|
||||||
}
|
}
|
||||||
vm.modelMap.put(WRITE_PERMISSION_KEY,"OK")
|
|
||||||
vm.modelMap.put("path","editor/")
|
|
||||||
vm.modelMap.put("SK",token)
|
|
||||||
} else {
|
|
||||||
vm.modelMap.put(WRITE_PERMISSION_KEY,"NO")
|
|
||||||
}
|
}
|
||||||
vm.modelMap.put("rowKey","chunkedPosts_")
|
vm.modelMap.put("rowKey","chunkedPosts_")
|
||||||
return vm
|
return vm
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("editor/{postId}")
|
@GetMapping("editor/{postId}")
|
||||||
fun editor(@PathVariable postId : String, @RequestParam("token") token : String?) : ResultMV{
|
fun editor(@PathVariable postId : String) : ResultMV{
|
||||||
val vm = ResultMV("content/blog/editor")
|
val vm = ResultMV("content/blog/editor")
|
||||||
postManageg.getPost(postId).block().apply {
|
postManageg.getPost(postId).block().apply {
|
||||||
this?.title = URLDecoder.decode(this?.title)
|
this?.title = URLDecoder.decode(this?.title)
|
||||||
this?.content = URLDecoder.decode(this?.content)
|
this?.content = URLDecoder.decode(this?.content)
|
||||||
vm.modelMap.put("srcPost",this)
|
vm.modelMap.put("srcPost",this)
|
||||||
}
|
}
|
||||||
if (TEMPTOKEN.equals(token)) {
|
|
||||||
vm.modelMap.put(WRITE_PERMISSION_KEY,"OK")
|
|
||||||
} else {
|
|
||||||
vm.modelMap.put(WRITE_PERMISSION_KEY,"NO")
|
|
||||||
}
|
|
||||||
return vm
|
return vm
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +178,7 @@ class BlogController() {
|
|||||||
@GetMapping("recent")
|
@GetMapping("recent")
|
||||||
fun recent() : ResultMV{
|
fun recent() : ResultMV{
|
||||||
val vm = ResultMV("content/blog/viewer")
|
val vm = ResultMV("content/blog/viewer")
|
||||||
locationLogService.find20().forEach {
|
locationLogService.find10().forEach {
|
||||||
logService.log(Gson().toJson(it))
|
logService.log(Gson().toJson(it))
|
||||||
}
|
}
|
||||||
locationLogService.getLocationLog()?.let {
|
locationLogService.getLocationLog()?.let {
|
||||||
|
|||||||
@ -33,11 +33,9 @@ class BumsPrivate {
|
|||||||
@GetMapping("where")
|
@GetMapping("where")
|
||||||
fun where() : ResultMV {
|
fun where() : ResultMV {
|
||||||
val m = ResultMV("content/private/where")
|
val m = ResultMV("content/private/where")
|
||||||
locationService.find20().apply {
|
|
||||||
|
locationService.find10().apply {
|
||||||
m.modelMap.put("locations",this.reversed())
|
m.modelMap.put("locations",this.reversed())
|
||||||
// forEach {
|
|
||||||
// logService.log(it.timeString.plus(it.mAddressLines.joinToString(",")))
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
m.setTitle("돼지 여기있다요~!!")
|
m.setTitle("돼지 여기있다요~!!")
|
||||||
return m
|
return m
|
||||||
@ -60,15 +58,15 @@ class BumsPrivate {
|
|||||||
val responce = ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(ResponceResult().apply {
|
val responce = ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(ResponceResult().apply {
|
||||||
|
|
||||||
})
|
})
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
// CoroutineScope(Dispatchers.IO).launch {
|
||||||
location?.let {
|
// location?.let {
|
||||||
val client = WebClient.create()
|
// val client = WebClient.create()
|
||||||
client.get()
|
// client.get()
|
||||||
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${it.mAddressLines.first()} 저장")
|
// .uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${it.mAddressLines.first()} 저장")
|
||||||
.retrieve()
|
// .retrieve()
|
||||||
.bodyToMono(String::class.java).block() ?: "FAIL"
|
// .bodyToMono(String::class.java).block() ?: "FAIL"
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return responce
|
return responce
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -74,6 +74,7 @@ class UserController {
|
|||||||
@PostMapping("login.ajax")
|
@PostMapping("login.ajax")
|
||||||
fun login(httpServletRequest: HttpServletRequest, @RequestBody jsonString: String) : ResponseEntity<LoginResult> {
|
fun login(httpServletRequest: HttpServletRequest, @RequestBody jsonString: String) : ResponseEntity<LoginResult> {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
logService.log(httpServletRequest.requestURI)
|
logService.log(httpServletRequest.requestURI)
|
||||||
logService.log(jsonString)
|
logService.log(jsonString)
|
||||||
var lResultCode = 0
|
var lResultCode = 0
|
||||||
|
|||||||
@ -90,8 +90,8 @@ class LocationLogService : LocationService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private lateinit var logRepository: LocationLogRepository
|
private lateinit var logRepository: LocationLogRepository
|
||||||
|
|
||||||
fun find20() : List<LocationLog> {
|
fun find10() : List<LocationLog> {
|
||||||
return logRepository.findAll().takeLast(20).buffer(20).blockLast(Duration.ofSeconds(30)) ?: listOf()
|
return logRepository.findAll().takeLast(10).buffer(10).blockLast(Duration.ofSeconds(30)) ?: listOf()
|
||||||
}
|
}
|
||||||
fun getLocationLog() : LocationLog? {
|
fun getLocationLog() : LocationLog? {
|
||||||
return logRepository.findFirstByOrderByTimeDesc().block()
|
return logRepository.findFirstByOrderByTimeDesc().block()
|
||||||
|
|||||||
@ -12,7 +12,8 @@ class SearXng {
|
|||||||
var unresponsive_engines: ArrayList<ArrayList<String>>? = null
|
var unresponsive_engines: ArrayList<ArrayList<String>>? = null
|
||||||
}
|
}
|
||||||
class SearXngResult {
|
class SearXngResult {
|
||||||
// var originQuery : String? = null
|
var originQuery : String? = null
|
||||||
|
var refinedQuery : String? = null
|
||||||
var url: String? = null
|
var url: String? = null
|
||||||
var title: String? = null
|
var title: String? = null
|
||||||
var content: String? = null
|
var content: String? = null
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import com.google.gson.annotations.SerializedName
|
|||||||
import io.micrometer.observation.ObservationRegistry
|
import io.micrometer.observation.ObservationRegistry
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kr.lunaticbum.back.lun.configs.GlobalEnvironment
|
import kr.lunaticbum.back.lun.configs.GlobalEnvironment
|
||||||
import kr.lunaticbum.back.lun.controllers.TelegramSendMsg
|
import kr.lunaticbum.back.lun.controllers.TelegramSendMsg
|
||||||
@ -21,6 +22,7 @@ import org.springframework.ai.ollama.management.ModelManagementOptions
|
|||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.beans.factory.annotation.Qualifier
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
|
import org.springframework.scheduling.annotation.Async
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.web.reactive.function.BodyInserters
|
import org.springframework.web.reactive.function.BodyInserters
|
||||||
import org.springframework.web.reactive.function.client.WebClient
|
import org.springframework.web.reactive.function.client.WebClient
|
||||||
@ -28,15 +30,14 @@ import reactor.kotlin.core.publisher.toMono
|
|||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class Lama {
|
class Lama {
|
||||||
|
|
||||||
|
|
||||||
@Qualifier("chatClient")
|
|
||||||
@Autowired
|
|
||||||
private lateinit var chatClient: OllamaApi
|
|
||||||
|
|
||||||
//, val date : String = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
|
//, val date : String = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
|
||||||
// data class QSearchData(val query : FloatArray,val limit : Int)
|
// data class QSearchData(val query : FloatArray,val limit : Int)
|
||||||
@ -62,7 +63,7 @@ class Lama {
|
|||||||
// .retrieve()
|
// .retrieve()
|
||||||
// .bodyToMono(String::class.java).timeout(Duration.ofMinutes(20L)).block() ?: ""
|
// .bodyToMono(String::class.java).timeout(Duration.ofMinutes(20L)).block() ?: ""
|
||||||
// }
|
// }
|
||||||
var qPointsCount : Long = 0
|
|
||||||
private fun checkCollection() : Long {
|
private fun checkCollection() : Long {
|
||||||
val qUrl = "https://ollama.lunaticbum.kr/collections/blama_vectors"
|
val qUrl = "https://ollama.lunaticbum.kr/collections/blama_vectors"
|
||||||
val client = WebClient.create()
|
val client = WebClient.create()
|
||||||
@ -119,9 +120,9 @@ class Lama {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return if (lastElement.size > 0) {
|
return if (lastElement.size > 0) {
|
||||||
lastElement.map { it.children().eachText() }.joinToString(joinString)
|
lastElement.eachText().joinToString(joinString)
|
||||||
} else {
|
} else {
|
||||||
body.children().map { it.children().eachText() }.joinToString(joinString)
|
body.children().eachText().joinToString(joinString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,71 +138,116 @@ class Lama {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
private fun addDocuments(query : String) {
|
|
||||||
|
|
||||||
val embeddingModel = OllamaEmbeddingModel(
|
fun addDocuments(query : String , refinedQuery: RefinedQuery?) {
|
||||||
chatClient,
|
var querys : ArrayList<String> = ArrayList()
|
||||||
OllamaOptions.builder().build(),
|
querys.add(query)
|
||||||
ObservationRegistry.create(),
|
refinedQuery?.ko_query?.let { querys.add(it) }
|
||||||
ModelManagementOptions.defaults()
|
refinedQuery?.en_query?.let { querys.add(it) }
|
||||||
)
|
refinedQuery?.keywords?.let { querys.add(it.joinToString { " " })}
|
||||||
val gSearch = "https://psn.lunaticbum.kr/search?q=${query?.replace("오늘", SimpleDateFormat("yyyMMdd").format(Date()))}&language=ko&time_range=month&safesearch=0&categories=general&format=json"
|
val readedUrls = ArrayList<String>()
|
||||||
println("gSearch >>> ${gSearch}")
|
querys.forEach { refinedQuery ->
|
||||||
val sdss = QPut(arrayListOf())
|
val gSearch = "https://psn.lunaticbum.kr/search?q=${refinedQuery?.replace("오늘", SimpleDateFormat("yyyMMdd").format(Date()))}&language=ko&time_range=month&safesearch=0&categories=general&format=json"
|
||||||
WebClient.create().get()
|
println("gSearch >>> ${gSearch}")
|
||||||
.uri(gSearch)
|
WebClient.create().get()
|
||||||
.retrieve()
|
.uri(gSearch)
|
||||||
.bodyToMono(SearXng::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { gsResult ->
|
.retrieve()
|
||||||
gsResult.results?.filter { it.score > 0.3}?.forEach {
|
.bodyToMono(SearXng::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { gsResult ->
|
||||||
qPointsCount += 1
|
gsResult.results?.filter { it.url?.startsWith("https://") == true && it.score > 0.4}?.forEach {
|
||||||
println("in filter ${it.url}")
|
println("in filter ${it.url}")
|
||||||
// it.originQuery = query
|
if (readedUrls.contains(it.url) == false) {
|
||||||
val data = Gson().toJson(it)
|
readedUrls.add(it.url!!)
|
||||||
println(it.title)
|
it.originQuery = query
|
||||||
jsopFilter(it.url!!).let { text ->
|
it.refinedQuery = refinedQuery
|
||||||
try {
|
println(it.title)
|
||||||
println("text >>>>> ${text?.chunked(50)?.first() ?: ""}")
|
try {
|
||||||
var dispoable = chatClient.chat(OllamaApi.ChatRequest.Builder("phi4:14b").stream(false).format("json").messages(
|
jsopFilter(it.url!!).let { text ->
|
||||||
listOf(OllamaApi.Message.Builder(OllamaApi.Message.Role.USER).content("원문:\n'${text}'\n원문의 웹 페이지 소스는 '$query'이 질문에 대해 연관 결과로 받은 내용이야. 해당 정보를 파악해서 'query:{질문},contents:{본문내용},summary:{요약},keywords:[키워드],related_links:[링크],relatedness_score:{0.0~10.0}'이 형식의 결과만들어줘 내용은 한국어로 부탁할께").build())
|
it.originHtml = text
|
||||||
).build()).toMono().subscribe({aiResponce ->
|
webPageSummarize(it,text)
|
||||||
it.pageData = aiResponce.message.content
|
}
|
||||||
// println(aiResponce)
|
}catch(e:Exception){e.printStackTrace()}
|
||||||
println("summary result >>>>> ${it.pageData}")
|
|
||||||
// it.originHtml = text
|
|
||||||
val embeddingResponse = embeddingModel.call(
|
|
||||||
EmbeddingRequest(
|
|
||||||
listOf(data),
|
|
||||||
OllamaOptions.builder()
|
|
||||||
.model("nomic-embed-text")
|
|
||||||
.truncate(false).build()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
sdss.points.add(QData(id = qPointsCount,embeddingResponse.result.output,it))
|
|
||||||
},{err->
|
|
||||||
err.printStackTrace()
|
|
||||||
})
|
|
||||||
}catch (e : Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
println("end of search")
|
||||||
println("out filter")
|
|
||||||
if (sdss.points.size > 0) {
|
|
||||||
val qUrl = "https://ollama.lunaticbum.kr/collections/blama_vectors".plus("/points")
|
|
||||||
val client = WebClient.create()
|
|
||||||
client.put()
|
|
||||||
.uri(qUrl)
|
|
||||||
.header("api-key", "blama-admin-key-gb")
|
|
||||||
.body(BodyInserters.fromValue(Gson().toJson(sdss)))
|
|
||||||
.retrieve()
|
|
||||||
.bodyToMono(String::class.java).timeout(Duration.ofMinutes(20L)).block() ?: ""
|
|
||||||
|
|
||||||
}
|
}
|
||||||
println("end of search")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun embedQuery(embedFlots : FloatArray) : QContents?{
|
var format = "원문:\n'%s'\n원문의 웹 페이지 소스는 '%s'이 질문에 대해 연관 결과로 받은 내용이야. 해당 정보를 파악해서 'query:{질문},contents:{본문내용 한국어},summary:{요약 한국어},keywords:[키워드],related_links:[링크],relatedness_score:{0.0~10.0}'이 형식의 결과만들어줘"
|
||||||
|
internal fun makeSummarizeRequestMsg(it : SearXngResult) : String= format.format(it.originHtml,it.originQuery)
|
||||||
|
|
||||||
|
internal fun makeCahtReq(reqMsg:String) = OllamaApi.ChatRequest.Builder("phi4:14b").stream(false).format("json").messages(listOf(OllamaApi.Message.Builder(OllamaApi.Message.Role.USER).content(reqMsg).build())).build()
|
||||||
|
|
||||||
|
@Async
|
||||||
|
fun webPageSummarize(it : SearXngResult , text : String) {
|
||||||
|
try {
|
||||||
|
val chatClient = OllamaApi("https://lama.lunaticbum.kr")
|
||||||
|
val embeddingModel = OllamaEmbeddingModel(
|
||||||
|
chatClient, OllamaOptions.builder().build(), ObservationRegistry.create(), ModelManagementOptions.defaults())
|
||||||
|
println("text >>>>> ${text?.chunked(50)?.first() ?: ""}")
|
||||||
|
var dispoable = chatClient.chat(makeCahtReq(makeSummarizeRequestMsg(it))).toMono().subscribe({aiResponce ->
|
||||||
|
it.pageData = aiResponce.message.content
|
||||||
|
println("summary result >>>>> ${it.pageData}")
|
||||||
|
val embeddingResponse = embeddingModel.call(
|
||||||
|
EmbeddingRequest(
|
||||||
|
listOf(aiResponce.message.content),
|
||||||
|
OllamaOptions.builder()
|
||||||
|
.model("bge-m3")
|
||||||
|
.truncate(false).build()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
infomationDic.put(it.url!!,aiResponce.message.content)
|
||||||
|
val sdss = QPut(arrayListOf())
|
||||||
|
sdss.points.add(QData(id = System.currentTimeMillis(),embeddingResponse.result.output,it))
|
||||||
|
if (sdss.points.size > 0) {
|
||||||
|
val qUrl = "https://ollama.lunaticbum.kr/collections/blama_vectors".plus("/points")
|
||||||
|
val client = WebClient.create()
|
||||||
|
client.put()
|
||||||
|
.uri(qUrl)
|
||||||
|
.header("api-key", "blama-admin-key-gb")
|
||||||
|
.body(BodyInserters.fromValue(Gson().toJson(sdss)))
|
||||||
|
.retrieve()
|
||||||
|
.bodyToMono(String::class.java).timeout(Duration.ofMinutes(20L)).subscribe(
|
||||||
|
{resultString -> },{error-> error.printStackTrace()}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},{err->
|
||||||
|
err.printStackTrace()
|
||||||
|
})
|
||||||
|
}catch (e : Exception) {
|
||||||
|
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RefinedQuery {
|
||||||
|
var ko_query : String? = null
|
||||||
|
var en_query : String? = null
|
||||||
|
var keywords : Array<String>? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
var queryFormat = "질문:\n'%s'\n앞은 질문의 내용을 정리해서 '{ko_query:한국어 질문,en_query:영어 번역된 질문,ko_keywords:[한국어 키워드],en_keyword:[영문키워드]}'이 형식의 결과를 부탁할께"
|
||||||
|
internal fun makeQuerySummarizeRequestMsg(query : String) : String= queryFormat.format(query)
|
||||||
|
fun querySummarize(query: String) : RefinedQuery? {
|
||||||
|
var refinedQuery : RefinedQuery? = null
|
||||||
|
try {
|
||||||
|
val chatClient = OllamaApi("https://lama.lunaticbum.kr")
|
||||||
|
var dispoable = chatClient.chat(makeCahtReq(makeQuerySummarizeRequestMsg(query))).toMono().subscribe({aiResponce ->
|
||||||
|
println("summary result >>>>> ${aiResponce.message.content}")
|
||||||
|
refinedQuery = Gson().fromJson(aiResponce.message.content, RefinedQuery::class.java)
|
||||||
|
},{err->
|
||||||
|
err.printStackTrace()
|
||||||
|
})
|
||||||
|
}catch (e : Exception) {
|
||||||
|
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return refinedQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public fun embedQuery(embedFlots : FloatArray) : QContents?{
|
||||||
val qUrl = "https://ollama.lunaticbum.kr/collections/blama_vectors".plus("/points/search")
|
val qUrl = "https://ollama.lunaticbum.kr/collections/blama_vectors".plus("/points/search")
|
||||||
val client = WebClient.create()
|
val client = WebClient.create()
|
||||||
var lists = client.post()
|
var lists = client.post()
|
||||||
@ -233,63 +279,41 @@ class Lama {
|
|||||||
@Autowired
|
@Autowired
|
||||||
lateinit var globalEvv : GlobalEnvironment
|
lateinit var globalEvv : GlobalEnvironment
|
||||||
|
|
||||||
|
var infomationDic = hashMapOf<String,String>()
|
||||||
suspend fun generateResponse(query: String?, targetId: String? = globalEvv.telegramMyId) {
|
suspend fun generateResponse(query: String?, targetId: String? = globalEvv.telegramMyId) {
|
||||||
|
infomationDic.clear()
|
||||||
|
val chatClient = OllamaApi("https://lama.lunaticbum.kr")
|
||||||
val embeddingModel = OllamaEmbeddingModel(
|
val embeddingModel = OllamaEmbeddingModel(
|
||||||
chatClient,
|
chatClient, OllamaOptions.builder().build(), ObservationRegistry.create(), ModelManagementOptions.defaults())
|
||||||
OllamaOptions.builder().build(),
|
|
||||||
ObservationRegistry.create(),
|
|
||||||
ModelManagementOptions.defaults()
|
|
||||||
)
|
|
||||||
println("On generateResponse :: find something ${query}")
|
println("On generateResponse :: find something ${query}")
|
||||||
query?.let {
|
query?.let { originalQuery ->
|
||||||
var embeddingResponse = embeddingModel.call(
|
var embeddingResponse = embeddingModel.call(EmbeddingRequest(listOf(originalQuery), OllamaOptions.builder().model("bge-m3").truncate(false).build()))
|
||||||
EmbeddingRequest(
|
addDocuments(originalQuery, querySummarize(originalQuery))
|
||||||
listOf(query),
|
|
||||||
OllamaOptions.builder()
|
|
||||||
.model("nomic-embed-text")
|
|
||||||
.truncate(false)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
println("points size ${embeddingResponse.result.output.size}")
|
println("points size ${embeddingResponse.result.output.size}")
|
||||||
qPointsCount = checkCollection()
|
|
||||||
addDocuments(it)
|
|
||||||
embeddingResponse = embeddingModel.call(
|
|
||||||
EmbeddingRequest(
|
|
||||||
listOf(query),
|
|
||||||
OllamaOptions.builder()
|
|
||||||
.model("nomic-embed-text")
|
|
||||||
.truncate(false)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
println(embeddingResponse.result.output)
|
|
||||||
var context : String? = ""
|
var context : String? = ""
|
||||||
try {
|
try {
|
||||||
embedQuery(embeddingResponse.result.output)?.result?.forEach { result ->
|
embedQuery(embeddingResponse.result.output)?.result?.forEach { result ->
|
||||||
context += "참고자료:".plus(if (result.payload?.pageData?.length ?: 0 > 10) {
|
if (infomationDic.contains(result.payload?.url ?: "NONE") == false) {
|
||||||
result.payload?.pageData
|
context += "\n# :".plus(if (result.payload?.pageData?.length ?: 0 > 10) {
|
||||||
} else {
|
result.payload?.pageData
|
||||||
result.payload?.content
|
} else {
|
||||||
})
|
result.payload?.content
|
||||||
context +="\n"
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch (e:Exception){
|
}catch (e:Exception){
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
val response: OllamaApi.ChatResponse = if (context?.length ?: 0 > 10) {
|
|
||||||
val prompt = "Context information is below.\n$context\nGiven the context information and not prior knowledge, answer the query: $query\n한국어로 대답해줘".trimIndent()
|
infomationDic.iterator().forEach { context += "\n#${it.key}:${it.value}" }
|
||||||
chatClient.chat(OllamaApi.ChatRequest.Builder("phi4:14b").stream(false).format("json").messages(
|
|
||||||
listOf(OllamaApi.Message.Builder(OllamaApi.Message.Role.USER).content(prompt).build())
|
val prompt = "참조:\n$context\n참조 내용을 고려해서\n해당 질문:${query}\n에 {질문내용:[한국어],답변내용:[한국어],전체키워드:[],참조링크:[]}형식으로 대답 해줘 ".trimIndent()
|
||||||
).build())
|
println(prompt)
|
||||||
} else {
|
val response: OllamaApi.ChatResponse = chatClient.chat(OllamaApi.ChatRequest.Builder("phi4:14b").stream(false).format("json").messages(
|
||||||
chatClient.chat(OllamaApi.ChatRequest.Builder("phi4:14b").stream(false).format("json").messages(
|
listOf(OllamaApi.Message.Builder(OllamaApi.Message.Role.USER).content(prompt).build())
|
||||||
listOf(OllamaApi.Message.Builder(OllamaApi.Message.Role.USER).content(query).build())
|
).build())
|
||||||
).build())
|
|
||||||
}
|
|
||||||
println(response.message.content)
|
println(response.message.content)
|
||||||
// val fullUrl = "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${query}의 대답이 도착했어요.\n\n${response.message.content}"
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
var toalmsg = "${query}의 대답이 도착했어요.\n${response.message.content}"
|
var toalmsg = "${query}의 대답이 도착했어요.\n${response.message.content}"
|
||||||
val fullUrl = "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage"
|
val fullUrl = "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage"
|
||||||
@ -309,8 +333,6 @@ class Lama {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
println("On generateResponse :: END OF Answer")
|
println("On generateResponse :: END OF Answer")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,13 +5,9 @@ onload = function() {
|
|||||||
var refreshToken = get_cookie("refresh")
|
var refreshToken = get_cookie("refresh")
|
||||||
console.log("access === " + accToken + " || " + accToken.length);
|
console.log("access === " + accToken + " || " + accToken.length);
|
||||||
console.log("refresh === " + refreshToken + " || " + refreshToken.length);
|
console.log("refresh === " + refreshToken + " || " + refreshToken.length);
|
||||||
|
document.cookie = "access=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"
|
||||||
if (accToken.length < 1) {
|
document.cookie = "refresh=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"
|
||||||
document.cookie = "refresh="+ window.sessionStorage.getItem("REFRESH") + ";";
|
document.cookie = "CLEAR=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"
|
||||||
}
|
|
||||||
if (refreshToken.length < 1) {
|
|
||||||
window.sessionStorage.setItem("REFRESH",get_cookie("refresh"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
onbeforeunload = function () {
|
onbeforeunload = function () {
|
||||||
var accToken = get_cookie("access")
|
var accToken = get_cookie("access")
|
||||||
@ -160,6 +156,10 @@ function logout() {
|
|||||||
// retrieve all cookies
|
// retrieve all cookies
|
||||||
document.cookie = "access=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"
|
document.cookie = "access=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"
|
||||||
document.cookie = "refresh=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"
|
document.cookie = "refresh=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"
|
||||||
|
|
||||||
|
console.log(document.cookie["JSESSIONID"])
|
||||||
|
document.cookie = "JSESSIONID=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"
|
||||||
|
document.cookie = "CLEAR="+Date.now()+"";
|
||||||
let logOutUrl = getMainPath() + "/user/logout.ajax";
|
let logOutUrl = getMainPath() + "/user/logout.ajax";
|
||||||
post(logOutUrl,"","","", function (resultData) {
|
post(logOutUrl,"","","", function (resultData) {
|
||||||
alert("로그아웃 됨요~! 빠염~!")
|
alert("로그아웃 됨요~! 빠염~!")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user