Skip to content

Commit

Permalink
add support for amazon nova models in v1
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyuan-he committed Dec 11, 2024
1 parent a593ff8 commit 6eda62e
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private static String approximateTokenCount(Map<String, Object> jsonBody, String
}

// Model -> Path Mapping:
// Amazon Nova -> "/inferenceConfig/max_new_tokens"
// Amazon Titan -> "/textGenerationConfig/maxTokenCount"
// Anthropic Claude -> "/max_tokens"
// Cohere Command -> "/max_tokens"
Expand All @@ -106,10 +107,15 @@ private static String approximateTokenCount(Map<String, Object> jsonBody, String
static String getMaxTokens(Object target) {
Map<String, Object> jsonBody = getJsonBody(target);
return findFirstMatchingPath(
jsonBody, "/max_tokens", "/max_gen_len", "/textGenerationConfig/maxTokenCount");
jsonBody,
"/max_tokens",
"/max_gen_len",
"/textGenerationConfig/maxTokenCount",
"/inferenceConfig/max_new_tokens");
}

// Model -> Path Mapping:
// Amazon Nova -> "/inferenceConfig/temperature"
// Amazon Titan -> "/textGenerationConfig/temperature"
// Anthropic Claude -> "/temperature"
// Cohere Command -> "/temperature"
Expand All @@ -120,10 +126,15 @@ static String getMaxTokens(Object target) {
@Nullable
static String getTemperature(Object target) {
Map<String, Object> jsonBody = getJsonBody(target);
return findFirstMatchingPath(jsonBody, "/temperature", "/textGenerationConfig/temperature");
return findFirstMatchingPath(
jsonBody,
"/temperature",
"/textGenerationConfig/temperature",
"inferenceConfig/temperature");
}

// Model -> Path Mapping:
// Amazon Nova -> "/inferenceConfig/top_p"
// Amazon Titan -> "/textGenerationConfig/topP"
// Anthropic Claude -> "/top_p"
// Cohere Command -> "/p"
Expand All @@ -134,10 +145,12 @@ static String getTemperature(Object target) {
@Nullable
static String getTopP(Object target) {
Map<String, Object> jsonBody = getJsonBody(target);
return findFirstMatchingPath(jsonBody, "/top_p", "/p", "/textGenerationConfig/topP");
return findFirstMatchingPath(
jsonBody, "/top_p", "/p", "/textGenerationConfig/topP", "/inferenceConfig/top_p");
}

// Model -> Path Mapping:
// Amazon Nova -> "/usage/inputTokens"
// Amazon Titan -> "/inputTextTokenCount"
// Anthropic Claude -> "/usage/input_tokens"
// Cohere Command -> "/prompt"
Expand All @@ -159,7 +172,8 @@ static String getInputTokens(Object target) {
"/inputTextTokenCount",
"/prompt_token_count",
"/usage/input_tokens",
"/usage/prompt_tokens");
"/usage/prompt_tokens",
"/usage/inputTokens");

if (directCount != null && !directCount.equals("null")) {
return directCount;
Expand All @@ -170,6 +184,7 @@ static String getInputTokens(Object target) {
}

// Model -> Path Mapping:
// Amazon Nova -> "/usage/outputTokens"
// Amazon Titan -> "/results/0/tokenCount"
// Anthropic Claude -> "/usage/output_tokens"
// Cohere Command -> "/generations/0/text"
Expand All @@ -191,7 +206,8 @@ static String getOutputTokens(Object target) {
"/generation_token_count",
"/results/0/tokenCount",
"/usage/output_tokens",
"/usage/completion_tokens");
"/usage/completion_tokens",
"/usage/outputTokens");

if (directCount != null && !directCount.equals("null")) {
return directCount;
Expand All @@ -202,6 +218,7 @@ static String getOutputTokens(Object target) {
}

// Model -> Path Mapping:
// Amazon Nova -> "/stopReason"
// Amazon Titan -> "/results/0/completionReason"
// Anthropic Claude -> "/stop_reason"
// Cohere Command -> "/generations/0/finish_reason"
Expand All @@ -215,6 +232,7 @@ static String getFinishReasons(Object target) {
String finishReason =
findFirstMatchingPath(
jsonBody,
"/stopReason",
"/finish_reason",
"/stop_reason",
"/results/0/completionReason",
Expand Down

0 comments on commit 6eda62e

Please sign in to comment.