11package org.gitanimals.quiz.app
22
3- import org.gitanimals.quiz.app.OpenAI.Request.Message
3+ import org.slf4j.LoggerFactory
44import org.springframework.stereotype.Component
55import org.springframework.web.bind.annotation.RequestBody
66import org.springframework.web.service.annotation.PostExchange
@@ -10,14 +10,23 @@ class AIApi(
1010 private val openAI : OpenAI ,
1111) {
1212
13+ private val logger = LoggerFactory .getLogger(this ::class .simpleName)
14+
1315 fun isDevelopmentQuiz (prompt : String , text : String ): Boolean {
1416 val request = OpenAI .Request (
15- messages = listOf (
16- Message (role = " system" , content = prompt),
17- Message (role = " user" , content = text)
18- )
17+ instructions = prompt,
18+ input = text,
1919 )
20- val aiResponseContent = openAI.invoke(request).choices.first().message.content
20+
21+ logger.info(" [AIApi] request: $request " )
22+ val aiResponseContent = openAI.invoke(request)
23+ .also {
24+ logger.info(" [AIApi] response: $it " )
25+ }
26+ .output
27+ .first { it.type == " message" }
28+ .content[0 ].text
29+
2130 return when (aiResponseContent.trim().lowercase()) {
2231 " true" -> true
2332 " false" -> false
@@ -28,12 +37,13 @@ class AIApi(
2837
2938fun interface OpenAI {
3039
31- @PostExchange(" /v1/chat/completions " )
40+ @PostExchange(" /v1/responses " )
3241 fun invoke (@RequestBody request : Request ): Response
3342
3443 data class Request (
35- val model : String = " o4-mini" ,
36- val messages : List <Message >,
44+ val model : String = " gpt-5-nano" ,
45+ val instructions : String ,
46+ val input : String ,
3747 ) {
3848
3949 data class Message (
@@ -44,41 +54,18 @@ fun interface OpenAI {
4454
4555 data class Response (
4656 val id : String ,
47- val `object `: String ,
48- val created : Long ,
4957 val model : String ,
50- val choices : List <Choice >,
51- val usage : Usage ,
52- val service_tier : String ,
53- val system_fingerprint : String? = null ,
58+ val output : List <Output >,
5459 ) {
55- data class Choice (
56- val index : Int ,
57- val message : Message ,
58- val logprobs : String? ,
59- val finish_reason : String
60+ data class Output (
61+ val id : String ,
62+ val type : String ,
63+ val content : List <Content >,
6064 ) {
6165
62- data class Message (
63- val role : String ,
64- val content : String ,
65- val refusal : String? ,
66- val annotations : List <String >
67- ) {
68-
69- }
70- }
71-
72- data class Usage (
73- val prompt_tokens : Int ,
74- val completion_tokens : Int ,
75- val total_tokens : Int ,
76- val prompt_tokens_details : TokenDetails ,
77- val completion_tokens_details : TokenDetails
78- ) {
79- data class TokenDetails (
80- val cached_tokens : Int ,
81- val audio_tokens : Int
66+ data class Content (
67+ val type : String ,
68+ val text : String ,
8269 )
8370 }
8471 }
0 commit comments