API 1.2+5 open ai chat completion fixes
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.AppText
|
||||
import com.aitrainer.api.repository.AppTextRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class CustomerAppTextController(private val appTextRepository: AppTextRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@GetMapping("/app_text")
|
||||
fun getAppTextWithTranslation(): ResponseEntity<List<AppText>> {
|
||||
val list = appTextRepository.findAllWithTranslation()
|
||||
|
||||
logger.info(" -- Get All app texts $list")
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ class OpenAIController() {
|
||||
var result: String
|
||||
val openAIService = OpenAIService(openaiKey, openai.modelName, openai.temperature)
|
||||
val deferred = GlobalScope.async {
|
||||
println(openai.messages)
|
||||
openAIService.chatCompletion(openai.messages)
|
||||
}
|
||||
runBlocking {
|
||||
|
||||
@@ -66,13 +66,17 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
val listDietSensitivity = dietSensitivityRepository.findAll()
|
||||
val listDietSensitivityJson = gson.toJson(listDietSensitivity)
|
||||
|
||||
val listAppText = appTextRepository.findAllWithTranslation()
|
||||
val listAppTextJson = gson.toJson(listAppText)
|
||||
|
||||
val packageJson: String =
|
||||
getClassRecord(Property::class.simpleName, listPropertyJson) +
|
||||
"|||" + getClassRecord(Membership::class.simpleName, listMembershipJson) +
|
||||
"|||" + getClassRecord(Store::class.simpleName, listStoreJson) +
|
||||
"|||" + getClassRecord(Recipe::class.simpleName, listRecipeJson) +
|
||||
"|||" + getClassRecord(Meal::class.simpleName, listRawMaterialJson) +
|
||||
"|||" + getClassRecord(DietSensitivity::class.simpleName, listDietSensitivityJson)
|
||||
"|||" + getClassRecord(DietSensitivity::class.simpleName, listDietSensitivityJson) +
|
||||
"|||" + getClassRecord(AppText::class.simpleName, listAppTextJson)
|
||||
|
||||
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(packageJson)
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.aitrainer.api.controller.diet
|
||||
|
||||
import com.aitrainer.api.model.diet.Diet
|
||||
import com.aitrainer.api.repository.diet.DietRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.util.*
|
||||
@@ -9,6 +10,7 @@ import java.util.*
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class DietController(private val dietRepository: DietRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@PostMapping("/diet")
|
||||
fun insert(@RequestBody diet: Diet): ResponseEntity<*> {
|
||||
@@ -32,9 +34,26 @@ class DietController(private val dietRepository: DietRepository) {
|
||||
return ResponseEntity.ok().body(dietRepository.save(updatedDiet))
|
||||
}
|
||||
|
||||
@PostMapping("/diet/no_text/{id}")
|
||||
fun updateNoText(@PathVariable(value = "id") id: Long, @RequestBody diet: Diet): ResponseEntity<Diet> {
|
||||
val existingDiet = dietRepository.findByDietId(id) ?: return ResponseEntity.notFound().build()
|
||||
|
||||
val updatedDiet: Diet = existingDiet.copy(
|
||||
dietId = diet.dietId,
|
||||
dietUserId = diet.dietUserId,
|
||||
startDate = diet.startDate
|
||||
)
|
||||
diet.meals.forEach {
|
||||
it.diet = diet
|
||||
updatedDiet.meals.add(it)
|
||||
}
|
||||
return ResponseEntity.ok().body(dietRepository.save(updatedDiet))
|
||||
}
|
||||
|
||||
@GetMapping("/diet/{dietUserId}")
|
||||
fun getByDietUserId(@PathVariable dietUserId: Long): ResponseEntity<List<Diet>> {
|
||||
val list = dietRepository.findByDietUserId(dietUserId)
|
||||
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ data class Diet (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose val dietId: Long = 0,
|
||||
@Expose @get: NotNull val dietUserId: Long = 0,
|
||||
@Expose @get: NotNull val dietText: String = "",
|
||||
@Expose @get: NotNull val startDate: String = "",
|
||||
@Expose @get: NotNull var startDate: String = "",
|
||||
) {
|
||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "diet")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import com.google.gson.annotations.Expose
|
||||
import jakarta.persistence.*
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.springframework.lang.NonNull
|
||||
|
||||
@Entity
|
||||
data class DietMeal (
|
||||
@@ -11,8 +12,9 @@ data class DietMeal (
|
||||
@Expose @get: NotNull val mealId: Long = 0,
|
||||
@Expose @get: NotNull val mealName: String = "",
|
||||
@Expose @get: NotNull val meal: String = "",
|
||||
@Expose @get: NotNull val quantity: Double = 0.0,
|
||||
@Expose @get: NotNull var quantity: Double = 0.0,
|
||||
@Expose @get: NotNull val quantityUnit: String = "",
|
||||
@Expose @get: NonNull var mealDate: String = "",
|
||||
) {
|
||||
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||
@JoinColumn(name = "dietId", nullable = false)
|
||||
|
||||
@@ -2,8 +2,12 @@ package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.AppText
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface AppTextRepository: JpaRepository<AppText, Long> {
|
||||
@Query("FROM AppText as e " +
|
||||
"LEFT JOIN AppTextTranslation as t ON e.textId = t.appText AND t.languageCode = 'hu' ")
|
||||
fun findAllWithTranslation(): List<AppText>
|
||||
}
|
||||
@@ -16,7 +16,7 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structure has been changed, increment this version number
|
||||
application.version=1.2.0
|
||||
application.version=1.2.1
|
||||
|
||||
jwt.secret=aitrainer
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structue has been changed, increment this version number
|
||||
application.version=1.2.0
|
||||
application.version=1.2.1
|
||||
|
||||
jwt.secret=aitrainer
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structue has been changed, increment this version number
|
||||
application.version=1.2.0
|
||||
application.version=1.2.1
|
||||
|
||||
jwt.secret=aitrainer
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structure has been changed, increment this version number
|
||||
application.version=1.2.0
|
||||
application.version=1.2.1
|
||||
|
||||
jwt.secret=aitrainer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user