davsclaus opened a new pull request, #27976:
URL: https://github.com/apache/camel/pull/27976

   Eleventh batch of 
[CAMEL-23688](https://issues.apache.org/jira/browse/CAMEL-23688) (test coverage 
of the CLI commands): the chat with tools of `LlmClient` (38% line coverage 
before), which `camel ask` uses. The existing LlmClient tests cover listing the 
models, the context window of Ollama and the Azure, Gemini, Vertex and watsonx 
specifics; the chat with Ollama, OpenAI-compatible servers and Anthropic was 
not tested.
   
   ### Tests
   - `LlmClientChatTest` (new), against `FakeLlmServer` playing each provider:
     - Ollama: the request (`think`, `keep_alive`, `num_ctx`, the tools), the 
answer with its tool calls and token usage (cached tokens, generation time), 
and the streamed answer printed as it comes, with a tool call whose arguments 
are text.
     - OpenAI-compatible: the tool calls, token usage and `Authorization` 
header, the reasoning when there is no content, and tool-call arguments as an 
object.
     - Anthropic: the `x-api-key` and `anthropic-version` headers, the system 
prompt apart, the tools with their `input_schema`, the `tool_use` blocks and 
usage.
     - The conversation (a question, a tool call and its result) in the format 
of each provider.
     - The errors: a `401` with the message of the provider, a streamed `404`, 
a connection that is refused (chat and generate), and `extractErrorMessage`.
   - `FakeLlmServer` can give the reply of any path (a test gives the answer of 
`/api/chat`, `/v1/chat/completions` or `/v1/messages`), and keeps the headers 
of the last request.
   
   ### Bugs the tests found
   - **A streamed answer that failed printed the error on stdout**, after the 
answer so far (`Error during streaming: ...`), while the errors of a request 
that is not streamed go to stderr. `camel explain`, `camel ask` and `camel 
overview --ai` stream against Ollama by default, so the error was mixed into 
the answer a script or an AI agent reads. Now on stderr, after the line of the 
answer so far is ended. `camel harden`, which has its own HTTP client, printed 
`ERROR:` followed by an empty line; fixed the same way.
   - **A failure without a message**, such as a refused connection (Java's 
`ConnectException` has none), printed `null`; now the message of its cause 
(`Connection refused`).
   - **The arguments of a tool call** that an OpenAI-compatible server gives as 
a JSON object, instead of JSON text, were dropped, and the tool called without 
arguments. The Ollama parser already took both.
   
   The user-visible changes are in the 4.24 upgrade guide.
   
   `mvn test` of the LlmClient, explain, harden and overview tests of 
camel-jbang-core: all pass. Each fix was checked by running the new tests 
without it: the 3 tests of the bugs fail.
   
   _Claude Code on behalf of davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_01DDRLJAyf8cDXSg8iX785My
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to