[ 
https://issues.apache.org/jira/browse/CAMEL-27513?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150304#comment-18150304
 ] 

Guillaume Nodet commented on CAMEL-27513:
-----------------------------------------

This issue is being investigated by a coding agent (on behalf of gnodet).

Root cause confirmed in code: Explain.stream defaults to true, and 
handleExplanationResult (Explain.java:250) only prints the response when 
!stream. However, generateOpenAi and generateGemini in LlmClient.java always 
send a non-streaming request and return the full text as a string. When 
stream=true (the default), Explain assumes the text was already printed inline 
(as Ollama and Anthropic do), but OpenAI and Gemini never print inline — so the 
response is silently dropped.

Fix: have generate() report whether the response was actually streamed (like 
ChatResponse.streamed() does for camel ask), and in handleExplanationResult 
print the response unless it was truly streamed. Add an ExplainTest case with 
--api-type=openai against a fake LLM server.

_Note: This comment was generated by an AI coding agent and requires manual 
verification._

> camel-jbang - camel explain prints no explanation with an OpenAI-compatible 
> or Gemini provider
> ----------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27513
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27513
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-jbang
>    Affects Versions: 4.23.0
>            Reporter: Federico Mariani
>            Assignee: Guillaume Nodet
>            Priority: Major
>
> h3. Problem
> With an OpenAI-compatible provider ({{--api-type=openai}}, which also covers 
> Azure OpenAI and watsonx) or Gemini, {{camel explain}} prints the header and 
> {{Analyzing route with <model> (openai)...}}, then nothing, and exits with 0. 
> The LLM call succeeds (HTTP 200, the response has the text), but the 
> explanation is never printed.
> Ollama and Anthropic are not affected.
> h3. Reproducer
> Any OpenAI-compatible server shows it. Without one, a fake server that 
> answers every chat completion with a fixed text is enough:
> {noformat}
> import http.server, json
> RESP = json.dumps({"object": "chat.completion", "model": "m", "choices": 
> [{"index": 0, "finish_reason": "stop",
>        "message": {"role": "assistant", "content": 
> "HELLO-FROM-FAKE"}}]}).encode()
> class H(http.server.BaseHTTPRequestHandler):
>     def _send(self, data):
>         self.send_response(200); self.send_header("Content-Type", 
> "application/json")
>         self.send_header("Content-Length", str(len(data))); 
> self.end_headers(); self.wfile.write(data)
>     def do_GET(self):
>         self._send(json.dumps({"data": [{"id": "m"}]}).encode())
>     def do_POST(self):
>         self.rfile.read(int(self.headers.get("Content-Length") or 0)); 
> self._send(RESP)
> http.server.HTTPServer(("127.0.0.1", 18557), H).serve_forever()
> {noformat}
> {noformat}
> camel explain orders.camel.yaml --api-type=openai 
> --url=http://127.0.0.1:18557 --api-key=x --model=m
> {noformat}
> ||CLI||no flag||--stream||--stream=false||
> |4.23.0|nothing printed|answer printed|not tried|
> |4.24.0-SNAPSHOT (main)|nothing printed|nothing printed|answer printed|
> On main the only way to see the answer is {{--stream=false}}. On 4.23.0, 
> {{--stream}} happens to flip the default to false.
> h3. Cause
> * {{Explain}}: {{stream}} defaults to {{true}}, and 
> {{handleExplanationResult}} prints the explanation only when {{!stream}}. It 
> assumes the client already printed the text while streaming.
> * {{LlmClient.generate}}: {{generateOllama}} and {{generateAnthropic}} stream 
> when {{stream}} is set. {{generateOpenAi}} and {{generateGemini}} always send 
> a non-streaming request and only return the text. For those providers, the 
> text comes back and {{Explain}} drops it.
> * {{ExplainTest}} only runs against Ollama ({{--api-type=ollama}}), so the 
> tests do not catch it.
> * {{camel ask}} and {{camel overview}} are not affected. {{ask}} uses 
> {{ChatResponse.streamed()}} to know whether the text was already printed, and 
> {{overview}} sets {{withStream(false)}}.
> h3. Suggested fix
> Print the explanation unless it was really streamed, for example by having 
> {{generate}} report whether it streamed, as {{ChatResponse.streamed()}} does 
> for {{ask}}. Add an {{ExplainTest}} case with {{--api-type=openai}} against 
> the fake LLM server.
> Found while running the Camel AI integration tests against an 
> OpenAI-compatible gateway (vLLM behind LiteLLM).
> _Claude Code on behalf of Croway_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to