-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Tokens in Evaluator Tests (#730) * Estimate price in Evaluator Tests (#731) * Enum description in tools (#732) * support enum descriptions * added example --------- Co-authored-by: José Carlos Montañez <[email protected]> Co-authored-by: Raúl Raja Martínez <[email protected]> * Update README with instruction to build locally (#725) * Add README instructions for building Xef * Include reasons why build may fail if you don't have docker * fixed error in enum description (#733) Co-authored-by: José Carlos Montañez <[email protected]> --------- Co-authored-by: Javier Pérez Pacheco <[email protected]> Co-authored-by: José Carlos Montañez <[email protected]> Co-authored-by: José Carlos Montañez <[email protected]> Co-authored-by: Raúl Raja Martínez <[email protected]>
- Loading branch information
1 parent
2b8f99b
commit d9dfd74
Showing
15 changed files
with
281 additions
and
216 deletions.
There are no files selected for viewing
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
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
18 changes: 18 additions & 0 deletions
18
core/src/commonMain/kotlin/com/xebia/functional/xef/llm/models/Messages.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,18 @@ | ||
package com.xebia.functional.xef.llm.models | ||
|
||
import com.xebia.functional.openai.generated.model.CompletionUsage | ||
|
||
data class MessagesWithUsage(val messages: List<String>, val usage: MessagesUsage?) | ||
|
||
data class MessageWithUsage(val message: String, val usage: MessagesUsage?) | ||
|
||
data class MessagesUsage(val completionTokens: Int, val promptTokens: Int, val totalTokens: Int) { | ||
companion object { | ||
operator fun invoke(usage: CompletionUsage) = | ||
MessagesUsage( | ||
completionTokens = usage.completionTokens, | ||
promptTokens = usage.promptTokens, | ||
totalTokens = usage.totalTokens | ||
) | ||
} | ||
} |
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
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
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
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
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
44 changes: 44 additions & 0 deletions
44
evaluator/src/main/kotlin/com/xebia/functional/xef/evaluator/models/ModelsPricing.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,44 @@ | ||
package com.xebia.functional.xef.evaluator.models | ||
|
||
data class ModelsPricing( | ||
val modelName: String, | ||
val currency: String, | ||
val input: ModelsPricingItem, | ||
val output: ModelsPricingItem | ||
) { | ||
|
||
companion object { | ||
|
||
const val oneMillion = 1_000_000 | ||
val oneThousand = 1_000 | ||
|
||
// The pricing for the models was updated the May 2st, 2024 | ||
// Be sure to update the pricing for each model | ||
|
||
val gpt4Turbo = | ||
ModelsPricing( | ||
modelName = "gpt-4-turbo", | ||
currency = "USD", | ||
input = ModelsPricingItem(10.0, oneMillion), | ||
output = ModelsPricingItem(30.0, oneMillion) | ||
) | ||
|
||
val gpt4 = | ||
ModelsPricing( | ||
modelName = "gpt-4-turbo", | ||
currency = "USD", | ||
input = ModelsPricingItem(30.0, oneMillion), | ||
output = ModelsPricingItem(60.0, oneMillion) | ||
) | ||
|
||
val gpt3_5Turbo = | ||
ModelsPricing( | ||
modelName = "gpt-3.5-turbo", | ||
currency = "USD", | ||
input = ModelsPricingItem(0.5, oneMillion), | ||
output = ModelsPricingItem(1.5, oneMillion) | ||
) | ||
} | ||
} | ||
|
||
data class ModelsPricingItem(val price: Double, val perTokens: Int) |
53 changes: 50 additions & 3 deletions
53
evaluator/src/main/kotlin/com/xebia/functional/xef/evaluator/models/TestModels.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 |
---|---|---|
@@ -1,17 +1,64 @@ | ||
package com.xebia.functional.xef.evaluator.models | ||
|
||
import com.xebia.functional.xef.llm.models.MessageWithUsage | ||
import com.xebia.functional.xef.llm.models.MessagesUsage | ||
import kotlin.jvm.JvmSynthetic | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable data class OutputDescription(val value: String) | ||
|
||
@Serializable | ||
data class OutputResponse(val description: OutputDescription, val value: String) { | ||
data class OutputResponse( | ||
val description: OutputDescription, | ||
val tokens: OutputTokens?, | ||
val value: String | ||
) { | ||
companion object { | ||
@JvmSynthetic | ||
suspend operator fun invoke( | ||
description: OutputDescription, | ||
block: suspend () -> String | ||
): OutputResponse = OutputResponse(description, block()) | ||
price: ModelsPricing?, | ||
block: suspend () -> MessageWithUsage | ||
): OutputResponse { | ||
val response = block() | ||
return OutputResponse( | ||
description, | ||
response.usage?.let { OutputTokens(it, price) }, | ||
response.message | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Serializable | ||
data class OutputTokens( | ||
val promptTokens: Int? = null, | ||
val estimatePricePerToken: Double? = null, | ||
val completionTokens: Int? = null, | ||
val estimatePriceCompletionToken: Double? = null, | ||
val totalTokens: Int? = null, | ||
val estimatePriceTotalToken: Double? = null, | ||
val currency: String? | ||
) { | ||
companion object { | ||
@JvmSynthetic | ||
operator fun invoke(usage: MessagesUsage, price: ModelsPricing?): OutputTokens { | ||
val estimateInputPrice = | ||
price?.let { usage.promptTokens.let { (it * price.input.price) / price.input.perTokens } } | ||
val estimateOutputPrice = | ||
price?.let { | ||
usage.completionTokens.let { (it * price.output.price) / price.output.perTokens } | ||
} | ||
val estimateTotalPrice = estimateInputPrice?.plus(estimateOutputPrice ?: 0.0) | ||
return OutputTokens( | ||
usage.promptTokens, | ||
estimateInputPrice, | ||
usage.completionTokens, | ||
estimateOutputPrice, | ||
usage.totalTokens, | ||
estimateTotalPrice, | ||
price?.currency | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.