davsclaus commented on code in PR #25171: URL: https://github.com/apache/camel/pull/25171#discussion_r3663007687
########## docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc: ########## @@ -21,6 +21,14 @@ The MCP Server has also been promoted to _Stable_. The Camel JBang CLI now automatic resolves quarkus version to use, instead of hardcoded `3.33.1.1` (https://github.com/apache/camel/commit/d1f4713ebdf787ab04a31c50a6f07e3ca66f0c2b). +The Camel CLI and TUI AI prompt (`camel ask`, TUI F8 panel) now auto-detect **Azure OpenAI** +when `AZURE_OPENAI_API_KEY` and `AZURE_OPENAI_ENDPOINT` are set (optional `AZURE_OPENAI_DEPLOYMENT_NAME` +and `AZURE_OPENAI_API_VERSION`). Azure requests use the `api-key` header instead of `Authorization: Bearer`. + +**GitHub Models** is opt-in: set `GITHUB_MODELS=1` (or any non-false value) together with `GITHUB_TOKEN` +to use `https://models.github.ai/inference`. A bare `GITHUB_TOKEN` alone no longer selects an LLM provider. Review Comment: Nit: the wording "no longer selects" implies this was previous behavior that changed, but `GITHUB_TOKEN` was never used for LLM auto-detection in prior releases. Consider rephrasing to present tense: ```suggestion to use `https://models.github.ai/inference`. A bare `GITHUB_TOKEN` alone does not select an LLM provider — the opt-in `GITHUB_MODELS` flag is required. ``` ########## dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/LlmClient.java: ########## @@ -1481,8 +1609,77 @@ private String readBaseUrlFromPidFile(Path pidFile) throws Exception { // ---- URL helpers ---- + static boolean isAzureOpenAiEndpoint(String endpoint) { + if (endpoint == null || endpoint.isBlank()) { + return false; + } + return endpoint.contains(".openai.azure.com") || endpoint.contains("/openai/deployments/"); + } + + static String stripTrailingSlash(String endpoint) { + if (endpoint == null || endpoint.isEmpty()) { + return endpoint; + } + return endpoint.endsWith("/") ? endpoint.substring(0, endpoint.length() - 1) : endpoint; + } + + String azureResourceBase(String endpoint) { + String u = stripTrailingSlash(endpoint); + int openAiPath = u.indexOf("/openai"); + if (openAiPath > 0) { + return u.substring(0, openAiPath); + } + return u; + } + + String resolveAzureApiVersion() { + String fromEnv = System.getenv("AZURE_OPENAI_API_VERSION"); + if (fromEnv != null && !fromEnv.isBlank()) { + return fromEnv; + } + return azureApiVersion != null ? azureApiVersion : DEFAULT_AZURE_API_VERSION; + } + + String appendAzureApiVersionQuery(String url) { + if (url.contains("api-version=")) { + return url; + } + return url + (url.contains("?") ? "&" : "?") + "api-version=" + resolveAzureApiVersion(); + } + + String normalizeAzureOpenAiChatUrl(String endpoint) { + String u = stripTrailingSlash(endpoint); + if (u.contains("/openai/deployments/") && u.contains("/chat/completions")) { + return appendAzureApiVersionQuery(u); + } + String deployment = (model != null && !model.isBlank()) ? model : "gpt-4o"; Review Comment: Minor: the `"gpt-4o"` fallback is a common Azure deployment name, but Azure deployments are user-defined — this won't match if the user named their deployment differently. In practice `resolveAzureOpenAiModel()` should have already set `model` before this is called, so this is a safety net. Just worth noting it's fragile for users who reach this path. -- 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]
