Fix stop reason for a few providers#468
Closed
narengogi wants to merge 37 commits intoPortkey-AI:mainfrom
Closed
Conversation
…mat of type and text is still supported by openai
cb64d75 to
23e49b7
Compare
23e49b7 to
9214e19
Compare
90cdbb8 to
27614ec
Compare
…PEN_AI_COMPLETION_FINISH_REASON
…m to OPEN_AI_CHAT_COMPLETION_FINISH_REASON
2ba8c98 to
fa1751a
Compare
Member
Author
|
@VisargD for your review |
Collaborator
|
Hey! This PR is not currently handling stop reason transformation for streaming calls. |
…new enums by providers and to not throw a runtime exception
…new enums by providers and to not throw a runtime exception
…new enums by providers and to not throw a runtime exception
…new enums by providers and to not throw a runtime exception
Member
Author
|
Member
Author
|
@VisargD please review this, I'll have to make changes again if new providers are added |
Member
Author
|
closing this for now as discussed with @VisargD and @ayush-portkey
Illustrated example on why doing this would mean context loss: export enum finishReason {
FINISH_REASON_UNSPECIFIED = 'FINISH_REASON_UNSPECIFIED',
STOP = 'STOP',
MAX_TOKENS = 'MAX_TOKENS',
SAFETY = 'SAFETY',
RECITATION = 'RECITATION',
OTHER = 'OTHER',
BLOCKLIST = 'BLOCKLIST',
PROHIBITED_CONTENT = 'PROHIBITED_CONTENT',
SPII = 'SPII',
}since OPENAI only has 4 finish_reason enums, we map the above keys to one of the 4. const transformVertexGeminiChatStopReason = (
stopReason?: VERTEX_GEMINI_GENERATE_CONTENT_FINISH_REASON | string
): OPEN_AI_CHAT_COMPLETION_FINISH_REASON => {
switch (stopReason) {
case VERTEX_GEMINI_GENERATE_CONTENT_FINISH_REASON.STOP:
return OPEN_AI_CHAT_COMPLETION_FINISH_REASON.stop;
case VERTEX_GEMINI_GENERATE_CONTENT_FINISH_REASON.SAFETY:
case VERTEX_GEMINI_GENERATE_CONTENT_FINISH_REASON.RECITATION:
case VERTEX_GEMINI_GENERATE_CONTENT_FINISH_REASON.BLOCKLIST:
case VERTEX_GEMINI_GENERATE_CONTENT_FINISH_REASON.PROHIBITED_CONTENT:
case VERTEX_GEMINI_GENERATE_CONTENT_FINISH_REASON.SPII:
return OPEN_AI_CHAT_COMPLETION_FINISH_REASON.content_filter;
case VERTEX_GEMINI_GENERATE_CONTENT_FINISH_REASON.MAX_TOKENS:
return OPEN_AI_CHAT_COMPLETION_FINISH_REASON.length;
default:
return OPEN_AI_CHAT_COMPLETION_FINISH_REASON.stop;
}
}; |
This was referenced Jul 3, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Title:
Description:
TO-DO
complete.tsandchatComplete.tsfiles to make the code more readableMotivation:
Related Issues:
Also thanks to @unsync for his initial PR on this. I've extended it to all the providers