-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] java.lang.NullPointerException - "tokenUsageAccumulator" is null - when using LocalAI function calling #935
Comments
dev.langchain4j.model.localai.LocalAiChatModel#generate(java.util.List<dev.langchain4j.data.message.ChatMessage>, java.util.List<dev.langchain4j.agent.tool.ToolSpecification>, dev.langchain4j.agent.tool.ToolSpecification) private Response<AiMessage> generate(List<ChatMessage> messages,
List<ToolSpecification> toolSpecifications,
ToolSpecification toolThatMustBeExecuted
) {
ChatCompletionRequest.Builder requestBuilder = ChatCompletionRequest.builder()
.model(modelName)
.messages(toOpenAiMessages(messages))
.temperature(temperature)
.topP(topP)
.maxTokens(maxTokens);
...
return Response.from(
aiMessageFrom(response),
null,
finishReasonFrom(response.choices().get(0).finishReason())
);
} the response of
I hope to try to solve it~ |
Related to #921 |
@Kugaaa I think AI Service should be changed to handle Ideally, |
Please raise priority |
@ohadpinch it should have been fixed by https://github.com/langchain4j/langchain4j/pull/939/files, could you please check the latest version (or snapshot)? |
I checked it, it's fixed with those changes. |
@ohadpinch thank you! |
Fixed by #939 |
@langchain4j sorry for the mix up! |
@langchain4j I think #939 not compatible with this situation #942 If the solution is just return a null value, it appears that too little information is provided, so I want to use the null object mode return a |
…Usage instance with null fields when openAi Usage is null
## Issue Fix #935 ## Change Replaced `TokenUsage.add(TokanUsage)` with static `TokenUsage.sum(TokanUsage, TokanUsage)` to better handle cases when one of the `TokanUsage` is absent (null). ## General checklist <!-- Please double-check the following points and mark them like this: [X] --> - [X] There are no breaking changes - [X] I have added unit and integration tests for my change - [X] I have manually run all the unit and integration tests in the module I have added/changed, and they are all green - [X] I have manually run all the unit and integration tests in the [core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core) and [main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j) modules, and they are all green <!-- Before adding documentation and example(s) (below), please wait until the PR is reviewed and approved. --> - [ ] I have added/updated the [documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs) - [ ] I have added an example in the [examples repo](https://github.com/langchain4j/langchain4j-examples) (only for "big" features)
Describe the bug
When implementing function calling using LocalAI a NPE is thrown stating "tokenUsageAccumulator" is null
Log and Stack trace
To Reproduce
Following is the jbang script
Expected behavior
Should call the function and return the result
Please complete the following information:
Additional context
The text was updated successfully, but these errors were encountered: