mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(types): annotate _FINISH_REASON_MAP and map_finish_reason with OpenAIChatCompletionFinishReason
Fixes mypy errors where dict[str, str] was incompatible with the expected Literal type in get_finish_reason_mapping() and _check_finish_reason() return types.
This commit is contained in:
parent
3196d40a04
commit
b6784e7d8c
1 changed files with 3 additions and 3 deletions
|
|
@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Any, Iterable, List, Literal, Optional, Union
|
|||
import httpx
|
||||
|
||||
from litellm._logging import verbose_logger
|
||||
from litellm.types.llms.openai import AllMessageValues
|
||||
from litellm.types.llms.openai import AllMessageValues, OpenAIChatCompletionFinishReason
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from opentelemetry.trace import Span as _Span
|
||||
|
|
@ -58,7 +58,7 @@ def safe_divide(
|
|||
return numerator / denominator
|
||||
|
||||
|
||||
_FINISH_REASON_MAP = {
|
||||
_FINISH_REASON_MAP: dict[str, OpenAIChatCompletionFinishReason] = {
|
||||
# Anthropic
|
||||
"stop_sequence": "stop",
|
||||
"end_turn": "stop",
|
||||
|
|
@ -99,7 +99,7 @@ _FINISH_REASON_MAP = {
|
|||
}
|
||||
|
||||
|
||||
def map_finish_reason(finish_reason: str) -> str:
|
||||
def map_finish_reason(finish_reason: str) -> OpenAIChatCompletionFinishReason:
|
||||
mapped = _FINISH_REASON_MAP.get(finish_reason)
|
||||
if mapped is None:
|
||||
verbose_logger.warning(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue