-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from grida-diary/main
docs
- Loading branch information
Showing
92 changed files
with
732 additions
and
536 deletions.
There are no files selected for viewing
15 changes: 0 additions & 15 deletions
15
grida-clients/ai-client/src/main/kotlin/org/grida/chat/ChatCompletionClient.kt
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
grida-clients/ai-client/src/main/kotlin/org/grida/chat/ChatCompletionDto.kt
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
grida-clients/ai-client/src/main/kotlin/org/grida/chat/ChatCompletionOptions.kt
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
grida-clients/ai-client/src/main/kotlin/org/grida/config/AiClientConfig.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
grida-clients/ai-client/src/main/kotlin/org/grida/image/ImageGenerateClient.kt
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
grida-clients/ai-client/src/main/kotlin/org/grida/image/ImageGenerateDtos.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
grida-clients/ai-client/src/main/kotlin/org/grida/image/ImageGenerateOptions.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
dependencies { | ||
// feign client | ||
implementation("org.springframework.cloud:spring-cloud-starter-openfeign:3.1.8") | ||
implementation("io.github.openfeign:feign-jackson:12.1") | ||
|
||
// jackson | ||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") | ||
} |
27 changes: 27 additions & 0 deletions
27
grida-clients/kakao-client/src/main/kotlin/org/grida/auth/KakaoAuthApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.grida.auth | ||
|
||
import org.springframework.cloud.openfeign.FeignClient | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
|
||
@FeignClient( | ||
name = "KakaoAuth", | ||
url = "https://kauth.kakao.com/oauth", | ||
) | ||
interface KakaoAuthApi { | ||
|
||
@PostMapping("/token", headers = ["Content-type=application/x-www-form-urlencoded;charset=utf-8"]) | ||
fun provideToken( | ||
@RequestParam("grant_type") grantType: String, | ||
@RequestParam("client_id") clientId: String, | ||
@RequestParam("redirect_uri") redirectUri: String, | ||
@RequestParam("code") code: String | ||
): KakaoAuthResponse | ||
|
||
@PostMapping("/token", headers = ["Content-type=application/x-www-form-urlencoded;charset=utf-8"]) | ||
fun refreshToken( | ||
@RequestParam("grant_type") grantType: String, | ||
@RequestParam("client_id") clientId: String, | ||
@RequestParam("refresh_token") refreshToken: String | ||
): KakaoAuthResponse | ||
} |
39 changes: 39 additions & 0 deletions
39
grida-clients/kakao-client/src/main/kotlin/org/grida/auth/KakaoAuthClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.grida.auth | ||
|
||
import feign.FeignException | ||
import org.grida.config.KakaoProperties | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class KakaoAuthClient( | ||
private val kakaoAuthApi: KakaoAuthApi, | ||
private val kakaoProperties: KakaoProperties | ||
) { | ||
|
||
fun provideAuthToken(code: String): KakaoAuthToken { | ||
try { | ||
val response = kakaoAuthApi.provideToken( | ||
grantType = "authorization_code", | ||
clientId = kakaoProperties.appKey, | ||
redirectUri = kakaoProperties.redirectUri, | ||
code = code | ||
) | ||
return response.toKakaoAuthToken() | ||
} catch (e: FeignException) { | ||
throw IllegalArgumentException(e.stackTraceToString()) | ||
} | ||
} | ||
|
||
fun refreshToken(refreshToken: String): KakaoAuthToken { | ||
try { | ||
val response = kakaoAuthApi.refreshToken( | ||
grantType = "refresh_token", | ||
clientId = kakaoProperties.appKey, | ||
refreshToken = refreshToken | ||
) | ||
return response.toKakaoAuthToken() | ||
} catch (e: FeignException) { | ||
throw IllegalArgumentException(e.stackTraceToString()) | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
grida-clients/kakao-client/src/main/kotlin/org/grida/auth/KakaoAuthResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.grida.auth | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class KakaoAuthResponse( | ||
@JsonProperty("token_type") | ||
val tokenType: String, | ||
@JsonProperty("access_token") | ||
val accessToken: String, | ||
@JsonProperty("expires_in") | ||
val expiresId: Int, | ||
@JsonProperty("refresh_token") | ||
val refreshToken: String?, | ||
@JsonProperty("refresh_token_expires_in") | ||
val refreshTokenExpiredIn: Int? | ||
) { | ||
|
||
fun toKakaoAuthToken(): KakaoAuthToken { | ||
return KakaoAuthToken(accessToken, refreshToken ?: "") | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
grida-clients/kakao-client/src/main/kotlin/org/grida/auth/KakaoAuthToken.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.grida.auth | ||
|
||
data class KakaoAuthToken( | ||
val accessToken: String, | ||
val refreshToken: String | ||
) |
15 changes: 15 additions & 0 deletions
15
grida-clients/kakao-client/src/main/kotlin/org/grida/config/KakaoClientConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.grida.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan | ||
import org.springframework.cloud.openfeign.EnableFeignClients | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
@ConfigurationPropertiesScan | ||
@EnableFeignClients( | ||
basePackages = [ | ||
"org.grida.auth", | ||
"org.grida.user" | ||
] | ||
) | ||
class KakaoClientConfig |
11 changes: 11 additions & 0 deletions
11
grida-clients/kakao-client/src/main/kotlin/org/grida/config/KakaoProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.grida.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.ConstructorBinding | ||
|
||
@ConstructorBinding | ||
@ConfigurationProperties("kakao") | ||
data class KakaoProperties( | ||
val appKey: String, | ||
val redirectUri: String | ||
) |
20 changes: 20 additions & 0 deletions
20
grida-clients/kakao-client/src/main/kotlin/org/grida/user/KakaoUserApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.grida.user | ||
|
||
import org.springframework.cloud.openfeign.FeignClient | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestHeader | ||
import org.springframework.web.bind.annotation.RequestParam | ||
|
||
@FeignClient( | ||
name = "KakaoUser", | ||
url = "https://kapi.kakao.com/v2/user", | ||
) | ||
interface KakaoUserApi { | ||
|
||
@GetMapping("/me", headers = ["Content-type=application/x-www-form-urlencoded;charset=utf-8"]) | ||
fun readUserProfile( | ||
@RequestHeader("Authorization") bearerToken: String, | ||
@RequestParam("property_keys") propertyKeys: String, | ||
@RequestParam("secure_resource") secureResource: Boolean | ||
): KakaoUserProfileResponse | ||
} |
23 changes: 23 additions & 0 deletions
23
grida-clients/kakao-client/src/main/kotlin/org/grida/user/KakaoUserClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.grida.user | ||
|
||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class KakaoUserClient( | ||
private val kakaoUserApi: KakaoUserApi | ||
) { | ||
|
||
fun readUserProfile(accessToken: String): KakaoUserProfile { | ||
val response = kakaoUserApi.readUserProfile( | ||
bearerToken = "Bearer $accessToken", | ||
propertyKeys = QUERY_PROPERTY_KEYS, | ||
secureResource = true | ||
) | ||
|
||
return response.toKakaoUserProfile() | ||
} | ||
|
||
companion object { | ||
const val QUERY_PROPERTY_KEYS = "[\"kakao_account.profile\"]" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
grida-clients/kakao-client/src/main/kotlin/org/grida/user/KakaoUserProfile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.grida.user | ||
|
||
data class KakaoUserProfile( | ||
val id: String, | ||
val name: String | ||
) |
24 changes: 24 additions & 0 deletions
24
grida-clients/kakao-client/src/main/kotlin/org/grida/user/KakaoUserProfileResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.grida.user | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class KakaoUserProfileResponse( | ||
val id: String, | ||
@JsonProperty("kakao_account") | ||
val properties: KakaoAccount | ||
) { | ||
fun toKakaoUserProfile(): KakaoUserProfile { | ||
return KakaoUserProfile( | ||
id = id, | ||
name = properties.profile.nickname, | ||
) | ||
} | ||
} | ||
|
||
data class KakaoAccount( | ||
val profile: KakaoAccountProfile | ||
) | ||
|
||
data class KakaoAccountProfile( | ||
val nickname: String, | ||
) |
Empty file.
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
grida-clients/openai-client/src/main/kotlin/org/grida/chat/OpenAiChatApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.grida.chat | ||
|
||
import org.springframework.cloud.openfeign.FeignClient | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestHeader | ||
|
||
@FeignClient( | ||
name = "OpenAiChatCompletion", | ||
url = "https://api.openai.com/v1/chat/completions", | ||
) | ||
interface OpenAiChatApi { | ||
|
||
@PostMapping(headers = ["Content-Type=application/json"]) | ||
fun chat( | ||
@RequestHeader("Authorization") secretKey: String, | ||
@RequestBody request: OpenAiChatRequest | ||
): OpenAiChatResponse | ||
} |
30 changes: 30 additions & 0 deletions
30
grida-clients/openai-client/src/main/kotlin/org/grida/chat/OpenAiChatClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.grida.chat | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class OpenAiChatClient( | ||
private val openAiChatApi: OpenAiChatApi, | ||
private val openAiSecretKey: String, | ||
private val objectMapper: ObjectMapper | ||
) { | ||
|
||
fun <T> chat( | ||
prompt: String, | ||
valueType: Class<T> | ||
): T { | ||
val bearerToken = "Bearer $openAiSecretKey" | ||
val request = OpenAiChatRequest( | ||
model = "gpt-4o", | ||
role = "system", | ||
prompt = prompt, | ||
responseFormat = "json_object" | ||
) | ||
|
||
val response = openAiChatApi.chat(bearerToken, request) | ||
val result = response.result | ||
|
||
return objectMapper.readValue(result, valueType) | ||
} | ||
} |
Oops, something went wrong.