refactor: Update ModelProfile to use costPerInToken and costPerOutToken for better clarity and accuracy
This commit is contained in:
@@ -111,8 +111,8 @@ final var modelProfile = new ModelProfile(
|
|||||||
"gpt-4", // modelName
|
"gpt-4", // modelName
|
||||||
"https://api.openai.com/v1", // url
|
"https://api.openai.com/v1", // url
|
||||||
System.getenv("OPENAI_API_KEY"), // apiKey
|
System.getenv("OPENAI_API_KEY"), // apiKey
|
||||||
new BigDecimal("0.03"), // costInToken (per token)
|
new BigDecimal("0.3").divide(1000000), // costPerInToken (per token)
|
||||||
new BigDecimal("0.06"), // costOutToken (per token)
|
new BigDecimal("0.6").divide(1000000), // costPerOutToken (per token)
|
||||||
null, // reasoningEffort
|
null, // reasoningEffort
|
||||||
null, // reasoningSummaryDetails
|
null, // reasoningSummaryDetails
|
||||||
"DYNAMIC" // category (short name for logging)
|
"DYNAMIC" // category (short name for logging)
|
||||||
@@ -558,8 +558,8 @@ final var customProfile = new ModelProfile(
|
|||||||
"gpt-4-turbo", // modelName
|
"gpt-4-turbo", // modelName
|
||||||
"https://api.openai.com/v1", // url
|
"https://api.openai.com/v1", // url
|
||||||
System.getenv("OPENAI_API_KEY"), // apiKey
|
System.getenv("OPENAI_API_KEY"), // apiKey
|
||||||
new BigDecimal("0.01"), // costInToken
|
new BigDecimal("0.3").divide(1000000), // costPerInToken (per token)
|
||||||
new BigDecimal("0.03"), // costOutToken
|
new BigDecimal("0.6").divide(1000000), // costPerOutToken (per token)
|
||||||
null, // reasoningEffort
|
null, // reasoningEffort
|
||||||
null, // reasoningSummaryDetails
|
null, // reasoningSummaryDetails
|
||||||
"GPT4T" // category
|
"GPT4T" // category
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<artifactId>lm-lib</artifactId>
|
<artifactId>lm-lib</artifactId>
|
||||||
<groupId>de.extio</groupId>
|
<groupId>de.extio</groupId>
|
||||||
<name>lm-lib</name>
|
<name>lm-lib</name>
|
||||||
<version>1.8.1</version>
|
<version>1.8.2</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ public final class AzureAiClient implements Client {
|
|||||||
Duration.between(start, LocalDateTime.now()),
|
Duration.between(start, LocalDateTime.now()),
|
||||||
promptTokens,
|
promptTokens,
|
||||||
completionTokens,
|
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);
|
false);
|
||||||
LOGGER.debug("{}", statistics);
|
LOGGER.debug("{}", statistics);
|
||||||
return statistics;
|
return statistics;
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ public abstract class AbstractCompletionClient implements Client, DisposableBean
|
|||||||
Duration.between(start, LocalDateTime.now()),
|
Duration.between(start, LocalDateTime.now()),
|
||||||
inTokens,
|
inTokens,
|
||||||
outTokens,
|
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);
|
false);
|
||||||
LOGGER.debug("{}", statistics);
|
LOGGER.debug("{}", statistics);
|
||||||
if (this.collectStatistics) {
|
if (this.collectStatistics) {
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ public record ModelProfile(
|
|||||||
String modelName,
|
String modelName,
|
||||||
String url,
|
String url,
|
||||||
String apiKey,
|
String apiKey,
|
||||||
BigDecimal costInToken,
|
BigDecimal costPerInToken,
|
||||||
BigDecimal costOutToken,
|
BigDecimal costPerOutToken,
|
||||||
String reasoningEffort,
|
String reasoningEffort,
|
||||||
String reasoningSummaryDetails,
|
String reasoningSummaryDetails,
|
||||||
String category) {
|
String category) {
|
||||||
|
|||||||
@@ -71,12 +71,12 @@ public class ModelProfileService {
|
|||||||
final var url = Optional.ofNullable(resource.getProperty("url"))
|
final var url = Optional.ofNullable(resource.getProperty("url"))
|
||||||
.map(Object::toString)
|
.map(Object::toString)
|
||||||
.orElseThrow(() -> new IllegalStateException("No model url found for model: " + modelName));
|
.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(Object::toString)
|
||||||
.map(value -> new BigDecimal(value))
|
.map(value -> new BigDecimal(value))
|
||||||
.orElse(BigDecimal.ZERO)
|
.orElse(BigDecimal.ZERO)
|
||||||
.divide(new BigDecimal(1000000.0));
|
.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(Object::toString)
|
||||||
.map(value -> new BigDecimal(value))
|
.map(value -> new BigDecimal(value))
|
||||||
.orElse(BigDecimal.ZERO)
|
.orElse(BigDecimal.ZERO)
|
||||||
@@ -103,7 +103,7 @@ public class ModelProfileService {
|
|||||||
.orElse(null);
|
.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) {
|
catch (final IOException e) {
|
||||||
LOGGER.error("Error while reading model profile", e);
|
LOGGER.error("Error while reading model profile", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user