refactor: Update ModelProfile to use costPerInToken and costPerOutToken for better clarity and accuracy

This commit is contained in:
extio-de
2025-10-31 16:15:37 +01:00
parent 12a48868b6
commit bd37a143f6
6 changed files with 12 additions and 12 deletions

View File

@@ -111,8 +111,8 @@ final var modelProfile = new ModelProfile(
"gpt-4", // modelName
"https://api.openai.com/v1", // url
System.getenv("OPENAI_API_KEY"), // apiKey
new BigDecimal("0.03"), // costInToken (per token)
new BigDecimal("0.06"), // costOutToken (per token)
new BigDecimal("0.3").divide(1000000), // costPerInToken (per token)
new BigDecimal("0.6").divide(1000000), // costPerOutToken (per token)
null, // reasoningEffort
null, // reasoningSummaryDetails
"DYNAMIC" // category (short name for logging)
@@ -558,8 +558,8 @@ final var customProfile = new ModelProfile(
"gpt-4-turbo", // modelName
"https://api.openai.com/v1", // url
System.getenv("OPENAI_API_KEY"), // apiKey
new BigDecimal("0.01"), // costInToken
new BigDecimal("0.03"), // costOutToken
new BigDecimal("0.3").divide(1000000), // costPerInToken (per token)
new BigDecimal("0.6").divide(1000000), // costPerOutToken (per token)
null, // reasoningEffort
null, // reasoningSummaryDetails
"GPT4T" // category

View File

@@ -4,7 +4,7 @@
<artifactId>lm-lib</artifactId>
<groupId>de.extio</groupId>
<name>lm-lib</name>
<version>1.8.1</version>
<version>1.8.2</version>
<properties>
<java.version>21</java.version>

View File

@@ -291,7 +291,7 @@ public final class AzureAiClient implements Client {
Duration.between(start, LocalDateTime.now()),
promptTokens,
completionTokens,
new BigDecimal(promptTokens).multiply(modelProfile.costInToken()).add(new BigDecimal(completionTokens).multiply(modelProfile.costOutToken())),
new BigDecimal(promptTokens).multiply(modelProfile.costPerInToken()).add(new BigDecimal(completionTokens).multiply(modelProfile.costPerOutToken())),
false);
LOGGER.debug("{}", statistics);
return statistics;

View File

@@ -161,7 +161,7 @@ public abstract class AbstractCompletionClient implements Client, DisposableBean
Duration.between(start, LocalDateTime.now()),
inTokens,
outTokens,
new BigDecimal(inTokens).multiply(modelProfile.costInToken()).add(new BigDecimal(outTokens).multiply(modelProfile.costOutToken())),
new BigDecimal(inTokens).multiply(modelProfile.costPerInToken()).add(new BigDecimal(outTokens).multiply(modelProfile.costPerOutToken())),
false);
LOGGER.debug("{}", statistics);
if (this.collectStatistics) {

View File

@@ -13,8 +13,8 @@ public record ModelProfile(
String modelName,
String url,
String apiKey,
BigDecimal costInToken,
BigDecimal costOutToken,
BigDecimal costPerInToken,
BigDecimal costPerOutToken,
String reasoningEffort,
String reasoningSummaryDetails,
String category) {

View File

@@ -71,12 +71,12 @@ public class ModelProfileService {
final var url = Optional.ofNullable(resource.getProperty("url"))
.map(Object::toString)
.orElseThrow(() -> new IllegalStateException("No model url found for model: " + modelName));
final var costInToken = Optional.ofNullable(resource.getProperty("cost1MInTokens"))
final var costPerInToken = Optional.ofNullable(resource.getProperty("cost1MInTokens"))
.map(Object::toString)
.map(value -> new BigDecimal(value))
.orElse(BigDecimal.ZERO)
.divide(new BigDecimal(1000000.0));
final var costOutToken = Optional.ofNullable(resource.getProperty("cost1MOutTokens"))
final var costPerOutToken = Optional.ofNullable(resource.getProperty("cost1MOutTokens"))
.map(Object::toString)
.map(value -> new BigDecimal(value))
.orElse(BigDecimal.ZERO)
@@ -103,7 +103,7 @@ public class ModelProfileService {
.orElse(null);
}
return new ModelProfile(promptTemplate, tokenEncoding, maxTokens, maxContextLength, temperature, topP, modelProvider, modelNameCfg, url, apiKey, costInToken, costOutToken, reasoningEffort, reasoningSummaryDetails, category);
return new ModelProfile(promptTemplate, tokenEncoding, maxTokens, maxContextLength, temperature, topP, modelProvider, modelNameCfg, url, apiKey, costPerInToken, costPerOutToken, reasoningEffort, reasoningSummaryDetails, category);
}
catch (final IOException e) {
LOGGER.error("Error while reading model profile", e);