-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Add Ibm Granite Completion and Chat Completion support #129146
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
Merged
dan-rubinstein
merged 21 commits into
elastic:main
from
Evgenii-Kazannik:Add-IBM-Granite-support-for-completion-and-chat-completion
Jul 2, 2025
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
78ab1da
Add Ibm Granite Completion and Chat Completion support
Evgenii-Kazannik f92f348
Apply suggestions
Evgenii-Kazannik 510e3c5
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik d6d19be
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik a6eaec6
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik 9faf6f6
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik b23bdfb
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik 136416d
remove ibm watsonx transport version constant
Evgenii-Kazannik ff6ccf5
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik 80537a4
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik b44bab6
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik b1a76c3
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik 1bf81ed
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik e70752f
Merge remote-tracking branch 'origin/Add-IBM-Granite-support-for-comp…
Evgenii-Kazannik b219e72
update transport version
Evgenii-Kazannik c950380
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik bf882a0
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik f9b086f
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik 8e08b9e
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik 08ab2f6
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik 4ed865c
Merge branch 'main' into Add-IBM-Granite-support-for-completion-and-c…
Evgenii-Kazannik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 129146 | ||
summary: "[ML] Add IBM watsonx Completion and Chat Completion support to the Inference Plugin" | ||
area: Machine Learning | ||
type: enhancement | ||
issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ch/xpack/inference/services/ibmwatsonx/IbmWatsonUnifiedChatCompletionResponseHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.services.ibmwatsonx; | ||
|
||
import org.elasticsearch.xpack.core.inference.results.UnifiedChatCompletionException; | ||
import org.elasticsearch.xpack.inference.external.http.HttpResult; | ||
import org.elasticsearch.xpack.inference.external.http.retry.ErrorResponse; | ||
import org.elasticsearch.xpack.inference.external.http.retry.ResponseParser; | ||
import org.elasticsearch.xpack.inference.external.request.Request; | ||
import org.elasticsearch.xpack.inference.services.ibmwatsonx.response.IbmWatsonxErrorResponseEntity; | ||
import org.elasticsearch.xpack.inference.services.openai.OpenAiUnifiedChatCompletionResponseHandler; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Handles streaming chat completion responses and error parsing for Watsonx inference endpoints. | ||
* Adapts the OpenAI handler to support Watsonx's error schema. | ||
*/ | ||
public class IbmWatsonUnifiedChatCompletionResponseHandler extends OpenAiUnifiedChatCompletionResponseHandler { | ||
|
||
private static final String WATSONX_ERROR = "watsonx_error"; | ||
|
||
public IbmWatsonUnifiedChatCompletionResponseHandler(String requestType, ResponseParser parseFunction) { | ||
super(requestType, parseFunction, IbmWatsonxErrorResponseEntity::fromResponse); | ||
} | ||
|
||
@Override | ||
protected Exception buildError(String message, Request request, HttpResult result, ErrorResponse errorResponse) { | ||
assert request.isStreaming() : "Only streaming requests support this format"; | ||
var responseStatusCode = result.response().getStatusLine().getStatusCode(); | ||
if (request.isStreaming()) { | ||
var errorMessage = errorMessage(message, request, result, errorResponse, responseStatusCode); | ||
var restStatus = toRestStatus(responseStatusCode); | ||
return errorResponse instanceof IbmWatsonxErrorResponseEntity | ||
? new UnifiedChatCompletionException(restStatus, errorMessage, WATSONX_ERROR, restStatus.name().toLowerCase(Locale.ROOT)) | ||
: new UnifiedChatCompletionException( | ||
restStatus, | ||
errorMessage, | ||
createErrorType(errorResponse), | ||
restStatus.name().toLowerCase(Locale.ROOT) | ||
); | ||
} else { | ||
return super.buildError(message, request, result, errorResponse); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...lasticsearch/xpack/inference/services/ibmwatsonx/IbmWatsonxCompletionResponseHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.services.ibmwatsonx; | ||
|
||
import org.elasticsearch.xpack.inference.external.http.retry.ResponseParser; | ||
import org.elasticsearch.xpack.inference.services.ibmwatsonx.response.IbmWatsonxErrorResponseEntity; | ||
import org.elasticsearch.xpack.inference.services.openai.OpenAiChatCompletionResponseHandler; | ||
|
||
public class IbmWatsonxCompletionResponseHandler extends OpenAiChatCompletionResponseHandler { | ||
|
||
/** | ||
* Constructs a IbmWatsonxCompletionResponseHandler with the specified request type and response parser. | ||
* | ||
* @param requestType The type of request being handled (e.g., "IBM watsonx completions"). | ||
* @param parseFunction The function to parse the response. | ||
*/ | ||
public IbmWatsonxCompletionResponseHandler(String requestType, ResponseParser parseFunction) { | ||
super(requestType, parseFunction, IbmWatsonxErrorResponseEntity::fromResponse); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify why this needs to be a
RateLimitGroupingModel
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type needs to be used in GenericRequestManager
which I believe is also going to handle the requests for other tasks in the future