Skip to content

Commit

Permalink
fix in pydantic validator
Browse files Browse the repository at this point in the history
  • Loading branch information
khai-meetkai committed Jan 8, 2025
1 parent e9ec966 commit 5c8b138
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 7 additions & 1 deletion functionary/openai_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import uuid
from typing import Dict, List, Literal, Optional, Union

from pydantic import BaseModel, Field, validator
from pydantic import BaseModel, Field, validator, field_validator


class FunctionCall(BaseModel):
Expand Down Expand Up @@ -145,6 +145,12 @@ class ChatCompletionRequest(BaseModel):
min_tokens: Optional[int] = 0
repetition_penalty: Optional[float] = 1.0
stop_token_ids: Optional[List[int]] = Field(default_factory=list)

@field_validator("temperature", mode="before")
def handle_str_temperature(cls, value):
if isinstance(value, float) or isinstance(value, int):
return float(value)
return 1e-5

# @validator("tool_choice", always=True)
# def validate_tool_choice(cls, value, values):
Expand Down
4 changes: 1 addition & 3 deletions functionary/sglang_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,7 @@ async def v1_chat_completions(
"""
request_json = await raw_request.json()
request = ChatCompletionRequest(**request_json)
if type(request.temperature) is not float:
request.temperature = 1e-5


tokenizer = (
tokenizer_manager.tokenizer
if tokenizer_manager
Expand Down

0 comments on commit 5c8b138

Please sign in to comment.