From d74123200b6374531a24ce8c7ec2e916a8cc6218 Mon Sep 17 00:00:00 2001 From: djaler Date: Fri, 6 Oct 2023 23:11:11 +0300 Subject: [PATCH] =?UTF-8?q?chore:=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../djaler/evilbot/clients/YandexGptClient.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/github/djaler/evilbot/clients/YandexGptClient.kt b/src/main/kotlin/com/github/djaler/evilbot/clients/YandexGptClient.kt index 8e6dceb..f666202 100644 --- a/src/main/kotlin/com/github/djaler/evilbot/clients/YandexGptClient.kt +++ b/src/main/kotlin/com/github/djaler/evilbot/clients/YandexGptClient.kt @@ -8,7 +8,9 @@ import com.github.djaler.evilbot.config.yandex.YandexApiProperties import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.request.* +import io.ktor.client.statement.* import io.ktor.http.* +import org.apache.logging.log4j.LogManager import org.springframework.context.annotation.Conditional import org.springframework.stereotype.Component @@ -19,20 +21,30 @@ class YandexGptClient( private val httpClient: HttpClient, private val yandexApiProperties: YandexApiProperties ) { + companion object { + private val log = LogManager.getLogger() + } + suspend fun generateLinkThesis(link: String, sessionId: String? = null): ThesisResult { - return httpClient.post { + val response = httpClient.post { url("https://300.ya.ru/api/generation") contentType(ContentType.Application.Json) - setBody(mapOf( - "article_url" to link, - "session_id" to sessionId - )) + setBody( + mapOf( + "article_url" to link, + "session_id" to sessionId + ) + ) headers { append(HttpHeaders.Authorization, "OAuth ${yandexApiProperties.token}") } - }.body() + } + + log.info("yandex gpt response: ${response.bodyAsText()}") + + return response.body() } }