diff --git a/agents-flex-core/src/main/java/com/agentsflex/message/AiMessage.java b/agents-flex-core/src/main/java/com/agentsflex/message/AiMessage.java index fbbd53e..d430eb4 100644 --- a/agents-flex-core/src/main/java/com/agentsflex/message/AiMessage.java +++ b/agents-flex-core/src/main/java/com/agentsflex/message/AiMessage.java @@ -20,6 +20,8 @@ public class AiMessage extends TextMessage { private Integer index; private MessageStatus status; + private Integer promptTokens; + private Integer completionTokens; private Integer totalTokens; private String fullContent; @@ -39,6 +41,22 @@ public class AiMessage extends TextMessage { this.status = status; } + public Integer getPromptTokens() { + return promptTokens; + } + + public void setPromptTokens(Integer promptTokens) { + this.promptTokens = promptTokens; + } + + public Integer getCompletionTokens() { + return completionTokens; + } + + public void setCompletionTokens(Integer completionTokens) { + this.completionTokens = completionTokens; + } + public Integer getTotalTokens() { return totalTokens; } diff --git a/agents-flex-core/src/main/java/com/agentsflex/message/HumanMessage.java b/agents-flex-core/src/main/java/com/agentsflex/message/HumanMessage.java index d792788..41ecbb3 100644 --- a/agents-flex-core/src/main/java/com/agentsflex/message/HumanMessage.java +++ b/agents-flex-core/src/main/java/com/agentsflex/message/HumanMessage.java @@ -17,6 +17,9 @@ package com.agentsflex.message; public class HumanMessage extends TextMessage{ + public HumanMessage() { + } + public HumanMessage(String content) { setContent(content); } diff --git a/agents-flex-core/src/main/java/com/agentsflex/message/SystemMessage.java b/agents-flex-core/src/main/java/com/agentsflex/message/SystemMessage.java index eec09e3..08a79d4 100644 --- a/agents-flex-core/src/main/java/com/agentsflex/message/SystemMessage.java +++ b/agents-flex-core/src/main/java/com/agentsflex/message/SystemMessage.java @@ -17,6 +17,9 @@ package com.agentsflex.message; public class SystemMessage extends TextMessage { + public SystemMessage() { + } + public SystemMessage(String content) { this.content = content; } diff --git a/agents-flex-core/src/main/java/com/agentsflex/parser/impl/DefaultAiMessageParser.java b/agents-flex-core/src/main/java/com/agentsflex/parser/impl/DefaultAiMessageParser.java index cc895ca..65e5a9c 100644 --- a/agents-flex-core/src/main/java/com/agentsflex/parser/impl/DefaultAiMessageParser.java +++ b/agents-flex-core/src/main/java/com/agentsflex/parser/impl/DefaultAiMessageParser.java @@ -30,6 +30,8 @@ public class DefaultAiMessageParser implements AiMessageParser { private String indexPath; private String statusPath; private String totalTokensPath; + private String promptTokensPath; + private String completionTokensPath; private Parser statusParser; public String getContentPath() { @@ -64,6 +66,22 @@ public class DefaultAiMessageParser implements AiMessageParser { this.totalTokensPath = totalTokensPath; } + public String getPromptTokensPath() { + return promptTokensPath; + } + + public void setPromptTokensPath(String promptTokensPath) { + this.promptTokensPath = promptTokensPath; + } + + public String getCompletionTokensPath() { + return completionTokensPath; + } + + public void setCompletionTokensPath(String completionTokensPath) { + this.completionTokensPath = completionTokensPath; + } + public Parser getStatusParser() { return statusParser; } @@ -88,6 +106,13 @@ public class DefaultAiMessageParser implements AiMessageParser { aiMessage.setTotalTokens((Integer) JSONPath.eval(rootJson, this.totalTokensPath)); } + if (StringUtil.hasText(promptTokensPath)) { + aiMessage.setPromptTokens((Integer) JSONPath.eval(rootJson, this.promptTokensPath)); + } + if (StringUtil.hasText(completionTokensPath)) { + aiMessage.setCompletionTokens((Integer) JSONPath.eval(rootJson, this.completionTokensPath)); + } + if (StringUtil.hasText(this.statusPath)) { Object statusString = JSONPath.eval(rootJson, this.statusPath); if (this.statusParser != null) { diff --git a/agents-flex-llm/agents-flex-llm-chatglm/src/main/java/com/agentsflex/llm/chatglm/ChatglmLlmUtil.java b/agents-flex-llm/agents-flex-llm-chatglm/src/main/java/com/agentsflex/llm/chatglm/ChatglmLlmUtil.java index 8470a47..0a8dae5 100644 --- a/agents-flex-llm/agents-flex-llm-chatglm/src/main/java/com/agentsflex/llm/chatglm/ChatglmLlmUtil.java +++ b/agents-flex-llm/agents-flex-llm-chatglm/src/main/java/com/agentsflex/llm/chatglm/ChatglmLlmUtil.java @@ -86,6 +86,8 @@ public class ChatglmLlmUtil { aiMessageParser.setStatusPath("$.choices[0].finish_reason"); aiMessageParser.setStatusParser(content -> parseMessageStatus((String) content)); aiMessageParser.setTotalTokensPath("$.usage.total_tokens"); + aiMessageParser.setPromptTokensPath("$.usage.prompt_tokens"); + aiMessageParser.setCompletionTokensPath("$.usage.completion_tokens"); return aiMessageParser; } diff --git a/agents-flex-llm/agents-flex-llm-llama/src/main/java/com/agentsflex/llm/llama/LlamaLlmUtil.java b/agents-flex-llm/agents-flex-llm-llama/src/main/java/com/agentsflex/llm/llama/LlamaLlmUtil.java index e41165e..19a484c 100644 --- a/agents-flex-llm/agents-flex-llm-llama/src/main/java/com/agentsflex/llm/llama/LlamaLlmUtil.java +++ b/agents-flex-llm/agents-flex-llm-llama/src/main/java/com/agentsflex/llm/llama/LlamaLlmUtil.java @@ -35,6 +35,8 @@ public class LlamaLlmUtil { aiMessageParser.setStatusPath("$.choices[0].finish_reason"); aiMessageParser.setStatusParser(content -> parseMessageStatus((String) content)); aiMessageParser.setTotalTokensPath("$.usage.total_tokens"); + aiMessageParser.setPromptTokensPath("$.usage.prompt_tokens"); + aiMessageParser.setCompletionTokensPath("$.usage.completion_tokens"); return aiMessageParser; } diff --git a/agents-flex-llm/agents-flex-llm-openai/src/main/java/com/agentsflex/llm/openai/OpenAiLLmUtil.java b/agents-flex-llm/agents-flex-llm-openai/src/main/java/com/agentsflex/llm/openai/OpenAiLLmUtil.java index 34a9f89..a875615 100644 --- a/agents-flex-llm/agents-flex-llm-openai/src/main/java/com/agentsflex/llm/openai/OpenAiLLmUtil.java +++ b/agents-flex-llm/agents-flex-llm-openai/src/main/java/com/agentsflex/llm/openai/OpenAiLLmUtil.java @@ -44,6 +44,10 @@ public class OpenAiLLmUtil { aiMessageParser.setIndexPath("$.choices[0].index"); aiMessageParser.setStatusPath("$.choices[0].finish_reason"); aiMessageParser.setStatusParser(content -> parseMessageStatus((String) content)); + aiMessageParser.setTotalTokensPath("$.usage.total_tokens"); + aiMessageParser.setPromptTokensPath("$.usage.prompt_tokens"); + aiMessageParser.setCompletionTokensPath("$.usage.completion_tokens"); + return aiMessageParser; } diff --git a/agents-flex-llm/agents-flex-llm-qwen/src/main/java/com/agentsflex/llm/qwen/QwenLlmUtil.java b/agents-flex-llm/agents-flex-llm-qwen/src/main/java/com/agentsflex/llm/qwen/QwenLlmUtil.java index 16a7c00..2ab40fd 100644 --- a/agents-flex-llm/agents-flex-llm-qwen/src/main/java/com/agentsflex/llm/qwen/QwenLlmUtil.java +++ b/agents-flex-llm/agents-flex-llm-qwen/src/main/java/com/agentsflex/llm/qwen/QwenLlmUtil.java @@ -36,6 +36,9 @@ public class QwenLlmUtil { aiMessageParser.setStatusPath("$.output.finish_reason"); aiMessageParser.setTotalTokensPath("$.usage.total_tokens"); aiMessageParser.setStatusParser(content -> parseMessageStatus((String) content)); + aiMessageParser.setTotalTokensPath("$.usage.total_tokens"); + aiMessageParser.setPromptTokensPath("$.usage.input_tokens"); + aiMessageParser.setCompletionTokensPath("$.usage.output_tokens"); return aiMessageParser; } diff --git a/agents-flex-llm/agents-flex-llm-spark/src/main/java/com/agentsflex/llm/spark/SparkLlmUtil.java b/agents-flex-llm/agents-flex-llm-spark/src/main/java/com/agentsflex/llm/spark/SparkLlmUtil.java index 36b9aee..83996a9 100644 --- a/agents-flex-llm/agents-flex-llm-spark/src/main/java/com/agentsflex/llm/spark/SparkLlmUtil.java +++ b/agents-flex-llm/agents-flex-llm-spark/src/main/java/com/agentsflex/llm/spark/SparkLlmUtil.java @@ -67,6 +67,9 @@ public class SparkLlmUtil { aiMessageParser.setContentPath("$.payload.choices.text[0].content"); aiMessageParser.setIndexPath("$.payload.choices.text[0].index"); aiMessageParser.setStatusPath("$.payload.choices.status"); + aiMessageParser.setCompletionTokensPath("$.payload.usage.text.completion_tokens"); + aiMessageParser.setPromptTokensPath("$.payload.usage.text.prompt_tokens"); + aiMessageParser.setTotalTokensPath("$.payload.usage.text.total_tokens"); aiMessageParser.setStatusParser(content -> parseMessageStatus((Integer) content)); return aiMessageParser; }