Skip to content

Commit

Permalink
🎨 Logprobs data class 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
이용홍 committed Mar 10, 2023
1 parent a610bb5 commit e4d92e5
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 13 deletions.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down
10 changes: 8 additions & 2 deletions openai/src/main/kotlin/herbaccara/openai/OpenAiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ class OpenAiService @JvmOverloads constructor(
fun proxy(proxy: Proxy): Builder = apply { this.proxy = proxy }

fun build(): OpenAiService {
if (apiKey == null) throw OpenAiException.IllegalArgumentException("\"api-key\" must not be null")
return OpenAiService(apiKey!!, baseUrl, timeout, validate, logging, proxy)
return OpenAiService(
requireNotNull(apiKey) { "\"apiKey\" must not be null" },
baseUrl,
timeout,
validate,
logging,
proxy
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ sealed interface OpenAiException {
cause: Throwable? = null,
val error: Error? = null
) : RuntimeException(message, cause), OpenAiException

class IllegalArgumentException(message: String? = null, cause: Throwable? = null) :
kotlin.IllegalArgumentException(message, cause), OpenAiException
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package herbaccara.openai.form.validation

import herbaccara.openai.exception.OpenAiException
import java.io.File
import kotlin.reflect.KProperty0

Expand All @@ -25,7 +24,7 @@ object ValidationUtils {

fun between(field: KProperty0<Number?>, start: Double, end: Double) {
val value = field.get() ?: return
if (value.toDouble() !in start..end) throw OpenAiException.IllegalArgumentException("\"${field.name}\" must be between $start and $end")
if (value.toDouble() !in start..end) throw IllegalArgumentException("\"${field.name}\" must be between $start and $end")
}

fun lessThan(field: KProperty0<String?>, limit: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.JsonProperty
data class CompletionChoice(
val text: String,
val index: Int,
val logprobs: Map<String, Any>?,
@field:JsonProperty("finish_reason")
val finishReason: String?
val logprobs: Logprobs?,
@field:JsonProperty("finish_reason") val finishReason: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package herbaccara.openai.model.completion

import com.fasterxml.jackson.annotation.JsonProperty

data class Logprobs(
@field:JsonProperty("text_offset") val textOffset: List<Int>,
@field:JsonProperty("token_logprobs") val tokenLogprobs: List<Double>,
val tokens: List<String>,
@field:JsonProperty("top_logprobs") val topLogprobs: List<Map<String, Double>>
)

0 comments on commit e4d92e5

Please sign in to comment.