Skip to content

Commit 5632cf4

Browse files
authored
Merge pull request #3 from pollinations/fix/always-normalize-finish-reason
fix: always normalize finish_reason to OpenAI format
2 parents 0cecfca + 5f1658b commit 5632cf4

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/providers/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ export function splitString(input: string, separator: string): SplitResult {
6565

6666
/*
6767
Transforms the finish reason from the provider to the finish reason used by the OpenAI API.
68-
If the finish reason is not found in the map, it will return the stop reason.
69-
If the strictOpenAiCompliance is true, it will return the finish reason from the map.
70-
If the strictOpenAiCompliance is false, it will return the finish reason from the provider.
68+
Always normalizes finish_reason to OpenAI format regardless of strictOpenAiCompliance,
69+
since finish_reason is a core part of OpenAI compatibility (not an extra field).
70+
If the finish reason is not found in the map, it falls back to the raw value
71+
(or "stop" when strictOpenAiCompliance is true).
7172
NOTE: this function always returns a finish reason
7273
*/
7374
export const transformFinishReason = (
7475
finishReason?: PROVIDER_FINISH_REASON,
7576
strictOpenAiCompliance?: boolean
7677
): FINISH_REASON | PROVIDER_FINISH_REASON => {
7778
if (!finishReason) return FINISH_REASON.stop;
78-
if (!strictOpenAiCompliance) return finishReason;
7979
const transformedFinishReason = finishReasonMap.get(finishReason);
8080
if (!transformedFinishReason) {
81-
return FINISH_REASON.stop;
81+
return strictOpenAiCompliance ? FINISH_REASON.stop : finishReason;
8282
}
8383
return transformedFinishReason;
8484
};

0 commit comments

Comments
 (0)