bugfix: convert several providers stop_reason to valid openai finish_reason#363
bugfix: convert several providers stop_reason to valid openai finish_reason#363unsync wants to merge 8 commits intoPortkey-AI:mainfrom
Conversation
1e5a6ee to
ae228b9
Compare
351fff8 to
ff93296
Compare
ff93296 to
b5a650e
Compare
|
hello @vrushankportkey @VisargD, i'm not sure if there is a process after opening a PR to request a review, any chance this PR could be considered ? |
|
Thank you so much @unsync! Yes, we're checking the PR and will share review if any in some time! Really appreciate you pushing this bugfix 🙌 |
b5a650e to
05eff29
Compare
| }; | ||
|
|
||
| // this converts the anthropic stop_reason to an openai finish_reason | ||
| const getFinishReason = (stopReason?: string): string | null => { |
There was a problem hiding this comment.
Recommend creating a type
type AnthropicStopReason = 'max_tokens' | 'stop_sequence' | 'end_turn' | ....
There was a problem hiding this comment.
also recommend using a switch/case
| logprobs: null, | ||
| finish_reason: response.stop_reason, | ||
| finish_reason: | ||
| getFinishReason(response.stop_reason) || response.stop_reason, |
There was a problem hiding this comment.
This should just be getFinishReason(response.stop_reason), Otherwise it defeats the purpose of strictly typing the response
narengogi
left a comment
There was a problem hiding this comment.
Thanks for the Pull Request! Requested a few changes
|
|
||
| // this converts the google stop_reason to an openai finish_reason | ||
| // https://ai.google.dev/api/python/google/ai/generativelanguage/Candidate/FinishReason | ||
| const getFinishReason = (stopReason?: string): string | null => { |
There was a problem hiding this comment.
Same comments as in the getFinishReason transformer function above.
- Use switch/case
- Define types for GoogleStopReason
| index: generation.index, | ||
| finish_reason: generation.finishReason, | ||
| finish_reason: | ||
| getFinishReason(generation.finishReason) ?? |
There was a problem hiding this comment.
should only be
finish_reason:
getFinishReason(generation.finishReason)
default case should be handled inside getFinishReason
@narengogi that is great ! |
|
Thanks @unsync & @narengogi! |
Description:
Currently, we forward the anthropic
stop_reason, which is not compatible with the openaifinish_reason.This can cause warnings from some OpenAI sdk.
The conversion function returns
stopas a default value in case newstop_reasonare added.There was also a bug in the groq and google providers for the
finish_reasonSide note:
It would probably be beneficial to update the types to we can get compilation-time validation :
gateway/src/providers/types.ts
Lines 101 to 123 in 77f32e5
Proposed change :
see https://platform.openai.com/docs/guides/text-generation/chat-completions-response-format